Replace marked namespaces with Marked instance

Based on a new addition to marked, this commits replaces the imported
marked namespaces with a Marked class, that doesn't change when
`marked.use` introduces new options or extensions.

Also changes the naming slighty to use `markdown` as module, so it
sounds more generic.

Reference: https://github.com/markedjs/marked/pull/2831

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-07-17 14:47:53 +02:00
parent 50088a5c8a
commit 69946f5d8c
5 changed files with 39 additions and 46 deletions
+2 -2
View File
@@ -1,14 +1,14 @@
<script lang="ts">
import dompurify from "dompurify";
import { marked } from "marked";
import markdown from "@app/lib/markdown";
import { twemoji } from "@app/lib/utils";
export let content: string;
export let fontSize: "tiny" | "small" | "medium" = "small";
const render = (content: string): string =>
dompurify.sanitize(marked.parseInline(content));
dompurify.sanitize(markdown.parseInline(content));
</script>
<style>
+3 -8
View File
@@ -2,13 +2,13 @@
import dompurify from "dompurify";
import matter from "@radicle/gray-matter";
import { afterUpdate } from "svelte";
import { marked } from "marked";
import { toDom } from "hast-util-to-dom";
import * as router from "@app/lib/router";
import markdown from "@app/lib/markdown";
import { Renderer } from "@app/lib/markdown";
import { highlight } from "@app/lib/syntax";
import { isUrl, twemoji, scrollIntoView, canonicalize } from "@app/lib/utils";
import { Renderer } from "@app/lib/markdown";
export let content: string;
// If present, resolve all relative links with respect to this URL
@@ -53,12 +53,7 @@
function render(content: string): string {
return dompurify.sanitize(
marked.parse(content, {
renderer: new Renderer(linkBaseUrl),
// TODO: Disables deprecated options, remove once removed from marked
mangle: false,
headerIds: false,
}),
markdown.parse(content, { renderer: new Renderer(linkBaseUrl) }),
);
}