From 5c9911a620b81e7906a50797800db2230d73d01f Mon Sep 17 00:00:00 2001 From: zbf Date: Fri, 15 Nov 2024 13:55:45 +0800 Subject: [PATCH] refactor: block-level formulas will be treated as inline when surrounded by text(#712) --- .../MdEditor/layouts/Content/markdownIt/katex/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/MdEditor/layouts/Content/markdownIt/katex/index.ts b/packages/MdEditor/layouts/Content/markdownIt/katex/index.ts index 353837b1..60c0cd47 100644 --- a/packages/MdEditor/layouts/Content/markdownIt/katex/index.ts +++ b/packages/MdEditor/layouts/Content/markdownIt/katex/index.ts @@ -10,7 +10,9 @@ import { mergeAttrs } from '~/utils/md-it'; const math_inline: ParserInline.RuleInline = (state, silent) => { const delimiters = [ + { open: '$$', close: '$$' }, { open: '$', close: '$' }, + { open: '\\[', close: '\\]' }, { open: '\\(', close: '\\)' } ]; let match, token, pos; @@ -25,7 +27,7 @@ const math_inline: ParserInline.RuleInline = (state, silent) => { while (state.src[pos] === '\\') { pos -= 1; } - if ((match - pos) % 2 == 1) { + if ((match - pos) % 2 === 1) { break; } match += delim.close.length; @@ -48,9 +50,12 @@ const math_inline: ParserInline.RuleInline = (state, silent) => { } if (!silent) { + const inlineContent = state.src.slice(start, match); + + // 创建数学公式 token token = state.push('math_inline', 'math', 0); token.markup = delim.open; - token.content = state.src.slice(start, match); + token.content = inlineContent; } state.pos = match + delim.close.length;