From db2ad81a1fb1840f6ef9fa353ffefb92c6a9180a Mon Sep 17 00:00:00 2001 From: cannorin <13620400+cannorin@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:43:48 +0900 Subject: [PATCH] feat: katex persistent macro support (#5838) Co-authored-by: cannorin --- client/components/editor/editor-markdown.vue | 5 +++-- server/modules/rendering/markdown-katex/renderer.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/client/components/editor/editor-markdown.vue b/client/components/editor/editor-markdown.vue index 38f0f353..6fc2e581 100644 --- a/client/components/editor/editor-markdown.vue +++ b/client/components/editor/editor-markdown.vue @@ -348,11 +348,12 @@ plantuml.init(md, {}) // KATEX // ======================================== +const macros = {} md.inline.ruler.after('escape', 'katex_inline', katexHelper.katexInline) md.renderer.rules.katex_inline = (tokens, idx) => { try { return katex.renderToString(tokens[idx].content, { - displayMode: false + displayMode: false, macros }) } catch (err) { console.warn(err) @@ -365,7 +366,7 @@ md.block.ruler.after('blockquote', 'katex_block', katexHelper.katexBlock, { md.renderer.rules.katex_block = (tokens, idx) => { try { return `

` + katex.renderToString(tokens[idx].content, { - displayMode: true + displayMode: true, macros }) + `

` } catch (err) { console.warn(err) diff --git a/server/modules/rendering/markdown-katex/renderer.js b/server/modules/rendering/markdown-katex/renderer.js index 2321ad12..fbb67393 100644 --- a/server/modules/rendering/markdown-katex/renderer.js +++ b/server/modules/rendering/markdown-katex/renderer.js @@ -24,12 +24,13 @@ katex.__defineMacro('\\tripledash', '{\\vphantom{-}\\raisebox{2.56mu}{$\\mkern2m module.exports = { init (mdinst, conf) { + const macros = {} if (conf.useInline) { mdinst.inline.ruler.after('escape', 'katex_inline', katexInline) mdinst.renderer.rules.katex_inline = (tokens, idx) => { try { return katex.renderToString(tokens[idx].content, { - displayMode: false + displayMode: false, macros }) } catch (err) { WIKI.logger.warn(err) @@ -44,7 +45,7 @@ module.exports = { mdinst.renderer.rules.katex_block = (tokens, idx) => { try { return `

` + katex.renderToString(tokens[idx].content, { - displayMode: true + displayMode: true, macros }) + `

` } catch (err) { WIKI.logger.warn(err)