mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-30 08:42:00 +00:00 
			
		
		
		
	Markdownish code block fix (#7571)
* markdownish codeblock fix * updating regexes
This commit is contained in:
		| @@ -877,7 +877,11 @@ | |||||||
|  |  | ||||||
|     // poor mans markdown replacement |     // poor mans markdown replacement | ||||||
|     const Markdownish = (params) => { |     const Markdownish = (params) => { | ||||||
|       const md = params.text |       const chunks = params.text.split('```'); | ||||||
|  |  | ||||||
|  |       for (let i = 0; i < chunks.length; i++) { | ||||||
|  |         if (i % 2 === 0) { // outside code block | ||||||
|  |           chunks[i] = chunks[i] | ||||||
|           .replace(/&/g, '&') |           .replace(/&/g, '&') | ||||||
|           .replace(/</g, '<') |           .replace(/</g, '<') | ||||||
|           .replace(/>/g, '>') |           .replace(/>/g, '>') | ||||||
| @@ -889,7 +893,14 @@ | |||||||
|           .replace(/```.*?\n([\s\S]*?)```/g, '<pre><code>$1</code></pre>') |           .replace(/```.*?\n([\s\S]*?)```/g, '<pre><code>$1</code></pre>') | ||||||
|           .replace(/`(.*?)`/g, '<code>$1</code>') |           .replace(/`(.*?)`/g, '<code>$1</code>') | ||||||
|           .replace(/\n/gim, '<br />'); |           .replace(/\n/gim, '<br />'); | ||||||
|       return html`<span dangerouslySetInnerHTML=${{ __html: md }} />`; |         } else { // inside code block | ||||||
|  |           chunks[i] = `<pre><code>${chunks[i]}</code></pre>`; | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       const restoredText = chunks.join(''); | ||||||
|  |  | ||||||
|  |       return html`<span dangerouslySetInnerHTML=${{ __html: restoredText }} />`; | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     const ModelGenerationInfo = (params) => { |     const ModelGenerationInfo = (params) => { | ||||||
| @@ -903,6 +914,7 @@ | |||||||
|       ` |       ` | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     // simple popover impl |     // simple popover impl | ||||||
|     const Popover = (props) => { |     const Popover = (props) => { | ||||||
|       const isOpen = useSignal(false); |       const isOpen = useSignal(false); | ||||||
| @@ -1054,4 +1066,3 @@ | |||||||
| </body> | </body> | ||||||
|  |  | ||||||
| </html> | </html> | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Nathan Epstein
					Nathan Epstein