prevent markdownish from modifying text inside code block
This commit is contained in:
parent
ec2a24fedf
commit
c2504b16d2
1 changed files with 23 additions and 23 deletions
|
@ -711,31 +711,31 @@
|
||||||
|
|
||||||
// poor mans markdown replacement
|
// poor mans markdown replacement
|
||||||
const Markdownish = (params) => {
|
const Markdownish = (params) => {
|
||||||
const md = params.text
|
const chunks = params.text.split('```');
|
||||||
.replace(/&/g, '&')
|
|
||||||
.replace(/</g, '<')
|
for (let i = 0; i < chunks.length; i++) {
|
||||||
.replace(/>/g, '>')
|
if (i % 2 === 0) { // outside code block
|
||||||
.replace(/^#{1,6} (.*)$/gim, '<h3>$1</h3>')
|
chunks[i] = chunks[i]
|
||||||
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
.replace(/&/g, '&')
|
||||||
.replace(/__(.*?)__/g, '<strong>$1</strong>')
|
.replace(/</g, '<')
|
||||||
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
.replace(/>/g, '>')
|
||||||
.replace(/_(.*?)_/g, '<em>$1</em>')
|
.replace(/^#{1,6} (.*)$/gim, '<h3>$1</h3>')
|
||||||
.replace(/```.*?\n([\s\S]*?)```/g, '<pre><code>$1</code></pre>')
|
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
||||||
.replace(/`(.*?)`/g, '<code>$1</code>')
|
.replace(/__(.*?)__/g, '<strong>$1</strong>')
|
||||||
.replace(/\n/gim, '<br />');
|
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
||||||
return html`<span dangerouslySetInnerHTML=${{ __html: md }} />`;
|
.replace(/_(.*?)_/g, '<em>$1</em>')
|
||||||
|
.replace(/`(.*?)`/g, '<code>$1</code>')
|
||||||
|
.replace(/\n/gim, '<br />');
|
||||||
|
} 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) => {
|
|
||||||
if (!llamaStats.value) {
|
|
||||||
return html`<span/>`
|
|
||||||
}
|
|
||||||
return html`
|
|
||||||
<span>
|
|
||||||
${llamaStats.value.predicted_per_token_ms.toFixed()}ms per token, ${llamaStats.value.predicted_per_second.toFixed(2)} tokens per second
|
|
||||||
</span>
|
|
||||||
`
|
|
||||||
}
|
|
||||||
|
|
||||||
// simple popover impl
|
// simple popover impl
|
||||||
const Popover = (props) => {
|
const Popover = (props) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue