2023-07-27 02:14:16 +00:00
|
|
|
const escapeDiv = document.createElement("div");
|
|
|
|
/**
|
2023-08-05 05:09:33 +00:00
|
|
|
* @param text Potentially dangerous text
|
|
|
|
* @returns Text safe to embed in HTML
|
2023-07-27 02:14:16 +00:00
|
|
|
**/
|
2023-08-05 05:09:33 +00:00
|
|
|
export function escapeHtml(text: string): string {
|
2023-07-27 02:14:16 +00:00
|
|
|
escapeDiv.textContent = text;
|
|
|
|
return escapeDiv.innerHTML;
|
|
|
|
}
|