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!);
}
});
}
+3 -2
View File
@@ -1,4 +1,4 @@
import { editor, space, system } from "$sb/silverbullet-syscall/mod.ts";
import { editor, system } from "$sb/silverbullet-syscall/mod.ts";
import { asset, store } from "$sb/plugos-syscall/mod.ts";
import { parseMarkdown } from "$sb/silverbullet-syscall/markdown.ts";
import { renderMarkdownToHtml } from "./markdown_render.ts";
@@ -7,6 +7,7 @@ export async function updateMarkdownPreview() {
if (!(await store.get("enableMarkdownPreview"))) {
return;
}
const pageName = await editor.getCurrentPage();
const text = await editor.getText();
const mdTree = await parseMarkdown(text);
// const cleanMd = await cleanMarkdown(text);
@@ -15,7 +16,7 @@ export async function updateMarkdownPreview() {
const html = renderMarkdownToHtml(mdTree, {
smartHardBreak: true,
annotationPositions: true,
inlineAttachments: (url) => {
translateUrls: (url) => {
if (!url.includes("://")) {
return `/.fs/${url}`;
}