Go to file
2024-10-20 00:13:07 +08:00
src Version 1.0.0 2024-10-19 17:47:59 +08:00
.gitignore Version 1.0.0 2024-10-19 17:47:59 +08:00
build.mjs Version 1.0.0 2024-10-19 17:47:59 +08:00
LICENSE Version 1.0.0 2024-10-19 17:47:59 +08:00
package.json Update package name, README, and repository info 2024-10-19 18:25:29 +08:00
README_zh-CN.md add the solution of the error that occurs when using the plugin to render mathematical formulas with mathjax in articles that contain code blocks. 2024-10-20 00:13:07 +08:00
README.md add the solution of the error that occurs when using the plugin to render mathematical formulas with mathjax in articles that contain code blocks. 2024-10-20 00:13:07 +08:00
tsconfig.json Version 1.0.0 2024-10-19 17:47:59 +08:00

Hexo-Highlight-Shiki

English丨简体中文

A hexo plugin to use Shiki as code block highlighter.

Hexo v7.0.0+ is required.

Features

  • Render code block with Shiki like Hexo default highlighter.
  • Support dual or more themes.
  • Support custom language.

Installation and Configuration

First, install the plugin:

npm install hexo-highlighter-shiki --save

Then switch the code highlighting engine in your config.yml:

syntax_highlighter: shiki

Finally, configure shiki:

shiki:
  theme: github-dark # default: one-dark-pro
  line_number: true # default: false

Configuration Options

The complete configuration is as follows:

shiki:
  theme: one-dark-pro # see https://shiki.style/themes for supported themes.
  line_number: false
  strip_indent: true
  tab_replace: "  "
  additional:
    langs: # List of the TextMate grammar json of languages to be added.
      - path/to/lang_grammar.json
    lang_alias: # List of the alias of languages.
      your_alias1: lang_name1
      your_alias2: lang_name2

Additionally, you can specify multiple themes in the theme option:

shiki:
  theme:
    light: one-light
    dark: one-dark-pro
    # ...

See Dual Themes for how to switch between multiple themes.

Bugs

mathjax

If you are using hexo-filter-mathjax or any other plugin that uses mathjax to render mathematical formulas locally, you may encounter an Error: Can't find handler for document when rendering articles that include code blocks and have mathjax rendering enabled. This is a problem with mathjax, as its LiteDOM cannot parse complex HTML fragments.

Solution

For example, if you are using the hexo-filter-mathjax plugin, modify the this line in the source code:

- data.content = mathjax(data.content);
+ data.content = data.content.replace(/<span\s+class="math\s+[^"]*">\\[\(\[].*?\\[\)\]]<\/span>/gs, mathjax);

This will prevent rendering errors for complex HTML fragments that result in Can't find handler for document.

Acknowledgments

This plugin is developed based on