deno.land / x / diplodocus@0.0.3 / marked.ts

marked.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Marked, Renderer, tag as h } from "./deps.ts";import { aTag } from "./utils.ts";
// https://github.com/ts-stack/markdown/blob/5b6145bf713b928b510770df8ee57d3d48d36b9c/projects/markdown/src/renderer.tsclass MyRenderer extends Renderer { heading(text: string, level: number) { const id = String(text) .replace(/^(<.+?>)+/, "") .replace(/(<[^>]+>)+$/, "") .replace(/\s+|(<[^>]*>)+/g, "-") .trim().toLocaleLowerCase(); return h(`h${level}`, { id }, text); }
link(href: string, title: string, text: string): string { return aTag({ href, title: title || false }, text); }
image(src: string, title: string, alt: string): string { const loading = "lazy"; return h("figure", h("img", { src, alt, title: title || false, loading })); }
text(text: string): string { return /^https?:\/\//.test(text) ? aTag({ href: text }, text) : text; }}
Marked.setOptions({ renderer: new MyRenderer() });
export { Marked };
diplodocus
🦕 Deno Deploy Docs 📓
DocumentationDocumentation
GitHub Stars
21

Version Info

Tagged at
8 months ago