fix(ui): Asterisk pairs are removed in code block (#3326)
Co-authored-by: TAKAHASHI Shuuji <shuuji3@gmail.com>
This commit is contained in:
parent
e8e2192e75
commit
da26c38e59
3 changed files with 19 additions and 1 deletions
|
@ -104,11 +104,12 @@ export function parseMastodonHTML(
|
||||||
.replace(/</g, '<')
|
.replace(/</g, '<')
|
||||||
.replace(/>/g, '>')
|
.replace(/>/g, '>')
|
||||||
.replace(/`/g, '`')
|
.replace(/`/g, '`')
|
||||||
|
.replace(/\*/g, '*')
|
||||||
const classes = lang ? ` class="language-${lang}"` : ''
|
const classes = lang ? ` class="language-${lang}"` : ''
|
||||||
return `><pre><code${classes}>${code}</code></pre>`
|
return `><pre><code${classes}>${code}</code></pre>`
|
||||||
})
|
})
|
||||||
.replace(/`([^`\n]*)`/g, (_1, raw) => {
|
.replace(/`([^`\n]*)`/g, (_1, raw) => {
|
||||||
return raw ? `<code>${htmlToText(raw).replace(/</g, '<').replace(/>/g, '>')}</code>` : ''
|
return raw ? `<code>${htmlToText(raw).replace(/</g, '<').replace(/>/g, '>').replace(/\*/g, '*')}</code>` : ''
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||||
|
|
||||||
|
exports[`content-rich > asterisk paris in code block 1`] = `"<p><pre class="code-block">1 * 2 * 3</pre></p>"`;
|
||||||
|
|
||||||
|
exports[`content-rich > asterisk paris in inline code 1`] = `
|
||||||
|
"<p><code>1 * 2 * 3</code></p>
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`content-rich > block with backticks 1`] = `"<p><pre class="code-block">[(\`number string) (\`tag string)]</pre></p>"`;
|
exports[`content-rich > block with backticks 1`] = `"<p><pre class="code-block">[(\`number string) (\`tag string)]</pre></p>"`;
|
||||||
|
|
||||||
exports[`content-rich > block with injected html, with a known language 1`] = `
|
exports[`content-rich > block with injected html, with a known language 1`] = `
|
||||||
|
|
|
@ -186,6 +186,16 @@ describe('content-rich', () => {
|
||||||
`)
|
`)
|
||||||
expect(formatted).toMatchSnapshot()
|
expect(formatted).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it ('asterisk paris in inline code', async () => {
|
||||||
|
const { formatted } = await render('<p>`1 * 2 * 3`</p>')
|
||||||
|
expect(formatted).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('asterisk paris in code block', async () => {
|
||||||
|
const { formatted } = await render('<p>```<br />1 * 2 * 3<br />```</p>')
|
||||||
|
expect(formatted).toMatchSnapshot()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('editor', () => {
|
describe('editor', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue