Skip to content

Commit da26c38

Browse files
nove-bshuuji3
andauthored
fix(ui): Asterisk pairs are removed in code block (#3326)
Co-authored-by: TAKAHASHI Shuuji <shuuji3@gmail.com>
1 parent e8e2192 commit da26c38

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

app/composables/content-parse.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,12 @@ export function parseMastodonHTML(
104104
.replace(/</g, '&lt;')
105105
.replace(/>/g, '&gt;')
106106
.replace(/`/g, '&#96;')
107+
.replace(/\*/g, '&ast;')
107108
const classes = lang ? ` class="language-${lang}"` : ''
108109
return `><pre><code${classes}>${code}</code></pre>`
109110
})
110111
.replace(/`([^`\n]*)`/g, (_1, raw) => {
111-
return raw ? `<code>${htmlToText(raw).replace(/</g, '&lt;').replace(/>/g, '&gt;')}</code>` : ''
112+
return raw ? `<code>${htmlToText(raw).replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\*/g, '&ast;')}</code>` : ''
112113
})
113114
}
114115

tests/nuxt/__snapshots__/content-rich.test.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`content-rich > asterisk paris in code block 1`] = `"<p><pre class="code-block">1 * 2 * 3</pre></p>"`;
4+
5+
exports[`content-rich > asterisk paris in inline code 1`] = `
6+
"<p><code>1 * 2 * 3</code></p>
7+
"
8+
`;
9+
310
exports[`content-rich > block with backticks 1`] = `"<p><pre class="code-block">[(\`number string) (\`tag string)]</pre></p>"`;
411

512
exports[`content-rich > block with injected html, with a known language 1`] = `

tests/nuxt/content-rich.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ describe('content-rich', () => {
186186
`)
187187
expect(formatted).toMatchSnapshot()
188188
})
189+
190+
it ('asterisk paris in inline code', async () => {
191+
const { formatted } = await render('<p>`1 * 2 * 3`</p>')
192+
expect(formatted).toMatchSnapshot()
193+
})
194+
195+
it ('asterisk paris in code block', async () => {
196+
const { formatted } = await render('<p>```<br />1 * 2 * 3<br />```</p>')
197+
expect(formatted).toMatchSnapshot()
198+
})
189199
})
190200

191201
describe('editor', () => {

0 commit comments

Comments
 (0)