Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: webui supports math in markdown #1039

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions assets/arena.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
30 changes: 17 additions & 13 deletions assets/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Loading