No longer serialize binary blobs as data URLs
This commit is contained in:
@@ -77,9 +77,6 @@ async function actionClickOrActionEnter(
|
||||
}
|
||||
if (url.indexOf("://") === -1 && !url.startsWith("mailto:")) {
|
||||
url = decodeURIComponent(url);
|
||||
// // attachment URL, let's fetch as a data url
|
||||
// const dataUrl = await space.readAttachment(url);
|
||||
// return editor.downloadFile(url, dataUrl);
|
||||
return editor.openUrl(`/.fs/${url}`);
|
||||
} else {
|
||||
await editor.openUrl(url);
|
||||
|
||||
@@ -57,8 +57,7 @@ export async function updatePlugsCommand() {
|
||||
// console.log("Writing", `_plug/${plugName}.plug.js`, workerCode);
|
||||
await space.writeAttachment(
|
||||
`_plug/${plugName}.plug.js`,
|
||||
"utf8",
|
||||
workerCode,
|
||||
new TextEncoder().encode(workerCode),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ type MarkdownRenderOptions = {
|
||||
annotationPositions?: true;
|
||||
attachmentUrlPrefix?: string;
|
||||
// When defined, use to inline images as data: urls
|
||||
inlineAttachments?: (url: string) => Promise<string>;
|
||||
inlineAttachments?: (url: string) => string;
|
||||
};
|
||||
|
||||
function cleanTags(values: (Tag | null)[]): Tag[] {
|
||||
@@ -364,34 +364,34 @@ function render(
|
||||
}
|
||||
}
|
||||
|
||||
async function traverseTag(
|
||||
function traverseTag(
|
||||
t: Tag,
|
||||
fn: (t: Tag) => Promise<void>,
|
||||
): Promise<void> {
|
||||
await fn(t);
|
||||
fn: (t: Tag) => void,
|
||||
) {
|
||||
fn(t);
|
||||
if (typeof t === "string") {
|
||||
return;
|
||||
}
|
||||
if (t.body) {
|
||||
for (const child of t.body) {
|
||||
await traverseTag(child, fn);
|
||||
traverseTag(child, fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function renderMarkdownToHtml(
|
||||
export function renderMarkdownToHtml(
|
||||
t: ParseTree,
|
||||
options: MarkdownRenderOptions = {},
|
||||
) {
|
||||
preprocess(t, options);
|
||||
const htmlTree = posPreservingRender(t, options);
|
||||
if (htmlTree && options.inlineAttachments) {
|
||||
await traverseTag(htmlTree, async (t) => {
|
||||
traverseTag(htmlTree, (t) => {
|
||||
if (typeof t === "string") {
|
||||
return;
|
||||
}
|
||||
if (t.name === "img") {
|
||||
t.attrs!.src = await options.inlineAttachments!(t.attrs!.src!);
|
||||
t.attrs!.src = options.inlineAttachments!(t.attrs!.src!);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,17 +12,12 @@ export async function updateMarkdownPreview() {
|
||||
// const cleanMd = await cleanMarkdown(text);
|
||||
const css = await asset.readAsset("assets/styles.css");
|
||||
const js = await asset.readAsset("assets/handler.js");
|
||||
const html = await renderMarkdownToHtml(mdTree, {
|
||||
const html = renderMarkdownToHtml(mdTree, {
|
||||
smartHardBreak: true,
|
||||
annotationPositions: true,
|
||||
inlineAttachments: async (url): Promise<string> => {
|
||||
inlineAttachments: (url) => {
|
||||
if (!url.includes("://")) {
|
||||
try {
|
||||
return await space.readAttachment(url);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
return url;
|
||||
}
|
||||
return `/.fs/${url}`;
|
||||
}
|
||||
return url;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user