fix: escape/textify the contents of inline and block code (#954)
This commit is contained in:
parent
24d43699bb
commit
f9509f8987
3 changed files with 35 additions and 1 deletions
|
@ -53,10 +53,13 @@ export function parseMastodonHTML(
|
|||
// Handle code blocks
|
||||
html = html
|
||||
.replace(/>(```|~~~)(\w*)([\s\S]+?)\1/g, (_1, _2, lang: string, raw: string) => {
|
||||
const code = htmlToText(raw)
|
||||
const code = htmlToText(raw).replace(/</g, '<').replace(/>/g, '>')
|
||||
const classes = lang ? ` class="language-${lang}"` : ''
|
||||
return `><pre><code${classes}>${code}</code></pre>`
|
||||
})
|
||||
.replace(/`([^`\n]*)`/g, (_1, raw) => {
|
||||
return raw ? `<code>${htmlToText(raw).replace(/</g, '<').replace(/>/g, '>')}</code>` : ''
|
||||
})
|
||||
}
|
||||
|
||||
// Always sanitize the raw HTML data *after* it has been modified
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue