diff --git a/examples/server/public/index.html b/examples/server/public/index.html index bf1d1b794..6e8d14141 100644 --- a/examples/server/public/index.html +++ b/examples/server/public/index.html @@ -12,7 +12,7 @@ .markdown { h1, h2, h3, h4, h5, h6, ul, ol, li { all: revert; } pre { - @apply whitespace-pre-wrap my-4 rounded-lg p-2; + @apply whitespace-pre-wrap rounded-lg p-2; border: 1px solid currentColor; } /* TODO: fix markdown table */ @@ -234,9 +234,13 @@ import { createApp, defineComponent, shallowRef, computed, h } from './deps_vue.esm-browser.js'; import { llama } from './completion.js'; + // utility functions const isString = (x) => !!x.toLowerCase; const isNumeric = (n) => !isString(n) && !isNaN(n); + const escapeAttr = (str) => str.replace(/>/g, '>').replace(/"/g, '"'); + const copyStr = (str) => navigator.clipboard.writeText(str); + // constants const BASE_URL = localStorage.getItem('base') // for debugging || (new URL('.', document.baseURI).href).toString(); // for production const CONFIG_DEFAULT = { @@ -259,14 +263,23 @@ // markdown support const VueMarkdown = defineComponent( (props) => { - const md = shallowRef(new markdownit(props.options ?? { breaks: true })); - for (const plugin of props.plugins ?? []) { - md.value.use(plugin); - } + const md = shallowRef(new markdownit({ breaks: true })); + const origFenchRenderer = md.value.renderer.rules.fence; + md.value.renderer.rules.fence = (tokens, idx, ...args) => { + const content = tokens[idx].content; + const origRendered = origFenchRenderer(tokens, idx, ...args); + return `
+ + ${origRendered} +
`; + }; + window.copyStr = copyStr; const content = computed(() => md.value.render(props.source)); return () => h("div", { innerHTML: content.value }); }, - { props: ["source", "options", "plugins"] } + { props: ["source"] } ); // coversations is stored in localStorage @@ -512,7 +525,7 @@ this.generateMessage(currConvId); }, copyMsg(msg) { - navigator.clipboard.writeText(msg.content); + copyStr(msg.content); }, editUserMsgAndRegenerate(msg) { if (this.isGenerating) return;