fix(frontend): preserve single tildes in markdown (#4245)

This commit is contained in:
Huixin615
2026-07-16 16:57:32 +08:00
committed by GitHub
parent 756eac0d1a
commit 693507870c
3 changed files with 37 additions and 9 deletions
+7 -8
View File
@@ -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,
@@ -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("<del>");
});
it("continues to render double-tilde strikethrough", () => {
const html = renderMarkdown("状态:~~已取消~~", false);
expect(html).toContain("<del>已取消</del>");
});
});
@@ -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);