Skip to content

Commit

Permalink
feat: sanitizeHtmlPlugin now can pass options
Browse files Browse the repository at this point in the history
  • Loading branch information
2nthony committed Jan 18, 2024
1 parent 9662431 commit 652bc87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/HtmlPreviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function HtmlPreviewer(props: PreviewerProps) {
maxLines,
} = props;

const resolvedPlugins = [...plugins, sanitizeHtmlPlugin(allowedTags)];
const resolvedPlugins = [...plugins, sanitizeHtmlPlugin({ allowedTags })];

const ref = useRef<HTMLDivElement>(null);
const [html, setHtml] = useState(content);
Expand Down
22 changes: 16 additions & 6 deletions src/plugins/sanitizeHtml.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import type { Plugin, PreviewerProps } from "../types";
import type { Plugin } from "../types";
import sanitizeHtml from "sanitize-html";
import { getMentionIdentityUserTargetElementAttrs } from "./renderMentionIdentityUser";

export function sanitizeHtmlPlugin(
allowedTags: PreviewerProps["allowedTags"] = sanitizeHtml.defaults.allowedTags.concat(
["img", "iframe", "br", "ins", "del"],
),
): Plugin {
export function sanitizeHtmlPlugin(options?: sanitizeHtml.IOptions): Plugin {
const {
allowedTags = sanitizeHtml.defaults.allowedTags.concat([
"img",
"iframe",
"br",
"ins",
"del",
]),
allowedAttributes = {},
...rest
} = options ?? {};

return {
name: "sanitize-html",

Expand All @@ -21,7 +29,9 @@ export function sanitizeHtmlPlugin(
td: ["align"],
th: ["align"],
li: ["data-list"],
...allowedAttributes,
},
...rest,
});
},
};
Expand Down

0 comments on commit 652bc87

Please sign in to comment.