Improves #1312 by rendering Lua expressions (but not widgets)

This commit is contained in:
Zef Hemel
2025-06-04 14:57:53 +02:00
parent 5f784b72a9
commit e217f64d36
6 changed files with 30 additions and 37 deletions
-1
View File
@@ -103,7 +103,6 @@ export function stripMarkdown(
return tree.children![0].text!;
}
case "TemplateDirective":
case "DeadlineDate": {
return renderToText(tree);
}
-9
View File
@@ -472,15 +472,6 @@ function render(
case "Entity":
return t.children![0].text!;
case "TemplateDirective": {
return {
name: "span",
attrs: {
class: "template-directive",
},
body: renderToText(t),
};
}
case "Superscript":
return {
name: "sup",
-5
View File
@@ -18,7 +18,6 @@ export async function updateMarkdownPreview() {
const currentPage = await editor.getCurrentPage();
const text = await editor.getText();
let mdTree = await markdown.parseMarkdown(text);
// const cleanMd = await cleanMarkdown(text);
const css = await asset.readAsset("markdown", "assets/preview.css");
const js = await asset.readAsset("markdown", "assets/preview.js");
@@ -68,14 +67,10 @@ function renderToolbar(): string {
export async function previewClickHandler(e: any) {
const [eventName, arg] = JSON.parse(e);
// console.log("Got click", eventName, arg);
switch (eventName) {
case "pos":
// console.log("Moving cursor to", +arg);
await editor.moveCursor(+arg, true);
break;
case "command":
await system.invokeCommand(arg);
break;
}
}
-3
View File
@@ -163,9 +163,6 @@ export class LuaWidget extends WidgetType {
);
html = parseHtmlString(renderMarkdownToHtml(mdTree, {
// Annotate every element with its position so we can use it to put
// the cursor there when the user clicks on the table.
annotationPositions: true,
translateUrls: (url) => {
if (isLocalPath(url)) {
url = resolvePath(
-1
View File
@@ -13,7 +13,6 @@ const straightQuoteContexts = [
"FrontMatterCode",
"Attribute",
"CommandLink",
"TemplateDirective",
"LuaDirective",
];
+30 -18
View File
@@ -15,6 +15,8 @@ import {
isLocalPath,
resolvePath,
} from "@silverbulletmd/silverbullet/lib/resolve";
import { expandMarkdown } from "../markdown.ts";
import { LuaStackFrame } from "../space_lua/runtime.ts";
class TableViewWidget extends WidgetType {
tableBodyText: string;
@@ -41,25 +43,35 @@ class TableViewWidget extends WidgetType {
});
});
dom.innerHTML = renderMarkdownToHtml(this.t, {
// Annotate every element with its position so we can use it to put
// the cursor there when the user clicks on the table.
annotationPositions: true,
translateUrls: (url) => {
if (isLocalPath(url)) {
url = resolvePath(this.client.currentPage, decodeURI(url));
}
const sf = LuaStackFrame.createWithGlobalEnv(
client.clientSystem.spaceLuaEnv.env,
);
expandMarkdown(
client,
this.t,
client.clientSystem.spaceLuaEnv.env,
sf,
).then((t) => {
dom.innerHTML = renderMarkdownToHtml(t, {
// Annotate every element with its position so we can use it to put
// the cursor there when the user clicks on the table.
annotationPositions: true,
translateUrls: (url) => {
if (isLocalPath(url)) {
url = resolvePath(this.client.currentPage, decodeURI(url));
}
return url;
},
preserveAttributes: true,
});
setTimeout(() => {
this.client.setCachedWidgetHeight(
`table:${this.tableBodyText}`,
dom.clientHeight,
);
return url;
},
preserveAttributes: true,
});
setTimeout(() => {
// Give it a tick to render
this.client.setCachedWidgetHeight(
`table:${this.tableBodyText}`,
dom.clientHeight,
);
});
});
return dom;
}