refactor: Fixed redundant blank characters in message content

This commit is contained in:
choizhang
2025-04-22 01:25:18 +08:00
parent 522080e44f
commit 333c43fbdf
2 changed files with 5 additions and 6 deletions

View File

@@ -333,7 +333,6 @@ export const queryTextStream = async (
try { try {
const parsed = JSON.parse(line); const parsed = JSON.parse(line);
if (parsed.response) { if (parsed.response) {
console.log('Received chunk:', parsed.response); // Log for debugging
onChunk(parsed.response); onChunk(parsed.response);
} else if (parsed.error && onError) { } else if (parsed.error && onError) {
onError(parsed.error); onError(parsed.error);

View File

@@ -1,4 +1,4 @@
import { ReactNode, useCallback, useEffect, useState, useRef } from 'react' import { ReactNode, useCallback, useEffect, useRef } from 'react'
import { Message } from '@/api/lightrag' import { Message } from '@/api/lightrag'
import useTheme from '@/hooks/useTheme' import useTheme from '@/hooks/useTheme'
import Button from '@/components/ui/Button' import Button from '@/components/ui/Button'
@@ -24,6 +24,8 @@ export type MessageWithError = Message & {
export const ChatMessage = ({ message }: { message: MessageWithError }) => { export const ChatMessage = ({ message }: { message: MessageWithError }) => {
const { t } = useTranslation() const { t } = useTranslation()
// Remove extra spaces around bold text
message.content = message.content.replace(/\*\ {3}/g, '').replace(/\ {4}\*\*/g, '**')
const handleCopyMarkdown = useCallback(async () => { const handleCopyMarkdown = useCallback(async () => {
if (message.content) { if (message.content) {
@@ -47,9 +49,9 @@ export const ChatMessage = ({ message }: { message: MessageWithError }) => {
> >
<pre className="relative break-words whitespace-pre-wrap"> <pre className="relative break-words whitespace-pre-wrap">
<ReactMarkdown <ReactMarkdown
className="dark:prose-invert max-w-none text-sm" // Removed text-base as it might conflict className="dark:prose-invert max-w-none text-base text-sm"
remarkPlugins={[remarkGfm, remarkMath]} remarkPlugins={[remarkGfm, remarkMath]}
// Removed rehypeReact as it's often not needed with custom components and can cause issues rehypePlugins={[rehypeReact]}
skipHtml={false} skipHtml={false}
components={{ components={{
code: CodeHighlight code: CodeHighlight
@@ -168,8 +170,6 @@ const CodeHighlight = ({ className, children, node, ...props }: CodeHighlightPro
.filter(line => !line.trim().startsWith('linkStyle')) // Keep filtering linkStyle .filter(line => !line.trim().startsWith('linkStyle')) // Keep filtering linkStyle
.join('\n'); .join('\n');
console.log("Rendering Mermaid with debounced, filtered content:", processedContent);
const mermaidId = `mermaid-${Date.now()}`; const mermaidId = `mermaid-${Date.now()}`;
mermaid.render(mermaidId, processedContent) mermaid.render(mermaidId, processedContent)
.then(({ svg, bindFunctions }) => { .then(({ svg, bindFunctions }) => {