Skip to content

Commit

Permalink
docs(extensions): add extensions example
Browse files Browse the repository at this point in the history
  • Loading branch information
Eumeryx committed May 9, 2022
1 parent afcf503 commit a50c060
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<p>${katex.renderToString(token.math, {displayMode: true})}</p>\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

0 comments on commit a50c060

Please sign in to comment.