From ec1513229c6f0d1c681058129c43fe02604d99d0 Mon Sep 17 00:00:00 2001 From: bLue Date: Wed, 27 Mar 2024 17:06:45 +0800 Subject: [PATCH] fix: Adjust math delimiter to fix markdown import/export compatibility issue ( #6650) --- shared/editor/nodes/Math.ts | 4 ++-- shared/editor/nodes/MathBlock.ts | 4 ++-- shared/editor/rules/math.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/shared/editor/nodes/Math.ts b/shared/editor/nodes/Math.ts index b9183f33a8a5..83c0911e57d6 100644 --- a/shared/editor/nodes/Math.ts +++ b/shared/editor/nodes/Math.ts @@ -69,9 +69,9 @@ export default class Math extends Node { } toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) { - state.write("$$"); + state.write("$"); state.text(node.textContent, false); - state.write("$$"); + state.write("$"); } parseMarkdown() { diff --git a/shared/editor/nodes/MathBlock.ts b/shared/editor/nodes/MathBlock.ts index fe1b618f68b8..3ffbfd5d170e 100644 --- a/shared/editor/nodes/MathBlock.ts +++ b/shared/editor/nodes/MathBlock.ts @@ -41,10 +41,10 @@ export default class MathBlock extends Node { } toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) { - state.write("$$$\n"); + state.write("$$\n"); state.text(node.textContent, false); state.ensureNewLine(); - state.write("$$$"); + state.write("$$"); state.closeBlock(node); } diff --git a/shared/editor/rules/math.ts b/shared/editor/rules/math.ts index 48717645cf66..f18191d6beb3 100644 --- a/shared/editor/rules/math.ts +++ b/shared/editor/rules/math.ts @@ -6,8 +6,8 @@ export const REGEX_INLINE_MATH_DOLLARS = /\$\$(.+)\$\$/; export const REGEX_BLOCK_MATH_DOLLARS = /\$\$\$\s+$/; -const inlineMathDelimiter = "$$"; -const blockMathDelimiter = "$$$"; +const inlineMathDelimiter = "$"; +const blockMathDelimiter = "$$"; // test if potential opening or closing delimiter // assumes that there is a "$" at state.src[pos] @@ -85,7 +85,7 @@ function mathInline(state: StateInline, silent: boolean): boolean { return true; } - // check if we have empty content (ex. $$$$) do not parse + // check if we have empty content (ex. $$) do not parse if (match - start === 0) { if (!silent) { state.pending += inlineMathDelimiter + inlineMathDelimiter;