diff --git a/webapp/src/lib/components/MarkdownRenderer.svelte b/webapp/src/lib/components/MarkdownRenderer.svelte index 2e2babf..ccfd325 100644 --- a/webapp/src/lib/components/MarkdownRenderer.svelte +++ b/webapp/src/lib/components/MarkdownRenderer.svelte @@ -5,6 +5,8 @@ import InternalLink from '$lib/marked/renderers/InternalLink.svelte'; import { marked } from 'marked'; import extensions from '$lib/marked/extensions'; + import Link from '$lib/marked/renderers/Link.svelte'; + import Tag from '$lib/marked/renderers/Tag.svelte'; export let plaintext: string; @@ -17,10 +19,17 @@
diff --git a/webapp/src/lib/marked/extensions.ts b/webapp/src/lib/marked/extensions.ts index 8b4738c..2099c22 100644 --- a/webapp/src/lib/marked/extensions.ts +++ b/webapp/src/lib/marked/extensions.ts @@ -7,10 +7,9 @@ const InternalLinkExtension = { tokenizer(src: string) { const match = src.match(/^\[\[([^\n]+?)]\]/); if (match) { - console.log(match); return { type: 'internal-link', - raw: match[0], + raw: match[0].trim(), text: match[1].trim() }; } @@ -18,4 +17,26 @@ const InternalLinkExtension = { } }; -export default [InternalLinkExtension]; +const TagExtension = { + name: 'tag', + level: 'inline', + start(src: string) { + return src.match(/#/)?.index; + }, + tokenizer(src: string) { + const match = src.match(/^#([\w/]+)[\W\s]/); + if (match) { + console.log(match); + return { + type: 'tag', + raw: match[0].trim(), + text: match[1].trim() + }; + } + return false; + } +}; + +export default [InternalLinkExtension, TagExtension]; + +// ^\#([\w\/]+)\W* diff --git a/webapp/src/lib/marked/renderers/InternalLink.svelte b/webapp/src/lib/marked/renderers/InternalLink.svelte index 2206034..2b315f8 100644 --- a/webapp/src/lib/marked/renderers/InternalLink.svelte +++ b/webapp/src/lib/marked/renderers/InternalLink.svelte @@ -1,9 +1,12 @@ - - {text} + + + {text} + + + diff --git a/webapp/src/lib/marked/renderers/Link.svelte b/webapp/src/lib/marked/renderers/Link.svelte new file mode 100644 index 0000000..fbc133c --- /dev/null +++ b/webapp/src/lib/marked/renderers/Link.svelte @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/webapp/src/lib/marked/renderers/Tag.svelte b/webapp/src/lib/marked/renderers/Tag.svelte new file mode 100644 index 0000000..0039cc3 --- /dev/null +++ b/webapp/src/lib/marked/renderers/Tag.svelte @@ -0,0 +1,3 @@ + + + diff --git a/webapp/src/routes/note/[id].svelte b/webapp/src/routes/note/[id].svelte index b226ec1..4b1e851 100644 --- a/webapp/src/routes/note/[id].svelte +++ b/webapp/src/routes/note/[id].svelte @@ -38,7 +38,7 @@

Shared ?? days ago -