From a72741e4d1c593f4c4f1279c29d2c7462f06ea6a Mon Sep 17 00:00:00 2001 From: Emma Date: Sat, 16 Mar 2024 03:19:18 -0600 Subject: [PATCH] ttcMD: improves table with full width --- lib/tcmd/TokenIdentifiers.tsx | 49 ++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/lib/tcmd/TokenIdentifiers.tsx b/lib/tcmd/TokenIdentifiers.tsx index 727f401..e6fa003 100644 --- a/lib/tcmd/TokenIdentifiers.tsx +++ b/lib/tcmd/TokenIdentifiers.tsx @@ -502,7 +502,6 @@ export const buildOnlyDefaultElements = () => { return (
{children?.map((e) => { - console.log(e); return {e.render(e)}; })}
@@ -564,9 +563,24 @@ export const buildOnlyDefaultElements = () => { registerIdentifier( "table", - /^\|\s[\s\S]*?\|(?=(\n\n)|$)/g, + /(?<=\n|^)\| [\s\S]*? \|(?=(\n|$)(?!\|))/g, (s) => { - const rowSections = s.split(/^\|[|-\s]+\|$/gm).map((s) => + const splitMarker = "{{^^}}"; + const original = s; + + let columnPattern: string[] = []; + let fullWidth = false; + s = s.replace(/^\| (<-)?[-|\s^]+(->)? \|$/gm, (e) => { + if (!columnPattern.length) { + columnPattern = e.split("|").filter((e) => e); + } + if (e.match(/^\| <-.*?-> \|/gm)) { + fullWidth = true; + } + return splitMarker; + }); + + const rowSections = s.split(splitMarker).map((s) => s .split("\n") .filter((r) => !!r) @@ -602,22 +616,34 @@ export const buildOnlyDefaultElements = () => { ); return { - content: s, - raw: s, + content: original, + raw: original, metadata: { headerRows: headerRows, bodyRows: bodyRows, footerRows: footerRows, columns: maxColumns, + columnPattern, + fullWidth, }, uuid: crypto.randomUUID(), }; }, (t) => { - const { headerRows, bodyRows, footerRows, columns } = t.metadata; + const { + headerRows, + bodyRows, + footerRows, + columns, + columnPattern, + fullWidth, + } = t.metadata; return ( - +
{!!headerRows && ( {headerRows.map((r, i) => ( @@ -638,10 +664,15 @@ export const buildOnlyDefaultElements = () => { {bodyRows.map((r, i) => ( - {r.concat(Array(columns - r.length).fill("")).map((c) => { + {r.concat(Array(columns - r.length).fill("")).map((c, i) => { const child = t.children?.find((child) => child.raw === c); return ( - );
+ {child?.render(child) || c}