update pay function
This commit is contained in:
@@ -121,6 +121,17 @@ const parseMarkdownWithCharts = (markdown) => {
|
||||
export const MarkdownWithCharts = ({ content, variant = 'auto' }) => {
|
||||
const parts = parseMarkdownWithCharts(content);
|
||||
|
||||
// 开发环境调试日志
|
||||
if (process.env.NODE_ENV === 'development' && content?.includes('echarts')) {
|
||||
logger.info('[MarkdownWithCharts] 解析结果', {
|
||||
contentLength: content?.length,
|
||||
contentPreview: content?.substring(0, 100),
|
||||
partsCount: parts.length,
|
||||
partTypes: parts.map(p => p.type),
|
||||
hasChartPart: parts.some(p => p.type === 'chart'),
|
||||
});
|
||||
}
|
||||
|
||||
// 系统颜色模式
|
||||
const systemTextColor = useColorModeValue('gray.700', 'gray.100');
|
||||
const systemHeadingColor = useColorModeValue('gray.800', 'gray.50');
|
||||
@@ -182,16 +193,42 @@ export const MarkdownWithCharts = ({ content, variant = 'auto' }) => {
|
||||
{children}
|
||||
</Box>
|
||||
),
|
||||
code: ({ inline, children }) =>
|
||||
inline ? (
|
||||
<Code fontSize="sm" px={1} bg={codeBg}>
|
||||
// 处理代码块和行内代码
|
||||
code: ({ node, inline, className, children, ...props }) => {
|
||||
// 检查是否是代码块(通过父元素是否为 pre 或通过 className 判断)
|
||||
const isCodeBlock = !inline && (className || (node?.position?.start?.line !== node?.position?.end?.line));
|
||||
|
||||
if (isCodeBlock) {
|
||||
// 代码块样式
|
||||
return (
|
||||
<Code
|
||||
display="block"
|
||||
p={3}
|
||||
borderRadius="md"
|
||||
fontSize="sm"
|
||||
whiteSpace="pre-wrap"
|
||||
bg={codeBg}
|
||||
overflowX="auto"
|
||||
maxW="100%"
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Code>
|
||||
);
|
||||
}
|
||||
// 行内代码样式
|
||||
return (
|
||||
<Code fontSize="sm" px={1} bg={codeBg} {...props}>
|
||||
{children}
|
||||
</Code>
|
||||
) : (
|
||||
<Code display="block" p={3} borderRadius="md" fontSize="sm" whiteSpace="pre-wrap" bg={codeBg}>
|
||||
{children}
|
||||
</Code>
|
||||
),
|
||||
);
|
||||
},
|
||||
// 处理 pre 元素,防止嵌套问题
|
||||
pre: ({ children }) => (
|
||||
<Box as="pre" my={2} overflow="hidden" borderRadius="md">
|
||||
{children}
|
||||
</Box>
|
||||
),
|
||||
blockquote: ({ children }) => (
|
||||
<Box
|
||||
borderLeftWidth="4px"
|
||||
@@ -262,9 +299,12 @@ export const MarkdownWithCharts = ({ content, variant = 'auto' }) => {
|
||||
} else if (part.type === 'chart') {
|
||||
// 渲染 ECharts 图表
|
||||
try {
|
||||
// 清理可能的 Markdown 残留符号
|
||||
// 清理可能的 Markdown 残留符号和代码块标记
|
||||
let cleanContent = part.content.trim();
|
||||
|
||||
// 移除可能残留的代码块结束标记
|
||||
cleanContent = cleanContent.replace(/```\s*$/g, '').trim();
|
||||
|
||||
// 移除可能的前后空白和不可见字符
|
||||
cleanContent = cleanContent.replace(/^\s+|\s+$/g, '');
|
||||
|
||||
@@ -427,7 +467,14 @@ export const MarkdownWithCharts = ({ content, variant = 'auto' }) => {
|
||||
}
|
||||
|
||||
return (
|
||||
<Box key={index}>
|
||||
<Box
|
||||
key={index}
|
||||
w="100%"
|
||||
minW="300px"
|
||||
my={3}
|
||||
borderRadius="md"
|
||||
overflow="hidden"
|
||||
>
|
||||
<EChartsRenderer option={chartOption} height={350} variant={variant} />
|
||||
</Box>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user