From c9170b963d938449bd5df67e0d42523df477278d Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Mon, 29 Dec 2025 22:50:00 +0100 Subject: [PATCH] Add table with markdown --- .../table-with-markdown.css | 24 ++++++++ .../table-with-markdown.jdd.tsx | 61 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/back/jdd-components/table-with-markdown/table-with-markdown.css create mode 100644 src/back/jdd-components/table-with-markdown/table-with-markdown.jdd.tsx diff --git a/src/back/jdd-components/table-with-markdown/table-with-markdown.css b/src/back/jdd-components/table-with-markdown/table-with-markdown.css new file mode 100644 index 0000000..17a25ba --- /dev/null +++ b/src/back/jdd-components/table-with-markdown/table-with-markdown.css @@ -0,0 +1,24 @@ +.table-with-markdown { + width: 100%; + display: flex; + flex-flow: column; + align-items: center; + background: var(--color-brand-text-bg); + padding: 16px; + + table, + td, + th { + border: 1px solid black; + } + + td, + th { + padding: 8px 16px; + } + + th { + font-weight: bold; + font-size: 16px; + } +} diff --git a/src/back/jdd-components/table-with-markdown/table-with-markdown.jdd.tsx b/src/back/jdd-components/table-with-markdown/table-with-markdown.jdd.tsx new file mode 100644 index 0000000..878e545 --- /dev/null +++ b/src/back/jdd-components/table-with-markdown/table-with-markdown.jdd.tsx @@ -0,0 +1,61 @@ +import { TempstreamJSX } from "tempstream"; +import type { ComponentToHTMLArgs } from "@sealcode/jdd"; +import { Component, ComponentArguments, isTableHeader } from "@sealcode/jdd"; + +const component_arguments = { + table: new ComponentArguments.Table( + new ComponentArguments.ShortText(), + new ComponentArguments.Structured({ + type: new ComponentArguments.Enum(["td", "th"]).setExampleValues(["td"]), + content: new ComponentArguments.ShortText().setExampleValues([""]), + }) + ), +} as const; + +export class TableWithMarkdown extends Component { + getArguments() { + return component_arguments; + } + + toHTML({ + args: { table }, + classes, + index, + jdd_context: { render_markdown, language }, + }: ComponentToHTMLArgs) { + return ( +
+ + + {table.rows.map((row) => + isTableHeader(row) ? ( + + + + ) : ( + + {row.cells.map(({ type, content }) => + type == "td" ? ( + + ) : ( + + ) + )} + + ) + )} + +
+ {row.header_content} +
{render_markdown(language, content)}{render_markdown(language, content)}
+
+ ); + } +}