Skip to content
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

allow Markdown plugins loading fix #585 #589

Closed
wants to merge 2 commits into from
Closed
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
24 changes: 24 additions & 0 deletions packages/@vuepress/markdown/__tests__/plugin.spec.js
Original file line number Diff line number Diff line change
@@ -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.': '<p>Demo <ins>inserted</ins> text.</p>\n',
'Demo ==marked== text.': '<p>Demo <mark>marked</mark> text.</p>\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])
}
})
})
10 changes: 9 additions & 1 deletion packages/@vuepress/markdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module.exports = (markdown = {}) => {
toc,
lineNumbers,
beforeInstantiate,
afterInstantiate
afterInstantiate,
plugins
} = markdown

// allow user config slugify
Expand Down Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions packages/docs/docs/guide/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down