1

我可以问你我的问题吗?我正在尝试将 remark-math 应用于我的 Elder.js 博客。它没有正确渲染。像这样。

降价

$$
\sin^2x + \cos^2x = 1
h \circ (g \circ f) = (h \circ g) \circ f = h \circ g \circ f
$$

呈现的 html

<div class="math math-display">
\sin^2x + \cos^2x = 1
h \circ (g \circ f) = (h \circ g) \circ f = h \circ g \circ f
</div>

现在我的博客链接

https://twinstae.github.io/category-for-functional/

我做了以下事情。

  • npm install remark-math remark-katex
  • 将 katex css 添加到头部
  • 将所有默认管道和 remarkMath、remarkKatex 添加到 Elder.config.js

Elder.config.js

plugins: {
  '@elderjs/plugin-markdown': {
    routes: ['blog'],
    remarkPlugins: [
      frontmatter, // 'remark-frontmatter' package
      [extractFrontmatter, { name: 'frontmatter', yaml: yaml.parse }], // 'remark-extract-frontmatter'       and 'yaml' packages.
      remarkSlug, // 'remark-slug' package
      remarkMath,
      remarkKatex,
      remarkHtml, // 'remark-html' package
    ],
  },
  ...
}

Elder.config.js 链接 https://github.com/twinstae/twinstae.github.io/blob/master/elder.config.js

备注插件链接的文档

https://www.npmjs.com/package/@elderjs/plugin-markdown#remark-plugins

我正在尝试几个插件订单,搜索,再次阅读 Elder.js 文档......

感谢您的阅读。:)

4

1 回答 1

1

我找到了答案!rehype -katex 是一个 rehype 的插件

新的Elder.config.js

const remarkMath = require('remark-math');
const remark2rehype = require('remark-rehype');
const rehypeKatex = require('rehype-katex');
const rehypeStringify = require('rehype-stringify');

... (default plugins),
remarkMath,
remark2rehype, <- I missed this
rehypeKatex,
rehypeStringify, <- I missed this too
于 2021-07-10T13:34:13.693 回答