Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added filter marked:use for direct access to the marked.use function #273

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
Loading