From 74916928be6552aa1e52fcdd1d634382bf7d9515 Mon Sep 17 00:00:00 2001 From: neumayr Date: Thu, 14 Jun 2018 16:48:13 +0200 Subject: [PATCH 1/2] add Plugins section to markdown docs --- packages/docs/docs/guide/markdown.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/docs/docs/guide/markdown.md b/packages/docs/docs/guide/markdown.md index b0ef8bed8f..617151e4f6 100644 --- a/packages/docs/docs/guide/markdown.md +++ b/packages/docs/docs/guide/markdown.md @@ -263,6 +263,18 @@ It also supports [line highlighting](#line-highlighting-in-code-blocks): ::: +## Plugins + +VuePress uses [markdown-it](https://github.com/markdown-it/markdown-it) as the markdown renderer. You can further customize the `markdown-it` instance using the `markdown.plugins` option in `.vuepress/config.js`. The `markdown-it-` prefix is optional and can omit in the list. + +``` js +module.exports = { + markdown: { + plugins: ['ins', 'mark'] + } +} +``` + ## Advanced Configuration VuePress uses [markdown-it](https://github.com/markdown-it/markdown-it) as the markdown renderer. A lot of the extensions above are implemented via custom plugins. You can further customize the `markdown-it` instance using the `markdown` option in `.vuepress/config.js`: From d674424a6905d53e0e9c4e9da5e4590ca15da0ff Mon Sep 17 00:00:00 2001 From: neumayr Date: Mon, 10 Dec 2018 16:52:29 +0100 Subject: [PATCH 2/2] rebase to work with v1.0.0-alpha --- .../markdown/__tests__/plugin.spec.js | 24 +++++++++++++++++++ packages/@vuepress/markdown/index.js | 10 +++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 packages/@vuepress/markdown/__tests__/plugin.spec.js diff --git a/packages/@vuepress/markdown/__tests__/plugin.spec.js b/packages/@vuepress/markdown/__tests__/plugin.spec.js new file mode 100644 index 0000000000..498ba0cf20 --- /dev/null +++ b/packages/@vuepress/markdown/__tests__/plugin.spec.js @@ -0,0 +1,24 @@ +import { Md } from './util' +import ins from 'markdown-it-ins' +import mark from 'markdown-it-mark' + +const mdP = Md().use(ins).use(mark) +// const mdP = Md().set({ +// markdown: { +// plugins: ['ins', 'mark'] +// } +// }) + +const asserts = { + 'Demo ++inserted++ text.': '

Demo inserted text.

\n', + 'Demo ==marked== text.': '

Demo marked text.

\n' +} + +describe('plugin', () => { + test('should convert markdown w/ custom plugins', () => { + for (const input in asserts) { + const output = mdP.render(input) + expect(output).toBe(asserts[input]) + } + }) +}) diff --git a/packages/@vuepress/markdown/index.js b/packages/@vuepress/markdown/index.js index 896f22d79c..727e580dc0 100644 --- a/packages/@vuepress/markdown/index.js +++ b/packages/@vuepress/markdown/index.js @@ -32,7 +32,8 @@ module.exports = (markdown = {}) => { toc, lineNumbers, beforeInstantiate, - afterInstantiate + afterInstantiate, + plugins } = markdown // allow user config slugify @@ -117,6 +118,13 @@ module.exports = (markdown = {}) => { module.exports.dataReturnable(md) + if (plugins) { + markdown.plugins.forEach(function (plugin) { + plugin = plugin.replace('markdown-it-', '') + md.use(require(`markdown-it-${plugin}`)) + }) + } + // expose slugify md.slugify = slugify