fix: 修复单个\n输入,渲染时不会换行的问题
This commit is contained in:
parent
c2464c3449
commit
0abf5aaff0
|
|
@ -28,6 +28,7 @@ import { resolveArtifactURL } from "@/core/artifacts/utils";
|
|||
import { useI18n } from "@/core/i18n/hooks";
|
||||
import {
|
||||
extractContentFromMessage,
|
||||
normalizeHumanMessageDisplayText,
|
||||
extractReasoningContentFromMessage,
|
||||
parseUploadedFiles,
|
||||
stripPriorityHintSuffix,
|
||||
|
|
@ -167,9 +168,11 @@ function MessageContent_({
|
|||
|
||||
const contentToDisplay = useMemo(() => {
|
||||
if (isHuman) {
|
||||
return rawContent
|
||||
? stripPriorityHintSuffix(stripUploadedFilesTag(rawContent))
|
||||
: "";
|
||||
if (!rawContent) {
|
||||
return "";
|
||||
}
|
||||
const cleaned = stripPriorityHintSuffix(stripUploadedFilesTag(rawContent));
|
||||
return normalizeHumanMessageDisplayText(cleaned);
|
||||
}
|
||||
return rawContent ?? "";
|
||||
}, [rawContent, isHuman]);
|
||||
|
|
|
|||
|
|
@ -364,6 +364,20 @@ export function stripPriorityHintSuffix(content: string): string {
|
|||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize human-authored message text for markdown rendering.
|
||||
* - Decode literal "\n" into real line breaks.
|
||||
* - Split Chinese-numbered items (e.g. "1)...") into separate paragraphs.
|
||||
*/
|
||||
export function normalizeHumanMessageDisplayText(content: string): string {
|
||||
return content
|
||||
.replace(/\\n/g, "\n")
|
||||
.replace(/\r\n?/g, "\n")
|
||||
.replace(/\n(?=\d+[))]\s*)/g, "\n\n")
|
||||
.replace(/\n{3,}/g, "\n\n")
|
||||
.trim();
|
||||
}
|
||||
|
||||
export function parseUploadedFiles(content: string): FileInMessage[] {
|
||||
// Match <uploaded_files>...</uploaded_files> tag
|
||||
const uploadedFilesRegex = /<uploaded_files>([\s\S]*?)<\/uploaded_files>/;
|
||||
|
|
|
|||
Loading…
Reference in New Issue