diff --git a/src/lib/components/chat/Messages/Markdown.svelte b/src/lib/components/chat/Messages/Markdown.svelte index c33e452a6c..b1ca46c79b 100644 --- a/src/lib/components/chat/Messages/Markdown.svelte +++ b/src/lib/components/chat/Messages/Markdown.svelte @@ -5,6 +5,7 @@ import markedExtension from '$lib/utils/marked/extension'; import markedKatexExtension from '$lib/utils/marked/katex-extension'; + import { disableSingleTilde } from '$lib/utils/marked/strikethrough-extension'; import { mentionExtension } from '$lib/utils/marked/mention-extension'; import MarkdownTokens from './Markdown/MarkdownTokens.svelte'; @@ -38,6 +39,7 @@ marked.use(markedKatexExtension(options)); marked.use(markedExtension(options)); + marked.use(disableSingleTilde); marked.use({ extensions: [mentionExtension({ triggerChar: '@' }), mentionExtension({ triggerChar: '#' })] }); diff --git a/src/lib/utils/marked/strikethrough-extension.ts b/src/lib/utils/marked/strikethrough-extension.ts new file mode 100644 index 0000000000..05e60e8100 --- /dev/null +++ b/src/lib/utils/marked/strikethrough-extension.ts @@ -0,0 +1,29 @@ +export const disableSingleTilde = { + tokenizer: { + del(src) { + // 1. First check for the REAL strikethrough: ~~text~~ + const doubleMatch = /^~~(?=\S)([\s\S]*?\S)~~/.exec(src); + if (doubleMatch) { + return { + type: 'del', + raw: doubleMatch[0], + text: doubleMatch[1], + tokens: this.lexer.inlineTokens(doubleMatch[1]) + }; + } + + // 2. Check for single-tilde: ~text~ + const singleMatch = /^~(?=\S)([\s\S]*?\S)~/.exec(src); + if (singleMatch) { + // return a plain-text token, NOT del + return { + type: 'text', + raw: singleMatch[0], + text: singleMatch[0] // include both tildes as literal text + }; + } + + return false; + } + } +};