mirror of
https://github.com/doocs/md.git
synced 2025-01-22 20:04:39 +08:00
fix: escape html (#506)
This commit is contained in:
parent
4f73811f0e
commit
8f09acb06d
@ -40,6 +40,16 @@ function buildTheme({ theme: _theme, fonts, size, isUseIndent }: IOpts): ThemeSt
|
|||||||
} as ThemeStyles
|
} as ThemeStyles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeHtml(text: string): string {
|
||||||
|
return text
|
||||||
|
.replace(/&/g, `&`) // 转义 &
|
||||||
|
.replace(/</g, `<`) // 转义 <
|
||||||
|
.replace(/>/g, `>`) // 转义 >
|
||||||
|
.replace(/"/g, `"`) // 转义 "
|
||||||
|
.replace(/'/g, `'`) // 转义 '
|
||||||
|
.replace(/`/g, ```) // 转义 `
|
||||||
|
}
|
||||||
|
|
||||||
function buildAddition(): string {
|
function buildAddition(): string {
|
||||||
return `
|
return `
|
||||||
<style>
|
<style>
|
||||||
@ -203,7 +213,7 @@ export function initRenderer(opts: IOpts) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
codespan({ text }: Tokens.Codespan): string {
|
codespan({ text }: Tokens.Codespan): string {
|
||||||
const escapedText = text.replace(/</g, `<`).replace(/>/g, `>`)
|
const escapedText = escapeHtml(text)
|
||||||
return styledContent(`codespan`, escapedText, `code`)
|
return styledContent(`codespan`, escapedText, `code`)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user