-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
Copy pathindex.js
31 lines (28 loc) · 867 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const visit = require(`unist-util-visit`)
const katex = require(`katex`)
const remarkMath = require(`remark-math`)
const unified = require(`unified`)
const parse = require(`rehype-parse`)
module.exports = ({ markdownAST }, pluginOptions = {}) => {
visit(markdownAST, `inlineMath`, node => {
node.data.hChildren = unified()
.use(parse, { fragment: true, position: false })
.parse(
katex.renderToString(node.value, {
displayMode: false,
...pluginOptions,
})
).children
})
visit(markdownAST, `math`, node => {
node.data.hChildren = unified()
.use(parse, { fragment: true, position: false })
.parse(
katex.renderToString(node.value, {
displayMode: true,
...pluginOptions,
})
).children
})
}
module.exports.setParserPlugins = () => [remarkMath]