Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

570 B
Raw Blame
import DOMPurify from "dompurify";
import { marked } from "marked";

// Render stored content as HTML, never as an active document. In particular,
// templates must not introduce SVG, CSS, frames, or privileged scheme links.
export const safeMarkdownPreview = (markdown: string) => DOMPurify.sanitize(
  marked.parse(markdown, { async: false }),
  {
    USE_PROFILES: { html: true },
    FORBID_TAGS: ["style", "form", "input", "button", "textarea", "select"],
    FORBID_ATTR: ["style", "id", "name"],
    ALLOWED_URI_REGEXP: /^(?:(?:https?|mailto):|[^:]*$)/i,
  },
);