Skip to content

Commit dffcc55

Browse files
hugoguclaude
andcommitted
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 <noreply@anthropic.com> AI-model: kimi-for-coding/k2p6
1 parent b41c9cd commit dffcc55

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

client/components/editor/editor-markdown.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,13 @@ function protectMathPipes (text) {
326326
continue
327327
}
328328
}
329-
// Check for inline math ($...$)
329+
// Check for inline math ($...$) - must not span multiple lines
330330
if (text[i] === '$' && text[i + 1] !== '$') {
331+
// Only search for closing $ on the same line
332+
const lineEnd = text.indexOf('\n', i + 1)
333+
const searchEnd = lineEnd === -1 ? text.length : lineEnd
331334
const end = text.indexOf('$', i + 1)
332-
if (end !== -1) {
335+
if (end !== -1 && end < searchEnd) {
333336
result += text.slice(i, end + 1)
334337
.replace(/\|/g, PIPE_PLACEHOLDER)
335338
.replace(/&/g, AMPERSAND_PLACEHOLDER)

server/modules/rendering/markdown-core/renderer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ function protectMathPipes (text) {
4949
continue
5050
}
5151
}
52-
// Check for inline math ($...$)
52+
// Check for inline math ($...$) - must not span multiple lines
5353
if (text[i] === '$' && text[i + 1] !== '$') {
54+
// Only search for closing $ on the same line
55+
const lineEnd = text.indexOf('\n', i + 1)
56+
const searchEnd = lineEnd === -1 ? text.length : lineEnd
5457
const end = text.indexOf('$', i + 1)
55-
if (end !== -1) {
58+
if (end !== -1 && end < searchEnd) {
5659
result += text.slice(i, end + 1)
5760
.replace(/\|/g, PIPE_PLACEHOLDER)
5861
.replace(/&/g, AMPERSAND_PLACEHOLDER)

0 commit comments

Comments
 (0)