Support auto link in markdown render

pull/893/head
Zef Hemel 2024-06-13 11:47:03 +02:00
parent 78be20c24f
commit 470c1153ed
1 changed files with 22 additions and 0 deletions

View File

@ -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];