github io markdown不能渲染数学公式解决方法

本人环境:hexo + next主题

0x00

在博客根目录下,git bash here,执行以下命令

1
2
npm uninstall hexo-renderer-marked --save
npm install hexo-renderer-kramed --save

0x01

在博客根目录下,找到node_modules\kramed\lib\rules\inline.js
修改第11行:

1
2
//  escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
escape: /^\\([`*\[\]()#$+\-.!_>])/,

修改第20行:

1
2
//  em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

0x02

在主题目录下,修改_config.yml配置文件,找到mathjax,修改配置

1
2
3
4
#MathJax Support
mathjax:
enable: true
per_page: true

0x03

有公式需要渲染的文章需要在文章的Front-matter里使mathjax为true

1
2
3
4
5
title: test
date: 2021-09-27 21:58:32
tags:
categories:
mathjax: true

0x04

!!!
请clean一下
每次先执行hexo clean,再hexo g,再hexo d部署上去。

OK!