fix: 优化markdown解析器

This commit is contained in:
imeepos 2025-07-22 18:06:46 +08:00
parent 9a0ddb72d5
commit 9d3eb6d925
4 changed files with 51 additions and 19 deletions

View File

@ -14,7 +14,7 @@ use std::sync::{Arc, Mutex};
// 导入会话管理相关模块 // 导入会话管理相关模块
use crate::data::models::conversation::{ use crate::data::models::conversation::{
ConversationMessage, MessageRole, MessageContent, ConversationHistoryQuery, ConversationMessage, MessageRole, MessageContent, ConversationHistoryQuery,
CreateConversationSessionRequest, AddMessageRequest, AddMessageRequest,
}; };
use crate::data::repositories::conversation_repository::ConversationRepository; use crate::data::repositories::conversation_repository::ConversationRepository;

View File

@ -401,6 +401,8 @@ export const ChatInterface: React.FC<ChatInterfaceProps> = ({
showSources={showSources} showSources={showSources}
enableMaterialCards={enableImageCards} enableMaterialCards={enableImageCards}
enableReferences={true} enableReferences={true}
selectedTags={selectedTags}
onTagClick={toggleTag}
/> />
))} ))}
</> </>

View File

@ -47,6 +47,10 @@ interface EnhancedChatMessageV2Props {
enableReferences?: boolean; enableReferences?: boolean;
/** 自定义样式类名 */ /** 自定义样式类名 */
className?: string; className?: string;
/** 已选中的标签列表 */
selectedTags?: string[];
/** 标签点击回调 */
onTagClick?: (tag: string) => void;
} }
/** /**
@ -58,7 +62,9 @@ export const EnhancedChatMessageV2: React.FC<EnhancedChatMessageV2Props> = ({
showSources = true, showSources = true,
enableMaterialCards = true, enableMaterialCards = true,
enableReferences = true, enableReferences = true,
className = '' className = '',
selectedTags = [],
onTagClick
}) => { }) => {
const [copied, setCopied] = useState(false); const [copied, setCopied] = useState(false);
const [expandedSources, setExpandedSources] = useState(false); const [expandedSources, setExpandedSources] = useState(false);
@ -205,6 +211,8 @@ export const EnhancedChatMessageV2: React.FC<EnhancedChatMessageV2Props> = ({
showDetails={true} showDetails={true}
className="cursor-pointer" className="cursor-pointer"
onViewLarge={() => handleMaterialClick(source as GroundingSource)} onViewLarge={() => handleMaterialClick(source as GroundingSource)}
selectedTags={selectedTags}
onTagClick={onTagClick}
/> />
))} ))}
</div> </div>

View File

@ -34,6 +34,10 @@ interface ImageCardProps {
onViewLarge?: (source: GroundingSource) => void; onViewLarge?: (source: GroundingSource) => void;
/** 自定义样式类名 */ /** 自定义样式类名 */
className?: string; className?: string;
/** 已选中的标签列表 */
selectedTags?: string[];
/** 标签点击回调 */
onTagClick?: (tag: string) => void;
} }
/** /**
@ -46,7 +50,9 @@ export const ImageCard: React.FC<ImageCardProps> = ({
position, position,
onClose, onClose,
onDownload, onDownload,
className = '' className = '',
selectedTags = [],
onTagClick
}) => { }) => {
const [imageLoaded, setImageLoaded] = useState(false); const [imageLoaded, setImageLoaded] = useState(false);
const [imageError, setImageError] = useState(false); const [imageError, setImageError] = useState(false);
@ -186,14 +192,22 @@ export const ImageCard: React.FC<ImageCardProps> = ({
<div className="flex items-start space-x-2"> <div className="flex items-start space-x-2">
<MapPin className="w-3 h-3 text-gray-400 mt-0.5 flex-shrink-0" /> <MapPin className="w-3 h-3 text-gray-400 mt-0.5 flex-shrink-0" />
<div className="flex flex-wrap gap-1 min-w-0"> <div className="flex flex-wrap gap-1 min-w-0">
{(expandedEnvironmentTags ? environmentTags : environmentTags.slice(0, 2)).map((tag: string, index: number) => ( {(expandedEnvironmentTags ? environmentTags : environmentTags.slice(0, 2)).map((tag: string, index: number) => {
<span const isSelected = selectedTags.includes(tag);
key={index} return (
className="px-2 py-1 bg-blue-50 text-blue-700 text-xs rounded-md font-medium" <button
> key={index}
{tag} onClick={() => onTagClick?.(tag)}
</span> className={`px-2 py-1 text-xs rounded-md font-medium transition-all duration-200 cursor-pointer ${
))} isSelected
? 'bg-pink-500 text-white shadow-md transform scale-105'
: 'bg-blue-50 text-blue-700 hover:bg-pink-100 hover:text-pink-700'
}`}
>
{tag}
</button>
);
})}
{environmentTags.length > 2 && ( {environmentTags.length > 2 && (
<button <button
onClick={() => setExpandedEnvironmentTags(!expandedEnvironmentTags)} onClick={() => setExpandedEnvironmentTags(!expandedEnvironmentTags)}
@ -211,14 +225,22 @@ export const ImageCard: React.FC<ImageCardProps> = ({
<div className="flex items-start space-x-2"> <div className="flex items-start space-x-2">
<Shirt className="w-3 h-3 text-gray-400 mt-0.5 flex-shrink-0" /> <Shirt className="w-3 h-3 text-gray-400 mt-0.5 flex-shrink-0" />
<div className="flex flex-wrap gap-1 min-w-0"> <div className="flex flex-wrap gap-1 min-w-0">
{(expandedCategories ? categories : categories.slice(0, 2)).map((category: string, index: number) => ( {(expandedCategories ? categories : categories.slice(0, 2)).map((category: string, index: number) => {
<span const isSelected = selectedTags.includes(category);
key={index} return (
className="px-2 py-1 bg-pink-50 text-pink-700 text-xs rounded-md font-medium" <button
> key={index}
{category} onClick={() => onTagClick?.(category)}
</span> className={`px-2 py-1 text-xs rounded-md font-medium transition-all duration-200 cursor-pointer ${
))} isSelected
? 'bg-pink-500 text-white shadow-md transform scale-105'
: 'bg-pink-50 text-pink-700 hover:bg-pink-100 hover:text-pink-800'
}`}
>
{category}
</button>
);
})}
{categories.length > 2 && ( {categories.length > 2 && (
<button <button
onClick={() => setExpandedCategories(!expandedCategories)} onClick={() => setExpandedCategories(!expandedCategories)}