From 470c1153ed257943acf12e57fecc7001853e6add Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Thu, 13 Jun 2024 11:47:03 +0200 Subject: [PATCH] Support auto link in markdown render --- plugs/markdown/markdown_render.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugs/markdown/markdown_render.ts b/plugs/markdown/markdown_render.ts index 367f2f7f..467beace 100644 --- a/plugs/markdown/markdown_render.ts +++ b/plugs/markdown/markdown_render.ts @@ -231,6 +231,28 @@ function render( body: cleanTags(mapRender(linkTextChildren)), }; } + case "Autolink": { + const urlNode = findNodeOfType(t, "URL"); + if (!urlNode) { + return renderToText(t); + } + let url = urlNode.children![0].text!; + if (isLocalPath(url)) { + if ( + options.attachmentUrlPrefix && + !url.startsWith(options.attachmentUrlPrefix) + ) { + url = `${options.attachmentUrlPrefix}${url}`; + } + } + return { + name: "a", + attrs: { + href: url, + }, + body: url, + }; + } case "Image": { const altTextNode = findNodeOfType(t, "WikiLinkAlias") || t.children![1];