refactor highlight: add extend api for highlight#5095
refactor highlight: add extend api for highlight#5095stevenjoezhang merged 14 commits intomasterfrom
Conversation
|
Publish flamegraph to https://ffdeaee6503ad5877006576f59622fb7d91390cc-16-hexo.surge.sh/flamegraph.html |
|
Discussion: should we use filter api to support CC @hexojs/core |
|
I think we should use |
|
Another difference is: other filters allow multiple callback functions to be registered per event, and callbacks are executed sequentially when the event is triggered. For code highlighting, only a single handler function should be registered. (For example, the user can choose either highlight.js or prism, but should not register both with |
There was a problem hiding this comment.
IMHO, the ideal design is that we have a new plugin API hexo.extend.highlight:
hexo.extend.highlight.register('highlight.js', highlighter);
hexo.extend.highlight.register('prismjs', highlighter);
hexo.extend.highlight.register('shiki', highlighter);We can read _config.yml to determine which highlighter to use:
// _config.yml
highlight: 'shiki'The highlighter should have an API interface like this:
declare function highlighter({
code: string,
language?: string,
meta?: string,
highlightLines?: unknown, // TBD
lineNumbers?: boolean,
// ...
}): string|
New API interface of declare function highlighter(code: string, options: {
language?: string,
meta?: string,
highlightLines?: unknown, // TBD
lineNumbers?: boolean,
// ...
}): stringThe types of two parameters are the same as Besides, can I remove the following code? It seems to be dead code Line 409 in 871ac4f See also hexojs/hexo-renderer-marked#134 https://github.com/hexojs/hexo-renderer-marked/issue/26 |
yoshinorin
left a comment
There was a problem hiding this comment.
I suggested two comments, but basically LGTM. I think we can merge this.
|
Would you please change the filename from |
What does it do?
Currently, there are 3 files relevant to code highlighting
Each file is hardcoded with support for highlight.js and prismjs, which would make it very difficult to support other code highlighting functions.
To make it more flexible, I propose a new highlight filter:
With this filter, developers can use custom code highlighting functions to replace the built-in highlight.js or prismjs.
Issue resolved: #1891 #1300 #4010 #1938
Usage
Screenshots
Pull request tasks