From ec16e4a9d5718ac4f4c25bb3dcaea3b7551372e0 Mon Sep 17 00:00:00 2001 From: luwol03 Date: Tue, 22 Jun 2021 14:31:45 +0200 Subject: [PATCH 1/2] fix: allow also " inside of an embed --- docs/embed-files.md | 2 +- src/core/render/utils.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/embed-files.md b/docs/embed-files.md index 07aa561f7..480d5fc5f 100644 --- a/docs/embed-files.md +++ b/docs/embed-files.md @@ -16,7 +16,7 @@ Then the content of `example.md` will be displayed directly here; You can check the original content for [example.md](_media/example.md ':ignore'). -Normally, this will compiled into a link, but in docsify, if you add `:include` it will be embedded. +Normally, this will compiled into a link, but in docsify, if you add `:include` it will be embedded. You can use single or double quotation marks around as you like. External links can be used too - just replace the target. If you want to use a gist URL, see [Embed a gist](#embed-a-gist) section. diff --git a/src/core/render/utils.js b/src/core/render/utils.js index bd892c653..42fbfa078 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(/^('|")/, '') + .replace(/('|")$/, '') .replace(/(?:^|\s):([\w-]+:?)=?([\w-%]+)?/g, (m, key, value) => { if (key.indexOf(':') === -1) { config[key] = (value && value.replace(/"/g, '')) || true; From 633f241547b03a337304773f6469f4cacd309515 Mon Sep 17 00:00:00 2001 From: luwol03 Date: Fri, 25 Jun 2021 17:26:27 +0200 Subject: [PATCH 2/2] added tests --- test/unit/render-util.test.js | 45 ++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/test/unit/render-util.test.js b/test/unit/render-util.test.js index 1f6996c2a..23f6f5938 100644 --- a/test/unit/render-util.test.js +++ b/test/unit/render-util.test.js @@ -1,4 +1,7 @@ -const { removeAtag } = require('../../src/core/render/utils'); +const { + removeAtag, + getAndRemoveConfig, +} = require('../../src/core/render/utils'); const { tree } = require(`../../src/core/render/tpl`); @@ -16,6 +19,46 @@ describe('core/render/utils', () => { expect(result).toEqual('content'); }); }); + + // getAndRemoveConfig() + // --------------------------------------------------------------------------- + describe('getAndRemoveConfig()', () => { + test('parse simple config', () => { + const result = getAndRemoveConfig( + `[filename](_media/example.md ':include')` + ); + + expect(result).toMatchObject({ + config: {}, + str: `[filename](_media/example.md ':include')`, + }); + }); + + test('parse config with arguments', () => { + const result = getAndRemoveConfig( + `[filename](_media/example.md ':include :foo=bar :baz test')` + ); + + expect(result).toMatchObject({ + config: { + foo: 'bar', + baz: true, + }, + str: `[filename](_media/example.md ':include test')`, + }); + }); + + test('parse config with double quotes', () => { + const result = getAndRemoveConfig( + `[filename](_media/example.md ":include")` + ); + + expect(result).toMatchObject({ + config: {}, + str: `[filename](_media/example.md ":include")`, + }); + }); + }); }); describe('core/render/tpl', () => {