From 7abb0963829f9e08fb3f16d19e3812715da702f3 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 10 Feb 2025 20:30:28 +0100 Subject: [PATCH] Lua: better handle nil, null and undefined values for Lua directives --- web/cm_plugins/lua_widget.ts | 12 ++++-------- website/Library/Std.md | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/web/cm_plugins/lua_widget.ts b/web/cm_plugins/lua_widget.ts index 6f472b7a..6306aaa9 100644 --- a/web/cm_plugins/lua_widget.ts +++ b/web/cm_plugins/lua_widget.ts @@ -66,14 +66,10 @@ export class LuaWidget extends WidgetType { this.client.currentPage, ); activeWidgets.add(this); - if (!widgetContent) { - div.innerHTML = ""; - this.client.setWidgetCache( - this.cacheKey, - { height: div.clientHeight, html: "" }, - ); - return; + if (widgetContent === null || widgetContent === undefined) { + widgetContent = { markdown: "nil" }; } + let html = ""; if (typeof widgetContent !== "object") { // Return as markdown string or number @@ -98,7 +94,7 @@ export class LuaWidget extends WidgetType { } else { // If there is a markdown key, use it, otherwise render the objects as a markdown table let mdContent = widgetContent.markdown; - if (!mdContent) { + if (mdContent === undefined) { mdContent = await renderExpressionResult(widgetContent); } let mdTree = parse( diff --git a/website/Library/Std.md b/website/Library/Std.md index 7f8f07d6..1827f502 100644 --- a/website/Library/Std.md +++ b/website/Library/Std.md @@ -2,5 +2,5 @@ This is the start of the standard library distributed as part of SilverBullet co ${template.each(query[[ from index.tag "page" - where name:startsWith("Library/Std") + where name:startsWith("Library/Std/") ]], templates.pageItem)} \ No newline at end of file