mobilizon/js/src/utils/html.ts

13 lines
351 B
TypeScript
Raw Permalink Normal View History

export function nl2br(text: string): string {
return text.replace(/(?:\r\n|\r|\n)/g, "<br>");
2019-04-26 13:22:16 +00:00
}
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;
}