Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/util/string.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
export function stripHtml(s: string): string {
// Remove HTML comments from Markdown - from Liquidjs
return s.replace(
/<script[\s\S]*?<\/script>|<style[\s\S]*?<\/style>|<.*?>|<!--[\s\S]*?-->/g,
"",
);
// Remove HTML, script/style tags, and comments from Markdown - from Liquidjs
// Apply the replacement repeatedly to avoid incomplete multi-character sanitization.
const stripRegex =
/<script[\s\S]*?<\/script>|<style[\s\S]*?<\/style>|<.*?>|<!--[\s\S]*?-->/g;
let previous: string;
let current = s;
do {
previous = current;
current = current.replace(stripRegex, "");
} while (current !== previous);
return current;
}

export function title(s: string): string {
Expand Down