phanpy/src/utils/getHTMLText.jsx

14 wiersze
362 B
React
Czysty Zwykły widok Historia

2023-03-28 17:12:59 +00:00
const div = document.createElement('div');
function getHTMLText(html) {
if (!html) return '';
div.innerHTML = html
.replace(/<\/p>/g, '</p>\n\n')
.replace(/<\/li>/g, '</li>\n');
div.querySelectorAll('br').forEach((br) => {
br.replaceWith('\n');
});
return div.innerText.replace(/[\r\n]{3,}/g, '\n\n').trim();
}
export default getHTMLText;