mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-11-08 03:30:34 +00:00
* fix(frontend): improve chat math rendering * fix(frontend): refine math rendering stability * fix(frontend): address review feedback on math preprocessing - Fix escaped-backslash blind spot: consume \\\\ as a unit so \\( and \\[ are not mis-interpreted as math delimiters when the backslash itself is escaped. - Thread inInlineCode state across lines so multi-line backtick code spans are protected from delimiter conversion. - Remove double math normalization: preprocessStreamdownMarkdown now only handles Mermaid; math normalization lives solely in ClipboardSafeStreamdown, preventing non-idempotent double passes. - Wire parseIncompleteMarkdown to isLoading in MarkdownContent so Streamdown's streaming-incomplete-math handling is actually active during streaming. * fix(frontend): address streamdown math review issues * refactor(frontend): move streamdown preprocessing out of ai elements
35 lines
966 B
TypeScript
35 lines
966 B
TypeScript
import { useMemo } from "react";
|
|
import type { ComponentProps } from "react";
|
|
import { type Streamdown } from "streamdown";
|
|
|
|
import {
|
|
capMarkdownNesting,
|
|
normalizeStreamdownMathMarkdown,
|
|
} from "./preprocess";
|
|
|
|
type StreamdownChildren = ComponentProps<typeof Streamdown>["children"];
|
|
|
|
export function getSafeStreamdownMarkdown(markdown: string): string {
|
|
return normalizeStreamdownMathMarkdown(capMarkdownNesting(markdown));
|
|
}
|
|
|
|
export function getSafeStreamdownChildren(
|
|
children: StreamdownChildren,
|
|
): StreamdownChildren {
|
|
if (typeof children !== "string") {
|
|
return children;
|
|
}
|
|
|
|
return getSafeStreamdownMarkdown(children);
|
|
}
|
|
|
|
export function useSafeStreamdownChildren(
|
|
children: StreamdownChildren,
|
|
): StreamdownChildren {
|
|
return useMemo(() => getSafeStreamdownChildren(children), [children]);
|
|
}
|
|
|
|
export function useSafeStreamdownMarkdown(markdown: string): string {
|
|
return useMemo(() => getSafeStreamdownMarkdown(markdown), [markdown]);
|
|
}
|