From b6ac3462381bb96a3d781bf8a9be710b26e3c3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=BCller?= Date: Mon, 1 Apr 2024 17:25:45 +0200 Subject: [PATCH] Added filter marked:use for direct access to the marked.use function (#273) --- README.md | 11 +++++++++++ lib/renderer.js | 3 +++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index bd6cbcd..4a1b6d4 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,17 @@ hexo.extend.filter.register('marked:extensions', function(extensions) { }); ``` +You may also get access to `marked.use` function. +For example to use the [marked-alert](https://github.com/bent10/marked-extensions/tree/main/packages/alert) extention wich also provides a `walkTokens` functions: + +```js +const markedAlert = require('marked-alert'); + +hexo.extend.filter.register('marked:use', function (markedUse) { + markedUse(markedAlert()); +}); +``` + [Markdown]: https://daringfireball.net/projects/markdown/ [marked]: https://github.com/chjj/marked [PHP Markdown Extra]: https://michelf.ca/projects/php-markdown/extra/#def-list diff --git a/lib/renderer.js b/lib/renderer.js index 8a206c4..92ef7f7 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -209,6 +209,9 @@ module.exports = function(data, options) { const { prependRoot, postAsset, dompurify } = markedCfg; const { path, text } = data; + // exec filter to extend marked + this.execFilterSync('marked:use', marked.use, { context: this }); + // exec filter to extend renderer. const renderer = new Renderer(this); this.execFilterSync('marked:renderer', renderer, { context: this });