feat: katex persistent macro support (#5838)

Co-authored-by: cannorin <cannorin@users.noreply.github.com>
This commit is contained in:
cannorin 2022-11-13 15:43:48 +09:00 committed by GitHub
parent dc90e0b5a7
commit db2ad81a1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -348,11 +348,12 @@ plantuml.init(md, {})
// KATEX // KATEX
// ======================================== // ========================================
const macros = {}
md.inline.ruler.after('escape', 'katex_inline', katexHelper.katexInline) md.inline.ruler.after('escape', 'katex_inline', katexHelper.katexInline)
md.renderer.rules.katex_inline = (tokens, idx) => { md.renderer.rules.katex_inline = (tokens, idx) => {
try { try {
return katex.renderToString(tokens[idx].content, { return katex.renderToString(tokens[idx].content, {
displayMode: false displayMode: false, macros
}) })
} catch (err) { } catch (err) {
console.warn(err) console.warn(err)
@ -365,7 +366,7 @@ md.block.ruler.after('blockquote', 'katex_block', katexHelper.katexBlock, {
md.renderer.rules.katex_block = (tokens, idx) => { md.renderer.rules.katex_block = (tokens, idx) => {
try { try {
return `<p>` + katex.renderToString(tokens[idx].content, { return `<p>` + katex.renderToString(tokens[idx].content, {
displayMode: true displayMode: true, macros
}) + `</p>` }) + `</p>`
} catch (err) { } catch (err) {
console.warn(err) console.warn(err)

View File

@ -24,12 +24,13 @@ katex.__defineMacro('\\tripledash', '{\\vphantom{-}\\raisebox{2.56mu}{$\\mkern2m
module.exports = { module.exports = {
init (mdinst, conf) { init (mdinst, conf) {
const macros = {}
if (conf.useInline) { if (conf.useInline) {
mdinst.inline.ruler.after('escape', 'katex_inline', katexInline) mdinst.inline.ruler.after('escape', 'katex_inline', katexInline)
mdinst.renderer.rules.katex_inline = (tokens, idx) => { mdinst.renderer.rules.katex_inline = (tokens, idx) => {
try { try {
return katex.renderToString(tokens[idx].content, { return katex.renderToString(tokens[idx].content, {
displayMode: false displayMode: false, macros
}) })
} catch (err) { } catch (err) {
WIKI.logger.warn(err) WIKI.logger.warn(err)
@ -44,7 +45,7 @@ module.exports = {
mdinst.renderer.rules.katex_block = (tokens, idx) => { mdinst.renderer.rules.katex_block = (tokens, idx) => {
try { try {
return `<p>` + katex.renderToString(tokens[idx].content, { return `<p>` + katex.renderToString(tokens[idx].content, {
displayMode: true displayMode: true, macros
}) + `</p>` }) + `</p>`
} catch (err) { } catch (err) {
WIKI.logger.warn(err) WIKI.logger.warn(err)