From dffcc55755c582020bf7e7478c5d7e6b243c53d6 Mon Sep 17 00:00:00 2001 From: Hugo Gu Date: Tue, 12 May 2026 22:49:45 +0800 Subject: [PATCH] fix: restrict inline math placeholder replacement to single line Unclosed $ delimiters would span across multiple lines, causing protectMathPipes() to corrupt table cell delimiters in unrelated content. Limit inline math matching to the same line to prevent false matches. Co-authored-by: Claude AI-model: kimi-for-coding/k2p6 --- client/components/editor/editor-markdown.vue | 7 +++++-- server/modules/rendering/markdown-core/renderer.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client/components/editor/editor-markdown.vue b/client/components/editor/editor-markdown.vue index d698348b..cc4bd52a 100644 --- a/client/components/editor/editor-markdown.vue +++ b/client/components/editor/editor-markdown.vue @@ -326,10 +326,13 @@ function protectMathPipes (text) { continue } } - // Check for inline math ($...$) + // Check for inline math ($...$) - must not span multiple lines if (text[i] === '$' && text[i + 1] !== '$') { + // Only search for closing $ on the same line + const lineEnd = text.indexOf('\n', i + 1) + const searchEnd = lineEnd === -1 ? text.length : lineEnd const end = text.indexOf('$', i + 1) - if (end !== -1) { + if (end !== -1 && end < searchEnd) { result += text.slice(i, end + 1) .replace(/\|/g, PIPE_PLACEHOLDER) .replace(/&/g, AMPERSAND_PLACEHOLDER) diff --git a/server/modules/rendering/markdown-core/renderer.js b/server/modules/rendering/markdown-core/renderer.js index e243c82d..d813c256 100644 --- a/server/modules/rendering/markdown-core/renderer.js +++ b/server/modules/rendering/markdown-core/renderer.js @@ -49,10 +49,13 @@ function protectMathPipes (text) { continue } } - // Check for inline math ($...$) + // Check for inline math ($...$) - must not span multiple lines if (text[i] === '$' && text[i + 1] !== '$') { + // Only search for closing $ on the same line + const lineEnd = text.indexOf('\n', i + 1) + const searchEnd = lineEnd === -1 ? text.length : lineEnd const end = text.indexOf('$', i + 1) - if (end !== -1) { + if (end !== -1 && end < searchEnd) { result += text.slice(i, end + 1) .replace(/\|/g, PIPE_PLACEHOLDER) .replace(/&/g, AMPERSAND_PLACEHOLDER)