docsify/docs/markdown.md

60 lines
1.2 KiB
Markdown
Raw Normal View History

2017-02-13 22:43:58 +08:00
# Markdown configuration
**docsify** uses [marked](https://github.com/markedjs/marked) as its Markdown parser. You can customize how it renders your Markdown content to HTML by customizing `renderer`:
2017-02-13 22:43:58 +08:00
```js
window.$docsify = {
markdown: {
2017-02-19 00:11:16 +08:00
smartypants: true,
renderer: {
link() {
2017-02-19 00:11:16 +08:00
// ...
},
},
},
};
2017-02-13 22:43:58 +08:00
```
?> Configuration Options Reference: [marked documentation](https://marked.js.org/#/USING_ADVANCED.md)
2017-02-13 22:43:58 +08:00
You can completely customize the parsing rules.
2017-02-13 22:43:58 +08:00
```js
window.$docsify = {
markdown(marked, renderer) {
2017-02-13 22:43:58 +08:00
// ...
return marked;
},
};
2017-02-13 22:43:58 +08:00
```
2017-08-17 16:52:54 +08:00
## Supports mermaid
```js
// Import mermaid
// <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.css">
// <script src="//cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
let num = 0;
2017-08-17 17:18:41 +08:00
mermaid.initialize({ startOnLoad: false });
2017-08-17 16:52:54 +08:00
window.$docsify = {
markdown: {
renderer: {
code(code, lang) {
if (lang === 'mermaid') {
return /* html */ `
<div class="mermaid">${mermaid.render(
'mermaid-svg-' + num++,
code
)}</div>
`;
2017-08-17 16:52:54 +08:00
}
return this.origin.code.apply(this, arguments);
},
},
},
};
2017-08-17 16:52:54 +08:00
```