this repo has no description
at main 30 lines 708 B view raw
1import mem from './mem'; 2 3const div = document.createElement('div'); 4function getHTMLText(html, opts) { 5 if (!html) return ''; 6 const { preProcess } = opts || {}; 7 8 div.innerHTML = html 9 .replace(/<\/p>/g, '</p>\n\n') 10 .replace(/<\/li>/g, '</li>\n'); 11 div.querySelectorAll('br').forEach((br) => { 12 br.replaceWith('\n'); 13 }); 14 15 preProcess?.(div); 16 17 // MASTODON-SPECIFIC classes 18 // Remove .invisible 19 div.querySelectorAll('.invisible').forEach((el) => { 20 el.remove(); 21 }); 22 // Add … at end of .ellipsis 23 div.querySelectorAll('.ellipsis').forEach((el) => { 24 el.append('...'); 25 }); 26 27 return div.innerText.replace(/[\r\n]{3,}/g, '\n\n').trim(); 28} 29 30export default mem(getHTMLText);