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

feat: add markdown-it to filter #121

Merged
merged 2 commits into from
Aug 12, 2020
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ markdown:

Refer to [the wiki](https://github.com/hexojs/hexo-renderer-markdown-it/wiki) for more details.

## Extensibility

This plugin overrides some default behaviors of how markdown-it plugin renders the markdown into html, to integrate with the Hexo ecosystem. It is possible to override this plugin too, without resorting to forking the whole thing.

For example, to enable [unsafe links](https://markdown-it.github.io/markdown-it/#MarkdownIt.prototype.validateLink) (which is disabled by default):

``` js
hexo.extend.filter.register('markdown-it:renderer', function(md) {
const { config } = this; // Skip this line if you don't need user config from _config.yml
md.validateLink = function() { return true; };
});
```

Save the file in "scripts/" folder and run Hexo as usual.

Refer to markdown-it [API documentation](https://markdown-it.github.io/markdown-it/#MarkdownIt).

## Requests and bug reports
If you have any feature requests or bugs to report, you're welcome to [file an issue](https://github.com/hexojs/hexo-renderer-markdown-it/issues).

Expand Down
2 changes: 2 additions & 0 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ module.exports = function(data, options) {
parser = parser.use(require('./anchors'), opt.anchors);
}

this.execFilterSync('markdown-it:renderer', parser, { context: this });

return parser.render(data.text);
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"chai": "^4.0.0",
"eslint": "^7.1.0",
"eslint-config-hexo": "^4.0.0",
"hexo": "^5.0.2",
"mocha": "^8.0.1",
"nyc": "^15.0.0"
},
Expand Down
Loading