From 15ccabc361419c912fbe9f2febfbfddf30f872b6 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 6 May 2026 16:46:05 +0200 Subject: [PATCH] Fix ref links in tables regression --- client/space_lua/render_lua_markdown.test.ts | 17 +++++++++++++++++ client/space_lua/render_lua_markdown.ts | 10 ++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/client/space_lua/render_lua_markdown.test.ts b/client/space_lua/render_lua_markdown.test.ts index 35bb5ed4..423041ca 100644 --- a/client/space_lua/render_lua_markdown.test.ts +++ b/client/space_lua/render_lua_markdown.test.ts @@ -409,6 +409,23 @@ test("e2e: table with wiki links produces clickable links", async () => { ); }); +test("e2e: ref column is rendered as a wiki link", async () => { + const row = new LuaTable(); + await row.rawSet("name", "Alice"); + await row.rawSet("ref", "SomePage"); + + const tbl = new LuaTable(); + await tbl.rawSet(1, row); + + expect(toHtml(tbl)).toBe( + "" + + '' + + '
nameref
Alice' + + 'SomePage' + + "
", + ); +}); + test("e2e: table with bold text renders strong tags", async () => { const row = new LuaTable(); await row.rawSet("note", "**important**"); diff --git a/client/space_lua/render_lua_markdown.ts b/client/space_lua/render_lua_markdown.ts index c1c5c232..4a5b5e14 100644 --- a/client/space_lua/render_lua_markdown.ts +++ b/client/space_lua/render_lua_markdown.ts @@ -56,7 +56,7 @@ function buildHtmlTable( parts.push(""); for (let i = 0; i < rowCount; i++) { parts.push(""); - for (const h of headers) parts.push(renderTd(getCell(i, h))); + for (const h of headers) parts.push(renderTd(getCell(i, h), h)); parts.push(""); } parts.push(""); @@ -330,10 +330,16 @@ function luaTypeName(v: any): string | undefined { return "string"; } -function renderTd(v: any): string { +function renderTd(v: any, header?: string): string { if (isEmpty(v)) return ""; const type = luaTypeName(v); const attr = type ? ` data-table-cell-type="${type}"` : ""; + // `ref` columns hold a page name by convention — wrap scalars in + // wiki-link syntax so the markdown renderer turns them into clickable + // page links (mirrors the clean-markdown copy path). + if (header === "ref" && (type === "string" || type === "number")) { + return `[[${formatScalar(v)}]]`; + } return `${renderCellContent(v)}`; }