Skip to content

Commit

Permalink
fix: getPlainContent causes external content to be fetched (#3193)
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland authored Dec 12, 2021
1 parent 1a42082 commit 325b9af
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions js/src/common/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ export function slug(string: string): string {
export function getPlainContent(string: string): string {
const html = string.replace(/(<\/p>|<br>)/g, '$1 &nbsp;').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();
}

/**
Expand Down

0 comments on commit 325b9af

Please sign in to comment.