Big refactors and fixes

* Query regen
* Fix anchor completion
* Dependency fixes
* Changelog update
This commit is contained in:
Zef Hemel
2023-07-02 11:25:32 +02:00
committed by GitHub
parent fee2c5928e
commit 7c825348b2
74 changed files with 935 additions and 567 deletions
+7 -3
View File
@@ -12,7 +12,7 @@ type MarkdownRenderOptions = {
annotationPositions?: true;
attachmentUrlPrefix?: string;
// When defined, use to inline images as data: urls
inlineAttachments?: (url: string) => string;
translateUrls?: (url: string) => string;
};
function cleanTags(values: (Tag | null)[]): Tag[] {
@@ -385,13 +385,17 @@ export function renderMarkdownToHtml(
) {
preprocess(t, options);
const htmlTree = posPreservingRender(t, options);
if (htmlTree && options.inlineAttachments) {
if (htmlTree && options.translateUrls) {
traverseTag(htmlTree, (t) => {
if (typeof t === "string") {
return;
}
if (t.name === "img") {
t.attrs!.src = options.inlineAttachments!(t.attrs!.src!);
t.attrs!.src = options.translateUrls!(t.attrs!.src!);
}
if (t.name === "a") {
t.attrs!.href = options.translateUrls!(t.attrs!.href!);
}
});
}