const div = document.createElement('div'); function getHTMLText(html) { if (!html) return ''; div.innerHTML = html .replace(/<\/p>/g, '

\n\n') .replace(/<\/li>/g, '\n'); div.querySelectorAll('br').forEach((br) => { br.replaceWith('\n'); }); return div.innerText.replace(/[\r\n]{3,}/g, '\n\n').trim(); } export default getHTMLText;