From e930fdda93d763353970305c3be3e89ea868dcaf Mon Sep 17 00:00:00 2001 From: HPCesia Date: Sun, 20 Oct 2024 00:13:07 +0800 Subject: [PATCH] add the solution of the error that occurs when using the plugin to render mathematical formulas with mathjax in articles that contain code blocks. --- README.md | 18 ++++++++++++++++++ README_zh-CN.md | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/README.md b/README.md index 748169c..b14f695 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,24 @@ shiki: ``` See [Dual Themes](https://shiki.style/guide/dual-themes) for how to switch between multiple themes. +## Bugs +### mathjax +If you are using [hexo-filter-mathjax](https://github.com/next-theme/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](https://github.com/next-theme/hexo-filter-mathjax/blob/20dc61352f8cf4d19425ad1833eb72b467c212ef/index.js#L20C3-L20C40) in the source code: +```js +- data.content = mathjax(data.content); ++ data.content = data.content.replace(/\\[\(\[].*?\\[\)\]]<\/span>/gs, mathjax); +``` +This will prevent rendering errors for complex HTML fragments that result in `Can't find handler for document`. + +#### Related Issues: +- [Error in applying html the markdown file #26](https://github.com/next-theme/hexo-filter-mathjax/issues/26) +- [Can't find handler for document #265](https://github.com/mathjax/MathJax-src/issues/265) + + ## Acknowledgments This plugin is developed based on - [ArcticLampyrid/hexo-shiki-highlighter](https://github.com/ArcticLampyrid/hexo-shiki-highlighter) diff --git a/README_zh-CN.md b/README_zh-CN.md index a99e661..d8b932d 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -53,6 +53,23 @@ shiki: ``` 在 [Dual Themes](https://shiki.style/guide/dual-themes) 中查看如何切换多个主题。 +## Bugs +### mathjax +如果你正在使用 [hexo-filter-mathjax](https://github.com/next-theme/hexo-filter-mathjax) 或其他任意在本地使用 mathjax 渲染数学公式的插件,在渲染包含代码块且开启 mathjax 渲染的文章时可能会出现 `Error: Can't find handler for document`。这是 mathjax 的问题,mathjax 的 LiteDOM 无法解析复杂的 HTML 片段。 + +#### 解决方法 + +以 hexo-filter-mathjax 插件为例,修改源代码中的[这一行](https://github.com/next-theme/hexo-filter-mathjax/blob/20dc61352f8cf4d19425ad1833eb72b467c212ef/index.js#L20C3-L20C40): +```js +- data.content = mathjax(data.content); ++ data.content = data.content.replace(/\\[\(\[].*?\\[\)\]]<\/span>/gs, mathjax); +``` +这可以避免对那些复杂的 HTML 片段进行渲染导致的 `Can't find handler for document` 错误。 + +#### 相关 Issues +- [Error in applying html the markdown file #26](https://github.com/next-theme/hexo-filter-mathjax/issues/26) +- [ Can't find handler for document #265 ](https://github.com/mathjax/MathJax-src/issues/265) + ## 感谢 本插件基于 - [ArcticLampyrid/hexo-shiki-highlighter](https://github.com/ArcticLampyrid/hexo-shiki-highlighter)