mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-03-10 06:00:19 +00:00
feat: support for <think></think> tags to allow reasoning tokens formatted in UI (#1205)
This commit is contained in:
parent
32bfdd9c24
commit
a199295ad8
@ -54,8 +54,28 @@ export const allowedHTMLElements = [
|
|||||||
'tr',
|
'tr',
|
||||||
'ul',
|
'ul',
|
||||||
'var',
|
'var',
|
||||||
|
'think',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Add custom rehype plugin
|
||||||
|
function remarkThinkRawContent() {
|
||||||
|
return (tree: any) => {
|
||||||
|
visit(tree, (node: any) => {
|
||||||
|
if (node.type === 'html' && node.value && node.value.startsWith('<think>')) {
|
||||||
|
const cleanedContent = node.value.slice(7);
|
||||||
|
node.value = `<div class="__boltThought__">${cleanedContent}`;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.type === 'html' && node.value && node.value.startsWith('</think>')) {
|
||||||
|
const cleanedContent = node.value.slice(8);
|
||||||
|
node.value = `</div>${cleanedContent}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const rehypeSanitizeOptions: RehypeSanitizeOptions = {
|
const rehypeSanitizeOptions: RehypeSanitizeOptions = {
|
||||||
...defaultSchema,
|
...defaultSchema,
|
||||||
tagNames: allowedHTMLElements,
|
tagNames: allowedHTMLElements,
|
||||||
@ -79,6 +99,8 @@ export function remarkPlugins(limitedMarkdown: boolean) {
|
|||||||
plugins.unshift(limitedMarkdownPlugin);
|
plugins.unshift(limitedMarkdownPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugins.unshift(remarkThinkRawContent);
|
||||||
|
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user