2023-10-19 17:57:56 +03:00
|
|
|
import mem from './mem';
|
|
|
|
|
2023-03-28 20:12:59 +03: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');
|
|
|
|
});
|
2024-01-09 20:48:20 +03:00
|
|
|
|
|
|
|
// MASTODON-SPECIFIC classes
|
|
|
|
// Remove .invisible
|
|
|
|
div.querySelectorAll('.invisible').forEach((el) => {
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
// Add … at end of .ellipsis
|
|
|
|
div.querySelectorAll('.ellipsis').forEach((el) => {
|
|
|
|
el.append('...');
|
|
|
|
});
|
|
|
|
|
2023-03-28 20:12:59 +03:00
|
|
|
return div.innerText.replace(/[\r\n]{3,}/g, '\n\n').trim();
|
|
|
|
}
|
|
|
|
|
2023-10-19 17:57:56 +03:00
|
|
|
export default mem(getHTMLText);
|