diff --git a/README.md b/README.md index 8d88e87..6480ea6 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,39 @@ hexo.extend.filter.register('marked:tokenizer', function(tokenizer) { }); ``` +#### Extensions + +It is also possible to customize the [extensions](https://marked.js.org/using_pro#extensions). +For example, use [KaTeX](https://katex.org/) to render block-level math: + +```js +const katex = require('katex'); + +hexo.extend.filter.register('marked:extensions', function(extensions) { + // Info: `extensions` is an array. + extensions.push({ + name: 'blockMath', + level: 'block', + tokenizer(src) { + const cap = /^\s{0,3}\$\$((?:[^\n]|\n[^\n])+?)\n{0,1}\$\$/.exec(src); + + if (cap !== null) { + return { + type: 'blockMath', + raw: cap[0], + math: cap[1] + }; + } + + return undefined; + }, + renderer(token) { + return `

${katex.renderToString(token.math, {displayMode: true})}

\n`; + } + }); +}); +``` + [Markdown]: https://daringfireball.net/projects/markdown/ [marked]: https://github.com/chjj/marked [PHP Markdown Extra]: https://michelf.ca/projects/php-markdown/extra/#def-list