From 4dd72b8f6d0cdc161a5b7f8086d87665070481c5 Mon Sep 17 00:00:00 2001 From: luwol03 Date: Sat, 26 Jun 2021 09:13:30 +0200 Subject: [PATCH 1/2] improved getAndRemoveConfig util function --- src/core/render/utils.js | 4 ++-- test/unit/render-util.test.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/core/render/utils.js b/src/core/render/utils.js index 42fbfa078..03c9ef145 100644 --- a/src/core/render/utils.js +++ b/src/core/render/utils.js @@ -23,8 +23,8 @@ export function getAndRemoveConfig(str = '') { if (str) { str = str - .replace(/^('|")/, '') - .replace(/('|")$/, '') + .replace(/^"(:.*)"$/, '$1') + .replace(/^'(:.*)'$/, '$1') .replace(/(?:^|\s):([\w-]+:?)=?([\w-%]+)?/g, (m, key, value) => { if (key.indexOf(':') === -1) { config[key] = (value && value.replace(/"/g, '')) || true; diff --git a/test/unit/render-util.test.js b/test/unit/render-util.test.js index 23f6f5938..17108766e 100644 --- a/test/unit/render-util.test.js +++ b/test/unit/render-util.test.js @@ -58,6 +58,37 @@ describe('core/render/utils', () => { str: `[filename](_media/example.md ":include")`, }); }); + + test('dont parse quotes without colon', () => { + const result = getAndRemoveConfig( + `[filename](_media/example.md 'include')` + ); + + expect(result).toMatchObject({ + config: {}, + str: `[filename](_media/example.md 'include')`, + }); + }); + + test('dont parse with different quotes', () => { + const result = getAndRemoveConfig( + `[filename](_media/example.md ":include')` + ); + + expect(result).toMatchObject({ + config: {}, + str: `[filename](_media/example.md ":include')`, + }); + }); + + test('parse headings without quotes', () => { + const result = getAndRemoveConfig('### Hello, world! :id=hello-world'); + + expect(result).toMatchObject({ + config: { id: 'hello-world' }, + str: '### Hello, world!', + }); + }); }); }); From f3292d706616749274474e0c9efc0b9ab703885f Mon Sep 17 00:00:00 2001 From: luwol03 Date: Thu, 8 Jul 2021 19:43:17 +0200 Subject: [PATCH 2/2] removed breaking change --- src/core/render/utils.js | 4 ++-- test/unit/render-util.test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/render/utils.js b/src/core/render/utils.js index 03c9ef145..347614ca7 100644 --- a/src/core/render/utils.js +++ b/src/core/render/utils.js @@ -23,8 +23,8 @@ export function getAndRemoveConfig(str = '') { if (str) { str = str - .replace(/^"(:.*)"$/, '$1') - .replace(/^'(:.*)'$/, '$1') + .replace(/^"(.*)"$/, '$1') + .replace(/^'(.*)'$/, '$1') .replace(/(?:^|\s):([\w-]+:?)=?([\w-%]+)?/g, (m, key, value) => { if (key.indexOf(':') === -1) { config[key] = (value && value.replace(/"/g, '')) || true; diff --git a/test/unit/render-util.test.js b/test/unit/render-util.test.js index 17108766e..6ec34d1b7 100644 --- a/test/unit/render-util.test.js +++ b/test/unit/render-util.test.js @@ -59,13 +59,13 @@ describe('core/render/utils', () => { }); }); - test('dont parse quotes without colon', () => { + test('parse quotes without first colon', () => { const result = getAndRemoveConfig( - `[filename](_media/example.md 'include')` + `[filename](_media/example.md 'include :foo=bar')` ); expect(result).toMatchObject({ - config: {}, + config: { foo: 'bar' }, str: `[filename](_media/example.md 'include')`, }); });