Skip to content

fix: allow also " inside of an embed #1598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/embed-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions src/core/render/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
45 changes: 44 additions & 1 deletion test/unit/render-util.test.js
Original file line number Diff line number Diff line change
@@ -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`);

Expand All @@ -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")`,
});
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what the behavior should actually be. Seems funky that it leaves things behind. Seems like it should handle everything.

});

describe('core/render/tpl', () => {
Expand Down