diff --git a/composables/content-parse.ts b/composables/content-parse.ts index dea3d5b2..845cdb09 100644 --- a/composables/content-parse.ts +++ b/composables/content-parse.ts @@ -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, '>') + const code = htmlToText(raw) + .replace(//g, '>') + .replace(/`/, '`') const classes = lang ? ` class="language-${lang}"` : '' return `>
${code}
` }) diff --git a/tests/__snapshots__/content-rich.test.ts.snap b/tests/__snapshots__/content-rich.test.ts.snap index c7202ea1..f48d4942 100644 --- a/tests/__snapshots__/content-rich.test.ts.snap +++ b/tests/__snapshots__/content-rich.test.ts.snap @@ -1,5 +1,7 @@ // Vitest Snapshot v1 +exports[`content-rich > block with backticks 1`] = `"

[(\`number string) (\`tag string)]

"`; + exports[`content-rich > code frame 1`] = ` "

Testing code block

import { useMouse, usePreferredDark } from '@vueuse/core'
 // tracks mouse position
diff --git a/tests/content-rich.test.ts b/tests/content-rich.test.ts
index c3df5b0c..920ab457 100644
--- a/tests/content-rich.test.ts
+++ b/tests/content-rich.test.ts
@@ -20,6 +20,11 @@ describe('content-rich', () => {
     expect(formatted).toMatchSnapshot()
   })
 
+  it ('block with backticks', async () => {
+    const { formatted } = await render('

```
[(`number string) (`tag string)]
```

') + expect(formatted).toMatchSnapshot() + }) + it('group mention', async () => { const { formatted } = await render('

@pilipinas

', undefined, [{ id: '', username: 'pilipinas', url: 'https://lemmy.ml/c/pilipinas', acct: 'pilipinas@lemmy.ml' }]) expect(formatted).toMatchSnapshot('html')