diff --git a/frontend/src/core/streamdown/plugins.ts b/frontend/src/core/streamdown/plugins.ts index ba7356311..3eda6373d 100644 --- a/frontend/src/core/streamdown/plugins.ts +++ b/frontend/src/core/streamdown/plugins.ts @@ -12,11 +12,13 @@ const katexOptions = { strict: false, } as const; +const sharedRemarkPlugins = [ + [remarkGfm, { singleTilde: false }], + [remarkMath, { singleDollarTextMath: true }], +] as StreamdownProps["remarkPlugins"]; + export const streamdownPlugins = { - remarkPlugins: [ - remarkGfm, - [remarkMath, { singleDollarTextMath: true }], - ] as StreamdownProps["remarkPlugins"], + remarkPlugins: sharedRemarkPlugins, rehypePlugins: [ rehypeRaw, [rehypeKatex, katexOptions], @@ -24,10 +26,7 @@ export const streamdownPlugins = { }; export const streamdownPluginsWithWordAnimation = { - remarkPlugins: [ - remarkGfm, - [remarkMath, { singleDollarTextMath: true }], - ] as StreamdownProps["remarkPlugins"], + remarkPlugins: sharedRemarkPlugins, rehypePlugins: [ [rehypeKatex, katexOptions], rehypeSplitWordsIntoSpans, diff --git a/frontend/tests/unit/components/workspace/messages/markdown-content.test.ts b/frontend/tests/unit/components/workspace/messages/markdown-content.test.ts index 7c29c7539..865e5723a 100644 --- a/frontend/tests/unit/components/workspace/messages/markdown-content.test.ts +++ b/frontend/tests/unit/components/workspace/messages/markdown-content.test.ts @@ -83,3 +83,18 @@ describe("MarkdownContent streaming code blocks", () => { expect(html).toContain("data-streaming-code-block"); }); }); + +describe("MarkdownContent strikethrough", () => { + it("preserves single tildes in temperature ranges", () => { + const html = renderMarkdown("周六23~30℃;周日22~30℃", false); + + expect(html).toContain("周六23~30℃;周日22~30℃"); + expect(html).not.toContain(""); + }); + + it("continues to render double-tilde strikethrough", () => { + const html = renderMarkdown("状态:~~已取消~~", false); + + expect(html).toContain("已取消"); + }); +}); diff --git a/frontend/tests/unit/core/streamdown/plugins.test.ts b/frontend/tests/unit/core/streamdown/plugins.test.ts index 84754f7a1..cb27294ad 100644 --- a/frontend/tests/unit/core/streamdown/plugins.test.ts +++ b/frontend/tests/unit/core/streamdown/plugins.test.ts @@ -1,7 +1,21 @@ import { expect, test } from "@rstest/core"; import rehypeRaw from "rehype-raw"; +import remarkGfm from "remark-gfm"; -import { reasoningPlugins, streamdownPlugins } from "@/core/streamdown/plugins"; +import { + reasoningPlugins, + streamdownPlugins, + streamdownPluginsWithWordAnimation, +} from "@/core/streamdown/plugins"; + +test("shared streamdown configs disable single-tilde strikethrough", () => { + const expectedGfmPlugin = [remarkGfm, { singleTilde: false }]; + + expect(streamdownPlugins.remarkPlugins).toContainEqual(expectedGfmPlugin); + expect(streamdownPluginsWithWordAnimation.remarkPlugins).toContainEqual( + expectedGfmPlugin, + ); +}); test("streamdownPlugins includes rehypeRaw", () => { expect(streamdownPlugins.rehypePlugins).toContain(rehypeRaw);