|
877 | 877 |
|
878 | 878 | // poor mans markdown replacement
|
879 | 879 | const Markdownish = (params) => {
|
880 |
| - const md = params.text |
881 |
| - .replace(/&/g, '&') |
882 |
| - .replace(/</g, '<') |
883 |
| - .replace(/>/g, '>') |
884 |
| - .replace(/(^|\n)#{1,6} ([^\n]*)(?=([^`]*`[^`]*`)*[^`]*$)/g, '$1<h3>$2</h3>') |
885 |
| - .replace(/\*\*(.*?)\*\*(?=([^`]*`[^`]*`)*[^`]*$)/g, '<strong>$1</strong>') |
886 |
| - .replace(/__(.*?)__(?=([^`]*`[^`]*`)*[^`]*$)/g, '<strong>$1</strong>') |
887 |
| - .replace(/\*(.*?)\*(?=([^`]*`[^`]*`)*[^`]*$)/g, '<em>$1</em>') |
888 |
| - .replace(/_(.*?)_(?=([^`]*`[^`]*`)*[^`]*$)/g, '<em>$1</em>') |
889 |
| - .replace(/```.*?\n([\s\S]*?)```/g, '<pre><code>$1</code></pre>') |
890 |
| - .replace(/`(.*?)`/g, '<code>$1</code>') |
891 |
| - .replace(/\n/gim, '<br />'); |
892 |
| - return html`<span dangerouslySetInnerHTML=${{ __html: md }} />`; |
| 880 | + const chunks = params.text.split('```'); |
| 881 | + |
| 882 | + for (let i = 0; i < chunks.length; i++) { |
| 883 | + if (i % 2 === 0) { // outside code block |
| 884 | + chunks[i] = chunks[i] |
| 885 | + .replace(/&/g, '&') |
| 886 | + .replace(/</g, '<') |
| 887 | + .replace(/>/g, '>') |
| 888 | + .replace(/(^|\n)#{1,6} ([^\n]*)(?=([^`]*`[^`]*`)*[^`]*$)/g, '$1<h3>$2</h3>') |
| 889 | + .replace(/\*\*(.*?)\*\*(?=([^`]*`[^`]*`)*[^`]*$)/g, '<strong>$1</strong>') |
| 890 | + .replace(/__(.*?)__(?=([^`]*`[^`]*`)*[^`]*$)/g, '<strong>$1</strong>') |
| 891 | + .replace(/\*(.*?)\*(?=([^`]*`[^`]*`)*[^`]*$)/g, '<em>$1</em>') |
| 892 | + .replace(/_(.*?)_(?=([^`]*`[^`]*`)*[^`]*$)/g, '<em>$1</em>') |
| 893 | + .replace(/```.*?\n([\s\S]*?)```/g, '<pre><code>$1</code></pre>') |
| 894 | + .replace(/`(.*?)`/g, '<code>$1</code>') |
| 895 | + .replace(/\n/gim, '<br />'); |
| 896 | + } else { // inside code block |
| 897 | + chunks[i] = `<pre><code>${chunks[i]}</code></pre>`; |
| 898 | + } |
| 899 | + } |
| 900 | + |
| 901 | + const restoredText = chunks.join(''); |
| 902 | + |
| 903 | + return html`<span dangerouslySetInnerHTML=${{ __html: restoredText }} />`; |
893 | 904 | };
|
894 | 905 |
|
895 | 906 | const ModelGenerationInfo = (params) => {
|
|
903 | 914 | `
|
904 | 915 | }
|
905 | 916 |
|
| 917 | + |
906 | 918 | // simple popover impl
|
907 | 919 | const Popover = (props) => {
|
908 | 920 | const isOpen = useSignal(false);
|
@@ -1054,4 +1066,3 @@ <h1>llama.cpp</h1>
|
1054 | 1066 | </body>
|
1055 | 1067 |
|
1056 | 1068 | </html>
|
1057 |
| - |
|
0 commit comments