This repository has been archived on 2024-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon/app/javascript/mastodon/utils/html.ts

10 lines
305 B
TypeScript

// NB: This function can still return unsafe HTML
export const unescapeHTML = (html: string) => {
const wrapper = document.createElement('div');
wrapper.innerHTML = html
.replace(/<br\s*\/?>/g, '\n')
.replace(/<\/p><p>/g, '\n\n')
.replace(/<[^>]*>/g, '');
return wrapper.textContent;
};