Skip to content
Merged
Prev Previous commit
Next Next commit
fix: improve HTML comment stripping
  • Loading branch information
sreya committed Nov 26, 2024
commit 99ef0f6fb97bada52e0c5aec64868e85592deb9f
7 changes: 5 additions & 2 deletions offlinedocs/pages/[[...slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import { MdMenu } from "react-icons/md";
import ReactMarkdown from "react-markdown";
import rehypeRaw from "rehype-raw";
import remarkGfm from "remark-gfm";
import DOMPurify from 'dompurify';


type FilePath = string;
type UrlPath = string;
Expand Down Expand Up @@ -194,8 +196,9 @@ const getNavigation = (manifest: Manifest): Nav => {
return navigation;
};

const removeHtmlComments = (string: string) => {
return string.replace(/<!--[\s\S]*?-->/g, "");
const removeHtmlComments = (input: string) => {
if (!input) return '';
return DOMPurify.sanitize(input, { ALLOW_COMMENTS: false });
};

export const getStaticPaths: GetStaticPaths = () => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"prettier": "3.3.3"
},
"dependencies": {
"dompurify": "^3.2.1",
"url-parse": "^1.5.10"
}
}
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions site/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading