glitch-soc/mastodon

View on GitHub
app/javascript/flavours/glitch/utils/html.ts

Summary

Maintainability
A
2 hrs
Test Coverage
// 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;
};