Skip to content

Commit

Permalink
feat: support for <think></think> tags to allow reasoning tokens form…
Browse files Browse the repository at this point in the history
…atted in UI (stackblitz-labs#1205)
  • Loading branch information
thecodacus authored Jan 28, 2025
1 parent 32bfdd9 commit a199295
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/utils/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('<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 = {
...defaultSchema,
tagNames: allowedHTMLElements,
Expand All @@ -79,6 +99,8 @@ export function remarkPlugins(limitedMarkdown: boolean) {
plugins.unshift(limitedMarkdownPlugin);
}

plugins.unshift(remarkThinkRawContent);

return plugins;
}

Expand Down

0 comments on commit a199295

Please sign in to comment.