theme-next / hexo-theme-next

Elegant and powerful theme for Hexo.
https://theme-next.org
Other
8.15k stars 2.05k forks source link

Mathjax 部分渲染失败 #826

Closed asdf2014 closed 5 years ago

asdf2014 commented 5 years ago

I agree and want to create new issue


Expected behavior

image

Actual behavior

image

Steps to reproduce the behavior

$M_n = \frac{ \sum_{i=1}^nX_i }n$

Node.js and NPM Information

$ node -v && npm -v
v11.6.0
6.9.0

Package dependencies Information

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.8.0"
  },
  "dependencies": {
    "@fancyapps/fancybox": "^3.5.7",
    "bookmark": "^0.2.3",
    "browser-sync": "^2.26.3",
    "gitment": "0.0.3",
    "gulp": "^3.9.1",
    "gulp-htmlclean": "^2.7.22",
    "gulp-htmlmin": "^3.0.0",
    "gulp-imagemin": "^4.1.0",
    "gulp-install": "^1.1.0",
    "gulp-minify-css": "^1.2.4",
    "gulp-uglify": "^3.0.2",
    "hexo": "^3.8.0",
    "hexo-abbrlink": "^2.0.5",
    "hexo-autonofollow": "^1.0.1",
    "hexo-deployer-git": "^1.0.0",
    "hexo-filter-flowchart": "^1.0.4",
    "hexo-filter-mermaid-diagrams": "^1.0.5",
    "hexo-fs": "^1.0.2",
    "hexo-generator-archive": "^0.1.5",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-feed": "^1.2.2",
    "hexo-generator-index": "^0.2.1",
    "hexo-generator-searchdb": "^1.0.8",
    "hexo-generator-sitemap": "^1.1.2",
    "hexo-generator-tag": "^0.2.0",
    "hexo-inject": "^1.0.0",
    "hexo-math": "^3.0.4",
    "hexo-offline": "^0.2.3",
    "hexo-related-popular-posts": "^2.0.6",
    "hexo-renderer-ejs": "^0.2.0",
    "hexo-renderer-kramed": "^0.1.4",
    "hexo-renderer-stylus": "^0.3.3",
    "hexo-server": "^0.2.2",
    "hexo-tag-mermaid": "^1.0.0",
    "markdown-it-emoji": "^1.4.0",
    "mermaid": "^8.0.0",
    "natives": "^1.1.6",
    "phantomjs": "^2.1.7"
  },
  "devDependencies": {
    "hexo-util": "^0.6.3"
  }
}

Hexo Information

Hexo version

hexo: 3.8.0
hexo-cli: 1.1.0
os: Darwin 18.2.0 darwin x64
node: 11.6.0
v8: 7.0.276.38-node.13
uv: 1.24.1
zlib: 1.2.11
ares: 1.15.0
modules: 67
nghttp2: 1.34.0
napi: 3
llhttp: 1.0.1
http_parser: 2.8.0
openssl: 1.1.0j
icu: 63.1
unicode: 11.0
cldr: 34.0
tz: 2018e

NexT Information

NexT Version:

NexT Scheme:

Other Information

https://yuzhouwan.com/posts/4534/ 这篇里面的 Mathjax 都是正常的,但是 https://yuzhouwan.com/posts/42737/ 中的部分渲染失败了

Mathjax 相关的配置:

# Math Equations Render Support
math:
  enable: true

  # Default (true) will load mathjax / katex script on demand.
  # That is it only render those page which has `mathjax: true` in Front Matter.
  # If you set it to false, it will load mathjax / katex srcipt EVERY PAGE.
  per_page: true

  engine: mathjax
  #engine: katex

  # hexo-rendering-pandoc (or hexo-renderer-kramed) needed to full MathJax support.
  mathjax:
    cdn: //cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML

    # See: https://mhchem.github.io/MathJax-mhchem/
    mhchem: //cdn.jsdelivr.net/npm/mathjax-mhchem@3

  # hexo-renderer-markdown-it-plus (or hexo-renderer-markdown-it with markdown-it-katex plugin) needed to full Katex support.
  katex:
    cdn: //cdn.jsdelivr.net/npm/katex@0/dist/katex.min.css

    copy_tex:
      # See: https://github.com/KaTeX/KaTeX/tree/master/contrib/copy-tex
      enable: false
      copy_tex_js: //cdn.jsdelivr.net/npm/katex@0/dist/contrib/copy-tex.min.js
      copy_tex_css: //cdn.jsdelivr.net/npm/katex@0/dist/contrib/copy-tex.min.css
welcome[bot] commented 5 years ago

Thanks for opening this issue, maintainers will get back to you as soon as possible!

stevenjoezhang commented 5 years ago

下划线被解释成Markdown语法了。加\转义,或者修改hexo-renderer-kramed配置。与NexT无关。

asdf2014 commented 5 years ago

@stevenjoezhang 感谢回复,google 了好久都没有找到如何通过配置 hexo-renderer-kramed 的解决方法~~ 忘告知,万分谢谢!

stevenjoezhang commented 5 years ago

@asdf2014 您好,可以试一下将_改为\_,看看能否解决问题。我没有在使用这个插件,但它可以修改的配置项似乎不多:https://www.npmjs.com/package/hexo-renderer-kramed 。也可以尝试使用其它的渲染插件。

npm
hexo-renderer-kramed
Markdown renderer plugin for Hexo with kramed engine
asdf2014 commented 5 years ago

@stevenjoezhang 是的,没有找到对应的配置文件。我试了一个修改 inline.js 代码的办法,是可以的。具体步骤如下:

# 修改 inline.js 中 inline 变量的 escape 和 em 两个属性
$ vim node_modules/kramed/lib/rules/inline.js
  var inline = {
    // escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
    escape: /^\\([`*\[\]()#$+\-.!_>])/,

    // em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
    em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
  };
stevenjoezhang commented 5 years ago

谢谢,未来会把相关内容写进文档,以提示用户避免这个问题。

asdf2014 commented 5 years ago

@stevenjoezhang SGTM :+1: