2020-06-10 20:54:23 +00:00
|
|
|
/* eslint-disable no-restricted-globals */
|
|
|
|
|
2020-04-08 22:51:25 +00:00
|
|
|
let decoder: HTMLDivElement
|
|
|
|
|
2021-05-27 21:25:34 +00:00
|
|
|
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
|
|
|
|
}
|
2020-04-08 22:51:25 +00:00
|
|
|
}
|