add htmlDecode() to unescape special characters

This commit is contained in:
ItsVipra 2023-07-19 11:54:59 +02:00
parent a8904497c0
commit 42b954f209
No known key found for this signature in database

View file

@ -85,3 +85,13 @@ export function insertAfter(insertion, target) {
//docs: https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore#example_2
target.parentElement.insertBefore(insertion, target.nextSibling);
}
/**
* Turns HTML text into human-readable text
* @param {string} input HTML Text
* @returns {string}
*/
export function htmlDecode(input) {
const doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
}