From 2283d16d09e04dc585936d3b3c49f843d36aa00f Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 13 Jan 2025 16:22:39 +0100 Subject: [PATCH] Render scalar arrays as bulleted list --- common/template/render.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/template/render.ts b/common/template/render.ts index 57457324..a76d98ac 100644 --- a/common/template/render.ts +++ b/common/template/render.ts @@ -3,6 +3,7 @@ import { evalQueryExpression } from "@silverbulletmd/silverbullet/lib/query_expr import { expressionToKvQueryExpression } from "../../plug-api/lib/parse_query.ts"; import type { FunctionMap } from "../../plug-api/types.ts"; import { jsonToMDTable } from "../../plugs/template/util.ts"; +import { LuaTable } from "$common/space_lua/runtime.ts"; export async function renderTemplate( ast: AST, @@ -83,6 +84,9 @@ async function renderExpressionDirective( } export function renderExpressionResult(result: any): string { + if (result instanceof LuaTable) { + result = result.asJS(); + } if ( Array.isArray(result) && result.length > 0 && typeof result[0] === "object" ) { @@ -101,8 +105,8 @@ export function renderExpressionResult(result: any): string { // if result is a plain object, render as a markdown table return jsonToMDTable([result]); } else if (Array.isArray(result)) { - // Not-object array - return JSON.stringify(result); + // Not-object array, let's render it as a markdown list + return result.map((item) => `- ${item}`).join("\n"); } else { return "" + result; }