export enum CodeClassNameEnum { guide = 'guide', questionguide = 'questionguide', mermaid = 'mermaid', echarts = 'echarts', quote = 'quote', files = 'files', latex = 'latex', iframe = 'iframe', html = 'html', svg = 'svg', video = 'video', audio = 'audio' } export const mdTextFormat = (text: string) => { // NextChat function - Format latex to $$ const pattern = /(```[\s\S]*?```|`.*?`)|\\\[([\s\S]*?[^\\])\\\]|\\\((.*?)\\\)/g; text = text.replace(pattern, (match, codeBlock, squareBracket, roundBracket) => { if (codeBlock) { return codeBlock; } else if (squareBracket) { return `$$${squareBracket}$$`; } else if (roundBracket) { return `$${roundBracket}$`; } return match; }); // 处理 [quote:id] 格式引用,将 [quote:675934a198f46329dfc6d05a] 转换为 [675934a198f46329dfc6d05a](QUOTE) text = text // .replace( // /([\u4e00-\u9fa5\u3000-\u303f])([a-zA-Z0-9])|([a-zA-Z0-9])([\u4e00-\u9fa5\u3000-\u303f])/g, // '$1$3 $2$4' // ) // 处理 [quote:id] 格式引用,将 [quote:675934a198f46329dfc6d05a] 转换为 [675934a198f46329dfc6d05a](QUOTE) .replace(/\[quote:?\s*([a-f0-9]{24})\](?!\()/gi, '[$1](QUOTE)') .replace(/\[([a-f0-9]{24})\](?!\()/g, '[$1](QUOTE)'); // 处理链接后的中文标点符号,增加空格 text = text.replace(/(https?:\/\/[^\s,。!?;:、]+)([,。!?;:、])/g, '$1 $2'); return text; };