浏览代码

fix: regex expressions distorted in code block (#16690)

tags/1.2.0
诗浓 7 个月前
父节点
当前提交
af5d6ca27d
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12
    2
      web/app/components/base/markdown.tsx

+ 12
- 2
web/app/components/base/markdown.tsx 查看文件

if (typeof content !== 'string') if (typeof content !== 'string')
return content return content


return flow([
const codeBlockRegex = /```[\s\S]*?```/g
const codeBlocks = content.match(codeBlockRegex) || []
let processedContent = content.replace(codeBlockRegex, 'CODE_BLOCK_PLACEHOLDER')

processedContent = flow([
(str: string) => str.replace(/\\\[(.*?)\\\]/g, (_, equation) => `$$${equation}$$`), (str: string) => str.replace(/\\\[(.*?)\\\]/g, (_, equation) => `$$${equation}$$`),
(str: string) => str.replace(/\\\[(.*?)\\\]/gs, (_, equation) => `$$${equation}$$`), (str: string) => str.replace(/\\\[(.*?)\\\]/gs, (_, equation) => `$$${equation}$$`),
(str: string) => str.replace(/\\\((.*?)\\\)/g, (_, equation) => `$$${equation}$$`), (str: string) => str.replace(/\\\((.*?)\\\)/g, (_, equation) => `$$${equation}$$`),
(str: string) => str.replace(/(^|[^\\])\$(.+?)\$/g, (_, prefix, equation) => `${prefix}$${equation}$`), (str: string) => str.replace(/(^|[^\\])\$(.+?)\$/g, (_, prefix, equation) => `${prefix}$${equation}$`),
])(content)
])(processedContent)

codeBlocks.forEach((block) => {
processedContent = processedContent.replace('CODE_BLOCK_PLACEHOLDER', block)
})

return processedContent
} }


const preprocessThinkTag = (content: string) => { const preprocessThinkTag = (content: string) => {

正在加载...
取消
保存