Skip to content

Instantly share code, notes, and snippets.

@yehuthi
Last active November 24, 2021 16:27
Show Gist options
  • Save yehuthi/d0a4f0f39c4a4124fb3973b2916c3bd1 to your computer and use it in GitHub Desktop.
Save yehuthi/d0a4f0f39c4a4124fb3973b2916c3bd1 to your computer and use it in GitHub Desktop.
[Svelte] Markdown Action
import { marked } from 'marked';
import dompurify from 'dompurify';
export default function (
element: HTMLElement,
markdown: string
): { update: (markdown: string) => void } {
function update(markdown: string) {
element.innerHTML = dompurify.sanitize(marked(markdown));
}
update(markdown);
return { update };
}
npm i marked dompurify
npm i -D @types/marked @types/dompurify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment