Skip to content

Commit e7cfedb

Browse files
committed
fix: stripHtml method to remove style, script and iframes before extracting the html text
1 parent 5421b9a commit e7cfedb

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

.changeset/hot-bats-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@chialab/sveltekit-utils": patch
3+
---
4+
5+
Fix stripHtml method to remove style, script and iframe tags before extracting the text in the html.

packages/utils/src/lib/utils/html.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { decode } from 'html-entities';
99
export const stripHtml = (html: string | null | undefined): string => {
1010
const element = document.createElement('div');
1111
element.innerHTML = html ?? '';
12+
element.querySelectorAll('style,script,iframe').forEach((node) => node.remove());
1213

1314
return decode(element.innerText);
1415
};

0 commit comments

Comments
 (0)