Hexo MathJax Windows 修复

未分类
783 词

deepseek-v4-flash-ascend检查修复后生成的memory file.

Hexo MathJax Windows 修复

问题

hexo server / hexo generate 报错:

1
2
3
Error: Can't find handler for document
at HandlerList.handlesDocument (...@mathjax/src/cjs/core/HandlerList.js:60:15)
at ...hexo-filter-mathjax/lib/filter.js:173:26

根因

Windows 上文件为 \r\n 换行。MathJax 的 Lite Parser 在解析 HTML 标签时,正则 SPACE = '[ \n]+' 不把 \r 当作空白字符,导致 adaptor.parse() 抛异常被吞掉,handlesDocument 返回 false → “Can’t find handler for document”。

参考:https://github.com/next-theme/hexo-filter-mathjax/issues/87 MathJax 修复 PR:https://github.com/mathjax/MathJax-src/pull/1521

修复

编辑 node_modules/@mathjax/src/cjs/adaptors/lite/Parser.js

1
2
3
4
5
6
// 修改前
var SPACE = '[ \\n]+';
var OPTIONALSPACE = '[ \\n]*';
// 修改后
var SPACE = '[ \\r\\n]+';
var OPTIONALSPACE = '[ \\r\\n]*';

注意:这是 node_modules 内的补丁,npm install 重新安装后会丢失,需重新应用。

留言