669037277b
fix #3001
17 lines
444 B
TypeScript
17 lines
444 B
TypeScript
/* eslint-disable no-restricted-globals */
|
|
|
|
let decoder: HTMLDivElement
|
|
|
|
export function decodeHtmlBrowser(raw: string, asAttr = false): string {
|
|
if (!decoder) {
|
|
decoder = document.createElement('div')
|
|
}
|
|
if (asAttr) {
|
|
decoder.innerHTML = `<div foo="${raw.replace(/"/g, '"')}">`
|
|
return decoder.children[0].getAttribute('foo') as string
|
|
} else {
|
|
decoder.innerHTML = raw
|
|
return decoder.textContent as string
|
|
}
|
|
}
|