Skip to content

Commit 4dd72b8

Browse files
committed
improved getAndRemoveConfig util function
1 parent 9d7dcd5 commit 4dd72b8

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/core/render/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export function getAndRemoveConfig(str = '') {
2323

2424
if (str) {
2525
str = str
26-
.replace(/^('|")/, '')
27-
.replace(/('|")$/, '')
26+
.replace(/^"(:.*)"$/, '$1')
27+
.replace(/^'(:.*)'$/, '$1')
2828
.replace(/(?:^|\s):([\w-]+:?)=?([\w-%]+)?/g, (m, key, value) => {
2929
if (key.indexOf(':') === -1) {
3030
config[key] = (value && value.replace(/"/g, '')) || true;

test/unit/render-util.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,37 @@ describe('core/render/utils', () => {
5858
str: `[filename](_media/example.md ":include")`,
5959
});
6060
});
61+
62+
test('dont parse quotes without colon', () => {
63+
const result = getAndRemoveConfig(
64+
`[filename](_media/example.md 'include')`
65+
);
66+
67+
expect(result).toMatchObject({
68+
config: {},
69+
str: `[filename](_media/example.md 'include')`,
70+
});
71+
});
72+
73+
test('dont parse with different quotes', () => {
74+
const result = getAndRemoveConfig(
75+
`[filename](_media/example.md ":include')`
76+
);
77+
78+
expect(result).toMatchObject({
79+
config: {},
80+
str: `[filename](_media/example.md ":include')`,
81+
});
82+
});
83+
84+
test('parse headings without quotes', () => {
85+
const result = getAndRemoveConfig('### Hello, world! :id=hello-world');
86+
87+
expect(result).toMatchObject({
88+
config: { id: 'hello-world' },
89+
str: '### Hello, world!',
90+
});
91+
});
6192
});
6293
});
6394

0 commit comments

Comments
 (0)