diff --git a/app/utils/markdown.ts b/app/utils/markdown.ts index 262222bf55..579b6454fe 100644 --- a/app/utils/markdown.ts +++ b/app/utils/markdown.ts @@ -54,8 +54,28 @@ export const allowedHTMLElements = [ 'tr', 'ul', 'var', + 'think', ]; +// Add custom rehype plugin +function remarkThinkRawContent() { + return (tree: any) => { + visit(tree, (node: any) => { + if (node.type === 'html' && node.value && node.value.startsWith('')) { + const cleanedContent = node.value.slice(7); + node.value = `
${cleanedContent}`; + + return; + } + + if (node.type === 'html' && node.value && node.value.startsWith('')) { + const cleanedContent = node.value.slice(8); + node.value = `
${cleanedContent}`; + } + }); + }; +} + const rehypeSanitizeOptions: RehypeSanitizeOptions = { ...defaultSchema, tagNames: allowedHTMLElements, @@ -79,6 +99,8 @@ export function remarkPlugins(limitedMarkdown: boolean) { plugins.unshift(limitedMarkdownPlugin); } + plugins.unshift(remarkThinkRawContent); + return plugins; }