mirror of
https://github.com/ItsVipra/ProToots
synced 2024-11-24 20:43:03 +00:00
Add a fallback if DOMParser does not exist
This commit is contained in:
parent
bd14d190a2
commit
58a8404a8d
1 changed files with 13 additions and 0 deletions
|
@ -92,6 +92,19 @@ export function insertAfter(insertion, target) {
|
|||
* @returns {string}
|
||||
*/
|
||||
export function htmlDecode(input) {
|
||||
if (typeof window === "undefined" || !window.DOMParser) {
|
||||
const replacements = {
|
||||
"&": "&",
|
||||
""": '"',
|
||||
"<": "<",
|
||||
">": ">",
|
||||
" ": "",
|
||||
};
|
||||
for (const [html, text] of Object.entries(replacements)) input = input.replaceAll(html, text);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
const doc = new DOMParser().parseFromString(input, "text/html");
|
||||
return doc.documentElement.textContent;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue