From 009e988a380979e44bdca92009a7e7a6883ebc11 Mon Sep 17 00:00:00 2001 From: Emma Date: Wed, 13 Mar 2024 00:30:59 -0600 Subject: [PATCH] ttcMD: made card (regrettably) nestable to allow them in code blocks inside of cards --- components/ttcmd/index.tsx | 4 +- lib/tcmd/TokenIdentifiers.ts | 118 ++++++++++++++++++++--------------- lib/tcmd/index.ts | 7 ++- md/help articles/test.md | 17 ++++- 4 files changed, 90 insertions(+), 56 deletions(-) diff --git a/components/ttcmd/index.tsx b/components/ttcmd/index.tsx index f2cc8a7..ef02657 100644 --- a/components/ttcmd/index.tsx +++ b/components/ttcmd/index.tsx @@ -14,9 +14,7 @@ export const TTCMD: FC<{ body: Promise }> = ({ body }) => { const text = use(body); const [elements, tabSpacing] = useMemo(() => createElements(text), [text]); const tada = useMemo( - () => ( - <>{renderer(elements.filter((e) => !e.parent).map((e) => e.token!))} - ), + () => <>{renderer(elements.map((e) => e.token))}, [elements], ); return ( diff --git a/lib/tcmd/TokenIdentifiers.ts b/lib/tcmd/TokenIdentifiers.ts index 0c8170e..809d745 100644 --- a/lib/tcmd/TokenIdentifiers.ts +++ b/lib/tcmd/TokenIdentifiers.ts @@ -31,12 +31,45 @@ export const TokenIdentifiers = new Map< // }); const rendersContentOnly = true; const rendersChildrenOnly = true; +TokenIdentifiers.set("grid", { + search(s, start, end) { + const rx = /(? !m.parent); - return markers; + return markers.filter((m) => !m.parent); + // return markers; } function establishClosestParent(blocks: TokenMarker[]): void { @@ -159,6 +159,7 @@ const contentToChildren = (token: Token) => { const splitMarker = "{{^^}}"; for (const child of token.children || []) { + if (token.type === "card" && child.type === "code") debugger; content = content.replace(child.raw, splitMarker); } @@ -183,6 +184,8 @@ function handleSpecial(token: Token) { token.children = items.flat(); return token.children; } + // case "grid": + // return token.children; default: return; } diff --git a/md/help articles/test.md b/md/help articles/test.md index d650218..9918c1d 100644 --- a/md/help articles/test.md +++ b/md/help articles/test.md @@ -1,7 +1,7 @@ -# TEST - [][][] +[[ +``` [][][] This will make three columns, just like how this is laid out right now. @@ -11,17 +11,30 @@ Each element will get its own cell in the grid. So each of these paragraphs will end up in a separate column. /[] +``` +]] + +[[ +``` [][] This will make two columns +[[ Each column can use a different element +]] /[] +``` +]] +[[ This card will end up in the third column... +]] +[[ ... but since there isn't enough for this one, it will automatically get moved to the next row. +]] /[] \ No newline at end of file