diff --git a/webapp/src/lib/components/MarkdownRenderer.svelte b/webapp/src/lib/components/MarkdownRenderer.svelte index e882189..376f9b9 100644 --- a/webapp/src/lib/components/MarkdownRenderer.svelte +++ b/webapp/src/lib/components/MarkdownRenderer.svelte @@ -8,6 +8,7 @@ import Link from '$lib/marked/renderers/Link.svelte'; import Tag from '$lib/marked/renderers/Tag.svelte'; import Highlight from '$lib/marked/renderers/Highlight.svelte'; + import InternalEmbed from '$lib/marked/renderers/InternalEmbed.svelte'; export let plaintext: string; @@ -29,6 +30,7 @@ prose-blockquote:first:before:content-['']" list: List, link: Link, 'internal-link': InternalLink, + 'internal-embed': InternalEmbed, tag: Tag, highlight: Highlight }} diff --git a/webapp/src/lib/marked/extensions.ts b/webapp/src/lib/marked/extensions.ts index 5b439c7..55620a9 100644 --- a/webapp/src/lib/marked/extensions.ts +++ b/webapp/src/lib/marked/extensions.ts @@ -17,6 +17,25 @@ const InternalLinkExtension = { } }; +const InternalEmbedExtension = { + name: 'internal-embed', + level: 'inline', + start(src: string) { + return src.match(/^!\[\[/)?.index; + }, + tokenizer(src: string) { + const match = src.match(/^!\[\[([^\n]+?)]\]/); + if (match) { + return { + type: 'internal-embed', + raw: match[0].trim(), + text: match[1].trim() + }; + } + return false; + } +}; + const TagExtension = { name: 'tag', level: 'inline', @@ -55,6 +74,6 @@ const HighlightExtension = { } }; -export default [InternalLinkExtension, TagExtension, HighlightExtension]; +export default [InternalLinkExtension, InternalEmbedExtension, TagExtension, HighlightExtension]; // ^\#([\w\/]+)\W* diff --git a/webapp/src/lib/marked/renderers/InternalEmbed.svelte b/webapp/src/lib/marked/renderers/InternalEmbed.svelte new file mode 100644 index 0000000..e261710 --- /dev/null +++ b/webapp/src/lib/marked/renderers/InternalEmbed.svelte @@ -0,0 +1,21 @@ + + + + + + Internal embed + + + {text} + + + +