dominhhai / dominhhai.github.io

My Blog
https://dominhhai.github.io/
14 stars 15 forks source link

Render KaTex Math on Server Side #7

Open dominhhai opened 6 years ago

dominhhai commented 6 years ago
html = html.replace(/\$\$(.*?)\$\$/g, function(outer, inner) {
    return katex.renderToString(inner, { displayMode: true })
}).replace(/\\\[(.*?)\\\]/g, function(outer, innner) {
    return katex.renderToString(inner, { displayMode: true })
}).replace(/\\\((.*?)\\\)/g, function(outer, innner) {
    return katex.renderToString(inner)
}).replace(/\$(.*?)\$/g, function(outer, innner) {
    return katex.renderToString(inner)
})
dominhhai commented 6 years ago
const ignoredTags = ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
var tagsTmp = new Map()
for (let tag of ignoredTags) {
  html = html.replace(/<tag>(.*?)</tag>/g, function(outer, inner, offset) {
    var key = tag + '_' + offset
    tagsTmp[key] = outer
    return key
  })
}