mirror of
https://github.com/flarum/framework.git
synced 2025-01-22 07:43:33 +08:00
fix: getPlainContent causes external content to be fetched (#3193)
This commit is contained in:
parent
1a420828aa
commit
325b9afca6
|
@ -28,11 +28,16 @@ export function slug(string: string): string {
|
|||
export function getPlainContent(string: string): string {
|
||||
const html = string.replace(/(<\/p>|<br>)/g, '$1 ').replace(/<img\b[^>]*>/gi, ' ');
|
||||
|
||||
const dom = $('<div/>').html(html);
|
||||
const element = new DOMParser().parseFromString(html, 'text/html').documentElement;
|
||||
|
||||
dom.find(getPlainContent.removeSelectors.join(',')).remove();
|
||||
getPlainContent.removeSelectors.forEach((selector) => {
|
||||
const el = element.querySelectorAll(selector);
|
||||
el.forEach((e) => {
|
||||
e.remove();
|
||||
});
|
||||
});
|
||||
|
||||
return dom.text().replace(/\s+/g, ' ').trim();
|
||||
return element.innerText.replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user