CHENXCHEN / hexo-renderer-markdown-it-plus

Markdown-it is a markdown parser, done right. A faster and CommonMark compliant alternative for Hexo.
https://chchc.me/hexo-article/2017/07/27/hexo-renderer-markdown-it-plus-plugin-demo/
MIT License
120 stars 22 forks source link

奇怪的部分渲染问题 #8

Closed oovm closed 6 years ago

oovm commented 6 years ago

部分行内公式渲染, 部分没渲染

image

网页链接

https://galaster.github.io/archives/59dcbda5.html


package.json

"dependencies": {
    "hexo": "^3.2.0",
    "hexo-abbrlink": "^2.0.5",
    "hexo-all-minifier": "^0.5.2",
    "hexo-generator-archive": "^0.1.4",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-index": "^0.2.0",
    "hexo-generator-tag": "^0.2.0",
    "hexo-helper-live2d": "^3.0.0",
    "hexo-inject": "^1.0.0",
    "hexo-renderer-ejs": "^0.3.1",
    "hexo-renderer-markdown-it-plus": "^1.0.2",
    "hexo-renderer-stylus": "^0.3.3",
    "hexo-server": "^0.3.1",
    "hexo-symbols-count-time": "^0.3.2",
    "live2d-widget-model-koharu": "^1.0.5"
  }

_config.yml

默认设置

theme/next/_config.yml

math:
  enable: true
  per_page: false # If you set it to false, it will load mathjax/katex srcipt EVERY PAGE.
  engine: katex
  katex:
    cdn: //cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css

不过我看 demo 用的也是 next 主题

项目快照

https://github.com/GalAster/Galaster.github.io/tree/8fb4db43b356a5ef5b2255cae7d2d61290d85c8f

CHENXCHEN commented 6 years ago

文章有笔误。在$与公式之间不得有空格。

$x_i + y_i = z_i$
oovm commented 6 years ago

谢谢, 你能不能帮我看下这个

我想装 markdown-it-katex-external

markdown_it_plus:
    ..............
    plugins:
      - plugin:
          name: markdown-it-katex-external
          enable: true
          options:
            throwOnError: false
            errorColor: "#cc0000"

好像不成功

INFO  Start processing
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
ReferenceError: window is not defined
    at Array.math_block (E:\Galaster.github.io\node_modules\markdown-it-katex-external\index.js:119:19)
    at ParserBlock.tokenize (E:\Galaster.github.io\node_modules\markdown-it\lib\parser_block.js:79:20)
    at ParserBlock.parse (E:\Galaster.github.io\node_modules\markdown-it\lib\parser_block.js:115:8)
    at Array.block (E:\Galaster.github.io\node_modules\markdown-it\lib\rules_core\block.js:14:20)
    at Core.process (E:\Galaster.github.io\node_modules\markdown-it\lib\parser_core.js:51:13)
    at MarkdownIt.parse (E:\Galaster.github.io\node_modules\markdown-it\lib\index.js:523:13)
    at MarkdownIt.render (E:\Galaster.github.io\node_modules\markdown-it\lib\index.js:543:36)
    at Hexo.module.exports (E:\Galaster.github.io\node_modules\hexo-renderer-markdown-it-plus\lib\renderer.js:132:15)
    at Hexo.tryCatcher (E:\Galaster.github.io\node_modules\bluebird\js\release\util.js:16:23)
    at Hexo.<anonymous> (E:\Galaster.github.io\node_modules\bluebird\js\release\method.js:15:34)
    at E:\Galaster.github.io\node_modules\hexo\lib\hexo\render.js:61:21
    at tryCatcher (E:\Galaster.github.io\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (E:\Galaster.github.io\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (E:\Galaster.github.io\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromiseCtx (E:\Galaster.github.io\node_modules\bluebird\js\release\promise.js:606:10)
    at Async._drainQueue (E:\Galaster.github.io\node_modules\bluebird\js\release\async.js:138:12)
    at Async._drainQueues (E:\Galaster.github.io\node_modules\bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues [as _onImmediate] (E:\Galaster.github.io\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:757:18)
    at tryOnImmediate (timers.js:718:5)
    at processImmediate [as _immediateCallback] (timers.js:698:5)

当前状态

https://github.com/GalAster/Galaster.github.io/tree/215943fc4a0dc618f01c7adeef3908b90b36a8f8

CHENXCHEN commented 6 years ago

并不需要使用该插件,其实并不需要引入 katex.min.js,因为在编译的时候已经渲染了,只需要引入 katex.min.css

oovm commented 6 years ago

另外用 KaTeX 0.7.x 以上的版本(8.3/9.0)就会变成这样, 请问怎么解决?

image

css 还是在 next 的 _config 里设定的

//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.0/katex.min.css


还有一个就是如何把错误的语法也扔出来

throwOnError: false 好像没啥用啊

test: $\frac{{1}}{x}$, $\frac{{1}{x}}$, $\frac{{1}{x}$

第一个能渲染, 但是不抛出, 第二第三个会卡掉渲染器, 只要有一篇文章出现了一个这个语法就统统不能渲染了

我很早以前用 MathType 写公式, 导出的全是类似 \frac{{1}{x}} 这种, katex的demo里还可以的

所以我想可能是 renderer 层面的东西, 所以来问一下

oovm commented 6 years ago

只要不卡掉渲染器就行了.... 原封不动还能查错

不然只要有一个错误语法就 hexo g 就挂了

以前在wordpress那个插件容错比较好也没注意这方面😂😂😂