mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-21 17:05:22 +03:00
fix: escape backticks within codeblocks
resolves https://github.com/elk-zone/elk/issues/970
This commit is contained in:
parent
a12d3d09b1
commit
8da4a8e78a
3 changed files with 11 additions and 1 deletions
|
@ -55,7 +55,10 @@ export function parseMastodonHTML(
|
|||
// Handle code blocks
|
||||
html = html
|
||||
.replace(/>(```|~~~)(\w*)([\s\S]+?)\1/g, (_1, _2, lang: string, raw: string) => {
|
||||
const code = htmlToText(raw).replace(/</g, '<').replace(/>/g, '>')
|
||||
const code = htmlToText(raw)
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/`/, '`')
|
||||
const classes = lang ? ` class="language-${lang}"` : ''
|
||||
return `><pre><code${classes}>${code}</code></pre>`
|
||||
})
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
// Vitest Snapshot v1
|
||||
|
||||
exports[`content-rich > block with backticks 1`] = `"<p><pre>[(\`number string) (\`tag string)]</pre></p>"`;
|
||||
|
||||
exports[`content-rich > code frame 1`] = `
|
||||
"<p>Testing code block</p><p></p><p><pre lang=\\"ts\\">import { useMouse, usePreferredDark } from '@vueuse/core'
|
||||
// tracks mouse position
|
||||
|
|
|
@ -20,6 +20,11 @@ describe('content-rich', () => {
|
|||
expect(formatted).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it ('block with backticks', async () => {
|
||||
const { formatted } = await render('<p>```<br />[(`number string) (`tag string)]<br />```</p>')
|
||||
expect(formatted).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('group mention', async () => {
|
||||
const { formatted } = await render('<p><span class="h-card"><a href="https://lemmy.ml/c/pilipinas" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>pilipinas</span></a></span></p>', undefined, [{ id: '', username: 'pilipinas', url: 'https://lemmy.ml/c/pilipinas', acct: 'pilipinas@lemmy.ml' }])
|
||||
expect(formatted).toMatchSnapshot('html')
|
||||
|
|
Loading…
Reference in a new issue