Gollum-wiki中MathJax使用<math>标签渲染公式失败求助
解决Gollum-wiki中
问题原因
Gollum默认的Markdown解析器会主动解析HTML标签,当你使用<math>标签时,解析器会尝试将其作为普通HTML处理,导致内部的公式文本被提前拆解,无法完整传递给MathJax处理,进而抛出Unexpected text node错误。
解决方案
1. 修改Gollum配置,保留
在config.rb中添加Markdown解析器配置,关闭HTML过滤,让<math>标签原封不动传递给MathJax:
:mathjax => true, :mathjax_config => 'mathjax.config.js', # 添加Markdown解析配置 :markdown => { :renderer => Redcarpet::Render::HTML.new( :filter_html => false, # 禁止过滤HTML标签 :safe_links_only => false, :hard_wrap => true ), :extensions => { :no_intra_emphasis => true, :tables => true, :fenced_code_blocks => true, :autolink => true, :strikethrough => true } }
2. 调整MathJax配置(可选优化)
将<math>标签仅归为inline或display的一类,避免重复匹配导致冲突,修改mathjax.config.js:
window.MathJax = { tex2jax: { inlineMath: [ ['$','$'], ['\\(','\\)'], ['<math>', '</math>'] ], displayMath: [ ['$$','$$'], ['\\[','\\]'] ], // 移除display中的<math>配置 processEscapes: true }, TeX: { extensions: ["autoload-all.js"] } };
3. 验证测试
重启Gollum服务后,在页面中使用<math>Avg = \sum_{}^{N} {x_i} </math>,即可正常渲染公式。
内容的提问来源于stack exchange,提问作者JohnA
相关产品推荐
相关产品推荐

