diff options
| author | sigoden <sigoden@gmail.com> | 2025-02-03 19:39:21 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-03 19:39:21 +0800 |
| commit | 07e58aaacd8c7f486a0d2a7c8d35a195f27d487e (patch) | |
| tree | 82d015218a20b84593197279e44b7a70a19a1683 /assets | |
| parent | 458cfc4ad16c509e1aaec8ce2a7d555519861d67 (diff) | |
| download | aichat-07e58aaacd8c7f486a0d2a7c8d35a195f27d487e.tar.gz | |
feat: webui support `think` tag (#1140)
Diffstat (limited to 'assets')
| -rw-r--r-- | assets/arena.html | 29 | ||||
| -rw-r--r-- | assets/playground.html | 27 |
2 files changed, 55 insertions, 1 deletions
diff --git a/assets/arena.html b/assets/arena.html index 7adad83..31973eb 100644 --- a/assets/arena.html +++ b/assets/arena.html @@ -1009,8 +1009,35 @@ </div>`; } }; + const thinkExtension = { + name: 'think', + level: 'block', + start(src) { + return src.indexOf('<think>'); + }, + tokenizer(src, tokens) { + const rule = /^\s*<think>([\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('</think>'); + const text = '<p>' + token.text.trim().replace(/\n+/g, '</p><p>') + '</p>'; + return `<details ${isOpen ? "open" : ""} class="think"> + <summary>Deeply thought</summary> + <blockquote>${text}</blockquote> + </details>`; + }, + }; marked.use({ renderer }); - marked.use(markedKatex({ throwOnError: false, inlineTolerantNoSpace: true })); + marked.use(markedKatex({ throwOnError: false, inlineTolerantNoSpace: true })); + marked.use({ extensions: [thinkExtension] }) } function escapeForHTML(input) { 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 @@ </div>`; } }; + const thinkExtension = { + name: 'think', + level: 'block', + start(src) { + return src.indexOf('<think>'); + }, + tokenizer(src, tokens) { + const rule = /^\s*<think>([\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('</think>'); + const text = '<p>' + token.text.trim().replace(/\n+/g, '</p><p>') + '</p>'; + return `<details ${isOpen ? "open" : ""} class="think"> + <summary>Deeply thought</summary> + <blockquote>${text}</blockquote> + </details>`; + }, + }; marked.use({ renderer }); marked.use(markedKatex({ throwOnError: false, inlineTolerantNoSpace: true })); + marked.use({ extensions: [thinkExtension] }) } function escapeForHTML(input) { |
