bigbuffet-rw/app/soapbox/utils/html.js

27 lines
646 B
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
// NB: This function can still return unsafe HTML
export const unescapeHTML = (html) => {
const wrapper = document.createElement('div');
2022-01-28 12:52:22 -08:00
wrapper.innerHTML = html.replace(/<br\s*\/?>/g, '\n').replace(/<\/p><[^>]*>/g, '\n\n').replace(/<[^>]*>/g, '');
2020-03-27 13:59:38 -07:00
return wrapper.textContent;
};
export const stripCompatibilityFeatures = html => {
const node = document.createElement('div');
node.innerHTML = html;
const selectors = [
'.quote-inline',
'.recipients-inline',
];
selectors.forEach(selector => {
const elem = node.querySelector(selector);
if (elem) {
elem.remove();
}
});
return node.innerHTML;
};