Render scalar arrays as bulleted list
parent
61f82869e9
commit
2283d16d09
|
@ -3,6 +3,7 @@ import { evalQueryExpression } from "@silverbulletmd/silverbullet/lib/query_expr
|
||||||
import { expressionToKvQueryExpression } from "../../plug-api/lib/parse_query.ts";
|
import { expressionToKvQueryExpression } from "../../plug-api/lib/parse_query.ts";
|
||||||
import type { FunctionMap } from "../../plug-api/types.ts";
|
import type { FunctionMap } from "../../plug-api/types.ts";
|
||||||
import { jsonToMDTable } from "../../plugs/template/util.ts";
|
import { jsonToMDTable } from "../../plugs/template/util.ts";
|
||||||
|
import { LuaTable } from "$common/space_lua/runtime.ts";
|
||||||
|
|
||||||
export async function renderTemplate(
|
export async function renderTemplate(
|
||||||
ast: AST,
|
ast: AST,
|
||||||
|
@ -83,6 +84,9 @@ async function renderExpressionDirective(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderExpressionResult(result: any): string {
|
export function renderExpressionResult(result: any): string {
|
||||||
|
if (result instanceof LuaTable) {
|
||||||
|
result = result.asJS();
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
Array.isArray(result) && result.length > 0 && typeof result[0] === "object"
|
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
|
// if result is a plain object, render as a markdown table
|
||||||
return jsonToMDTable([result]);
|
return jsonToMDTable([result]);
|
||||||
} else if (Array.isArray(result)) {
|
} else if (Array.isArray(result)) {
|
||||||
// Not-object array
|
// Not-object array, let's render it as a markdown list
|
||||||
return JSON.stringify(result);
|
return result.map((item) => `- ${item}`).join("\n");
|
||||||
} else {
|
} else {
|
||||||
return "" + result;
|
return "" + result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue