From 07e58aaacd8c7f486a0d2a7c8d35a195f27d487e Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 3 Feb 2025 19:39:21 +0800 Subject: feat: webui support `think` tag (#1140) --- assets/playground.html | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'assets/playground.html') diff --git a/assets/playground.html b/assets/playground.html index e7b8e11..d038bd1 100644 --- a/assets/playground.html +++ b/assets/playground.html @@ -1490,8 +1490,35 @@ `; } }; + const thinkExtension = { + name: 'think', + level: 'block', + start(src) { + return src.indexOf(''); + }, + tokenizer(src, tokens) { + const rule = /^\s*([\s\S]*?)(<\/think>|$)/; + const match = rule.exec(src); + if (match) { + return { + type: 'think', + raw: match[0], + text: match[1].trim(), + }; + } + }, + renderer(token) { + const isOpen = !token.raw.endsWith(''); + const text = '

' + token.text.trim().replace(/\n+/g, '

') + '

'; + return `
+ Deeply thought +
${text}
+
`; + }, + }; marked.use({ renderer }); marked.use(markedKatex({ throwOnError: false, inlineTolerantNoSpace: true })); + marked.use({ extensions: [thinkExtension] }) } function escapeForHTML(input) { -- cgit v1.2.3