Skip to content

Commit

Permalink
Update sanitizeHtml.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyu8512 authored Apr 18, 2024
1 parent 37a79ff commit b81419f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/utils/sanitizeHtml.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import DOMPurify from 'dompurify'

let sanitizer: null | { sanitizeFor: (...args: unknown[]) => any } = null
if (window.Sanitizer) {
const defaultConfig = new window.Sanitizer().getConfiguration()
defaultConfig.allowElements.push('svg')
sanitizer = new window.Sanitizer(defaultConfig)

try {
if (window.Sanitizer) {
const defaultConfig = new window.Sanitizer().getConfiguration()
defaultConfig.allowElements.push('svg')
sanitizer = new window.Sanitizer(defaultConfig)
}
} catch (e) {
// ignore
}

export default function sanitizerHtml(content: string, tag = 'div') {
Expand Down

0 comments on commit b81419f

Please sign in to comment.