More fixes related to #363

This commit is contained in:
Zef Hemel
2023-12-19 17:55:11 +01:00
parent a5c7405a35
commit 30436d97ea
9 changed files with 70 additions and 31 deletions
+3 -9
View File
@@ -1,8 +1,7 @@
import { asset, clientStore, editor, markdown, system } from "$sb/syscalls.ts";
import { renderMarkdownToHtml } from "./markdown_render.ts";
import { resolvePath } from "$sb/lib/resolve.ts";
import { resolveAttachmentPath } from "$sb/lib/resolve.ts";
import { expandCodeWidgets } from "./api.ts";
import { folderName, resolve } from "../../common/path.ts";
export async function updateMarkdownPreview() {
if (!(await clientStore.get("enableMarkdownPreview"))) {
@@ -19,14 +18,9 @@ export async function updateMarkdownPreview() {
const html = renderMarkdownToHtml(mdTree, {
smartHardBreak: true,
annotationPositions: true,
translateUrls: (url, type) => {
translateUrls: (url) => {
if (!url.includes("://")) {
if (type === "image" && !url.startsWith("/")) {
// Make relative to current folder
url = resolve(folderName(currentPage), decodeURI(url));
} else if (type === "link") { // link
url = resolvePath(currentPage, decodeURI(url), true);
}
url = resolveAttachmentPath(currentPage, decodeURI(url));
}
return url;
},