-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
refactor highlight: add extend api for highlight #5095
Conversation
Publish flamegraph to https://ffdeaee6503ad5877006576f59622fb7d91390cc-16-hexo.surge.sh/flamegraph.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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,
// ...
}): string The 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested two comments, but basically LGTM. I think we can merge this.
Would you please change the filename from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
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