mobilizon.chapril.org-mobil.../js/src/utils/html.ts
Thomas Citharel baac00f678
Improve search
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2022-08-22 12:12:09 +02:00

13 lines
351 B
TypeScript

export function nl2br(text: string): string {
return text.replace(/(?:\r\n|\r|\n)/g, "<br>");
}
export function htmlToText(html: string) {
const template = document.createElement("template");
const trimmedHTML = html.trim();
template.innerHTML = trimmedHTML;
const text = template.content.textContent;
template.remove();
return text;
}