feat: support for <think></think> tags to allow reasoning tokens formatted in UI (#1205)
Browse files- app/utils/markdown.ts +22 -0
app/utils/markdown.ts
CHANGED
@@ -54,8 +54,28 @@ export const allowedHTMLElements = [
|
|
54 |
'tr',
|
55 |
'ul',
|
56 |
'var',
|
|
|
57 |
];
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
const rehypeSanitizeOptions: RehypeSanitizeOptions = {
|
60 |
...defaultSchema,
|
61 |
tagNames: allowedHTMLElements,
|
@@ -79,6 +99,8 @@ export function remarkPlugins(limitedMarkdown: boolean) {
|
|
79 |
plugins.unshift(limitedMarkdownPlugin);
|
80 |
}
|
81 |
|
|
|
|
|
82 |
return plugins;
|
83 |
}
|
84 |
|
|
|
54 |
'tr',
|
55 |
'ul',
|
56 |
'var',
|
57 |
+
'think',
|
58 |
];
|
59 |
|
60 |
+
// Add custom rehype plugin
|
61 |
+
function remarkThinkRawContent() {
|
62 |
+
return (tree: any) => {
|
63 |
+
visit(tree, (node: any) => {
|
64 |
+
if (node.type === 'html' && node.value && node.value.startsWith('<think>')) {
|
65 |
+
const cleanedContent = node.value.slice(7);
|
66 |
+
node.value = `<div class="__boltThought__">${cleanedContent}`;
|
67 |
+
|
68 |
+
return;
|
69 |
+
}
|
70 |
+
|
71 |
+
if (node.type === 'html' && node.value && node.value.startsWith('</think>')) {
|
72 |
+
const cleanedContent = node.value.slice(8);
|
73 |
+
node.value = `</div>${cleanedContent}`;
|
74 |
+
}
|
75 |
+
});
|
76 |
+
};
|
77 |
+
}
|
78 |
+
|
79 |
const rehypeSanitizeOptions: RehypeSanitizeOptions = {
|
80 |
...defaultSchema,
|
81 |
tagNames: allowedHTMLElements,
|
|
|
99 |
plugins.unshift(limitedMarkdownPlugin);
|
100 |
}
|
101 |
|
102 |
+
plugins.unshift(remarkThinkRawContent);
|
103 |
+
|
104 |
return plugins;
|
105 |
}
|
106 |
|