diff options
author | Raphael Kabo <raphaelkabo@hey.com> | 2023-10-09 10:48:10 +0100 |
---|---|---|
committer | Raphael Kabo <raphaelkabo@hey.com> | 2023-10-09 10:48:10 +0100 |
commit | 8b33335584afbac74388c4ed16ff1ff7a04e3588 (patch) | |
tree | bc35e2e96695a56780139856dfd1f5267546193f /src/util/markdown.ts | |
parent | 8a1f07b11e8e18243c058149ac58ece7766b7ef3 (diff) |
Add static page config and handler
Diffstat (limited to 'src/util/markdown.ts')
-rw-r--r-- | src/util/markdown.ts | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/util/markdown.ts b/src/util/markdown.ts index 9f5d384..bab50bd 100644 --- a/src/util/markdown.ts +++ b/src/util/markdown.ts @@ -1,7 +1,6 @@ -// Extra marked renderer (used to render plaintext event description for page metadata) -// Adapted from https://dustinpfister.github.io/2017/11/19/nodejs-marked/ - import { marked } from "marked"; +import { JSDOM } from "jsdom"; +import DOMPurify from "dompurify"; // ? to ? helper function htmlEscapeToText(text: string) { @@ -14,6 +13,9 @@ function htmlEscapeToText(text: string) { }); } +// Extra marked renderer (used to render plaintext event description for page metadata) +// Adapted from https://dustinpfister.github.io/2017/11/19/nodejs-marked/ + export const renderPlain = () => { var render = new marked.Renderer(); // render just the text of a link, strong, em @@ -42,3 +44,11 @@ export const renderPlain = () => { }; return render; }; + +export const markdownToSanitizedHTML = (markdown: string) => { + const html = marked.parse(markdown); + const window = new JSDOM("").window; + const purify = DOMPurify(window); + const clean = purify.sanitize(html); + return clean; +}; |