Lua: better handle nil, null and undefined values for Lua directives

pull/1219/merge
Zef Hemel 2025-02-10 20:30:28 +01:00
parent 5b982ac257
commit 7abb096382
2 changed files with 5 additions and 9 deletions

View File

@ -66,14 +66,10 @@ export class LuaWidget extends WidgetType {
this.client.currentPage, this.client.currentPage,
); );
activeWidgets.add(this); activeWidgets.add(this);
if (!widgetContent) { if (widgetContent === null || widgetContent === undefined) {
div.innerHTML = ""; widgetContent = { markdown: "nil" };
this.client.setWidgetCache(
this.cacheKey,
{ height: div.clientHeight, html: "" },
);
return;
} }
let html = ""; let html = "";
if (typeof widgetContent !== "object") { if (typeof widgetContent !== "object") {
// Return as markdown string or number // Return as markdown string or number
@ -98,7 +94,7 @@ export class LuaWidget extends WidgetType {
} else { } else {
// If there is a markdown key, use it, otherwise render the objects as a markdown table // If there is a markdown key, use it, otherwise render the objects as a markdown table
let mdContent = widgetContent.markdown; let mdContent = widgetContent.markdown;
if (!mdContent) { if (mdContent === undefined) {
mdContent = await renderExpressionResult(widgetContent); mdContent = await renderExpressionResult(widgetContent);
} }
let mdTree = parse( let mdTree = parse(

View File

@ -2,5 +2,5 @@ This is the start of the standard library distributed as part of SilverBullet co
${template.each(query[[ ${template.each(query[[
from index.tag "page" from index.tag "page"
where name:startsWith("Library/Std") where name:startsWith("Library/Std/")
]], templates.pageItem)} ]], templates.pageItem)}