Skip to content

Commit b6ac346

Browse files
authored
Added filter marked:use for direct access to the marked.use function (#273)
1 parent 1b09354 commit b6ac346

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,17 @@ hexo.extend.filter.register('marked:extensions', function(extensions) {
268268
});
269269
```
270270

271+
You may also get access to `marked.use` function.
272+
For example to use the [marked-alert](https://github.com/bent10/marked-extensions/tree/main/packages/alert) extention wich also provides a `walkTokens` functions:
273+
274+
```js
275+
const markedAlert = require('marked-alert');
276+
277+
hexo.extend.filter.register('marked:use', function (markedUse) {
278+
markedUse(markedAlert());
279+
});
280+
```
281+
271282
[Markdown]: https://daringfireball.net/projects/markdown/
272283
[marked]: https://github.com/chjj/marked
273284
[PHP Markdown Extra]: https://michelf.ca/projects/php-markdown/extra/#def-list

lib/renderer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ module.exports = function(data, options) {
209209
const { prependRoot, postAsset, dompurify } = markedCfg;
210210
const { path, text } = data;
211211

212+
// exec filter to extend marked
213+
this.execFilterSync('marked:use', marked.use, { context: this });
214+
212215
// exec filter to extend renderer.
213216
const renderer = new Renderer(this);
214217
this.execFilterSync('marked:renderer', renderer, { context: this });

0 commit comments

Comments
 (0)