-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: webui supports math in markdown (#1039)
- Loading branch information
Showing
2 changed files
with
34 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,16 @@ | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="icon" href="data:;base64,iVBORw0KGgo="> | ||
<title>AIChat LLM Arena</title> | ||
<link rel="stylesheet" href="//unpkg.com/[email protected]/dist/katex.min.css"> | ||
<link rel="stylesheet" href="//unpkg.com/[email protected]/github-markdown.css"> | ||
<link rel="stylesheet" href="//unpkg.com/@highlightjs/[email protected]/styles/github-dark.min.css" | ||
media="screen and (prefers-color-scheme: dark)"> | ||
<link rel="stylesheet" href="//unpkg.com/@highlightjs/[email protected]/styles/github.min.css" | ||
media="screen and (prefers-color-scheme: light)"> | ||
<script src="//unpkg.com/@highlightjs/[email protected]/highlight.min.js"></script> | ||
<script src="//unpkg.com/[email protected]/lib/marked.umd.js" defer></script> | ||
<script src="//unpkg.com/@highlightjs/[email protected]/highlight.min.js" defer></script> | ||
<script src="//unpkg.com/[email protected]/lib/marked.umd.js" defer></script> | ||
<script src="//unpkg.com/[email protected]/dist/katex.min.js" defer></script> | ||
<script src="//unpkg.com/@sigodenjs/[email protected]/lib/index.umd.js" defer></script> | ||
<script src="//unpkg.com/[email protected]/dist/cdn.min.js" defer></script> | ||
<style> | ||
:root { | ||
|
@@ -989,24 +992,25 @@ | |
} | ||
|
||
function setupMarked() { | ||
const renderer = new marked.Renderer(); | ||
renderer.code = (code, language) => { | ||
const validLang = !!(language && hljs.getLanguage(language)); | ||
|
||
const highlighted = validLang | ||
? hljs.highlight(code, { language }).value | ||
: escapeForHTML(code); | ||
|
||
return `<div class="code-block"> | ||
<pre><code class="hljs ${language}">${highlighted}</code></pre> | ||
const renderer = { | ||
code({ text, lang }) { | ||
const validLang = !!(lang && hljs.getLanguage(lang)); | ||
const highlighted = validLang | ||
? hljs.highlight(text, { language: lang }).value | ||
: escapeForHTML(text); | ||
|
||
return `<div class="code-block"> | ||
<pre><code class="hljs ${lang}">${highlighted}</code></pre> | ||
<div class="copy-code-btn" @click="handleCopyCode" title="Copy code"> | ||
<svg fill="currentColor" viewBox="0 0 16 16"> | ||
<path fill-rule="evenodd" d="M4 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1zM2 5a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-1h1v1a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h1v1z"/> | ||
</svg> | ||
</div> | ||
</div>`; | ||
} | ||
}; | ||
marked.setOptions({ renderer }); | ||
marked.use({ renderer }); | ||
marked.use(markedKatex({ throwOnError: false, inlineTolerantNoSpace: true })); | ||
} | ||
|
||
function escapeForHTML(input) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,16 @@ | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="icon" href="data:;base64,iVBORw0KGgo="> | ||
<title>AIChat LLM Playground</title> | ||
<link rel="stylesheet" href="//unpkg.com/[email protected]/dist/katex.min.css"> | ||
<link rel="stylesheet" href="//unpkg.com/[email protected]/github-markdown.css"> | ||
<link rel="stylesheet" href="//unpkg.com/@highlightjs/[email protected]/styles/github-dark.min.css" | ||
media="screen and (prefers-color-scheme: dark)"> | ||
<link rel="stylesheet" href="//unpkg.com/@highlightjs/[email protected]/styles/github.min.css" | ||
media="screen and (prefers-color-scheme: light)"> | ||
<script src="//unpkg.com/@highlightjs/[email protected]/highlight.min.js"></script> | ||
<script src="//unpkg.com/[email protected]/lib/marked.umd.js" defer></script> | ||
<script src="//unpkg.com/@highlightjs/[email protected]/highlight.min.js" defer></script> | ||
<script src="//unpkg.com/[email protected]/lib/marked.umd.js" defer></script> | ||
<script src="//unpkg.com/[email protected]/dist/katex.min.js" defer></script> | ||
<script src="//unpkg.com/@sigodenjs/[email protected]/lib/index.umd.js" defer></script> | ||
<script src="//unpkg.com/[email protected]/dist/cdn.min.js" defer></script> | ||
<style> | ||
:root { | ||
|
@@ -1470,24 +1473,25 @@ | |
} | ||
|
||
function setupMarked() { | ||
const renderer = new marked.Renderer(); | ||
renderer.code = (code, language) => { | ||
const validLang = !!(language && hljs.getLanguage(language)); | ||
|
||
const highlighted = validLang | ||
? hljs.highlight(code, { language }).value | ||
: escapeForHTML(code); | ||
|
||
return `<div class="code-block"> | ||
<pre><code class="hljs ${language}">${highlighted}</code></pre> | ||
const renderer = { | ||
code({ text, lang }) { | ||
const validLang = !!(lang && hljs.getLanguage(lang)); | ||
const highlighted = validLang | ||
? hljs.highlight(text, { language: lang }).value | ||
: escapeForHTML(text); | ||
|
||
return `<div class="code-block"> | ||
<pre><code class="hljs ${lang}">${highlighted}</code></pre> | ||
<div class="copy-code-btn" @click="handleCopyCode" title="Copy code"> | ||
<svg fill="currentColor" viewBox="0 0 16 16"> | ||
<path fill-rule="evenodd" d="M4 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1zM2 5a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-1h1v1a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h1v1z"/> | ||
</svg> | ||
</div> | ||
</div>`; | ||
} | ||
}; | ||
marked.setOptions({ renderer }); | ||
marked.use({ renderer }); | ||
marked.use(markedKatex({ throwOnError: false, inlineTolerantNoSpace: true })); | ||
} | ||
|
||
function escapeForHTML(input) { | ||
|