Fix markdown preprocessing

This commit is contained in:
Saoud Rizwan
2024-10-05 21:57:43 -04:00
parent 636e6927f7
commit 6c03fdfbb9
2 changed files with 24 additions and 22 deletions

View File

@@ -800,25 +800,9 @@ const ProgressIndicator = () => (
)
const Markdown = memo(({ markdown }: { markdown?: string }) => {
const withoutThinkingTags = useMemo(() => {
if (!markdown) return ""
let processed = markdown
// Remove end substrings of <thinking or </thinking
processed = processed.replace(/<\/?t(?:h(?:i(?:n(?:k(?:i(?:n(?:g)?)?)?)?)?)?)?$/, "")
// Remove all instances of <thinking> (with optional line break after) and </thinking> (with optional line break before)
// Needs to be separate since we dont want to remove the line break before the first tag
processed = processed.replace(/<thinking>\s?/g, "")
processed = processed.replace(/\s?<\/thinking>/g, "")
return processed
}, [markdown])
return (
<div style={{ wordBreak: "break-word", overflowWrap: "anywhere", marginBottom: -15, marginTop: -15 }}>
<MarkdownBlock markdown={withoutThinkingTags} />
<MarkdownBlock markdown={markdown} />
</div>
)
})