summaryrefslogtreecommitdiff
path: root/apps/web/lib/sanitize.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/lib/sanitize.ts')
-rw-r--r--apps/web/lib/sanitize.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/apps/web/lib/sanitize.ts b/apps/web/lib/sanitize.ts
new file mode 100644
index 0000000..b63cee1
--- /dev/null
+++ b/apps/web/lib/sanitize.ts
@@ -0,0 +1,43 @@
+import sanitizeHtml from "sanitize-html"
+
+const SANITIZE_OPTIONS: sanitizeHtml.IOptions = {
+ allowedTags: [
+ "h1",
+ "h2",
+ "h3",
+ "h4",
+ "h5",
+ "h6",
+ "p",
+ "a",
+ "ul",
+ "ol",
+ "li",
+ "blockquote",
+ "pre",
+ "code",
+ "em",
+ "strong",
+ "del",
+ "br",
+ "hr",
+ "img",
+ "figure",
+ "figcaption",
+ "table",
+ "thead",
+ "tbody",
+ "tr",
+ "th",
+ "td",
+ ],
+ allowedAttributes: {
+ a: ["href", "title", "rel"],
+ img: ["src", "alt", "title", "width", "height"],
+ },
+ allowedSchemes: ["http", "https"],
+}
+
+export function sanitizeEntryContent(htmlContent: string): string {
+ return sanitizeHtml(htmlContent, SANITIZE_OPTIONS)
+}