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

26 lines
681 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',
];
// Remove all instances of all selectors
selectors.forEach(selector => {
node.querySelectorAll(selector).forEach(elem => {
elem.remove();
});
});
return node.innerHTML;
};