@alloy-js/markdown 0.25.0 → 0.27.0-dev.4

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.
Files changed (105) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +45 -0
  3. package/dist/dev/src/components/Code.js +20 -5
  4. package/dist/dev/src/components/Code.js.map +1 -1
  5. package/dist/dev/src/components/Heading.js +66 -2
  6. package/dist/dev/src/components/Heading.js.map +1 -1
  7. package/dist/dev/src/components/Link.js +33 -1
  8. package/dist/dev/src/components/Link.js.map +1 -1
  9. package/dist/dev/src/components/SourceFile.js +27 -6
  10. package/dist/dev/src/components/SourceFile.js.map +1 -1
  11. package/dist/dev/src/components/index.js +2 -0
  12. package/dist/dev/src/components/index.js.map +1 -1
  13. package/dist/dev/src/components/inline-code.js +28 -0
  14. package/dist/dev/src/components/inline-code.js.map +1 -0
  15. package/dist/dev/src/components/table.js +98 -0
  16. package/dist/dev/src/components/table.js.map +1 -0
  17. package/dist/dev/src/context/source-file.js +50 -0
  18. package/dist/dev/src/context/source-file.js.map +1 -0
  19. package/dist/dev/src/context/table.js +8 -0
  20. package/dist/dev/src/context/table.js.map +1 -0
  21. package/dist/dev/src/symbols/heading-symbol.js +22 -0
  22. package/dist/dev/src/symbols/heading-symbol.js.map +1 -0
  23. package/dist/dev/test/Code.test.js +150 -6
  24. package/dist/dev/test/Code.test.js.map +1 -1
  25. package/dist/dev/test/heading.test.js +774 -0
  26. package/dist/dev/test/heading.test.js.map +1 -0
  27. package/dist/dev/test/inline-code.test.js +236 -0
  28. package/dist/dev/test/inline-code.test.js.map +1 -0
  29. package/dist/dev/test/table.test.js +499 -0
  30. package/dist/dev/test/table.test.js.map +1 -0
  31. package/dist/dev/test/vitest.d.js.map +1 -1
  32. package/dist/src/components/Code.d.ts +10 -3
  33. package/dist/src/components/Code.d.ts.map +1 -1
  34. package/dist/src/components/Code.js +19 -4
  35. package/dist/src/components/Code.js.map +1 -1
  36. package/dist/src/components/Heading.d.ts +10 -2
  37. package/dist/src/components/Heading.d.ts.map +1 -1
  38. package/dist/src/components/Heading.js +54 -2
  39. package/dist/src/components/Heading.js.map +1 -1
  40. package/dist/src/components/Link.d.ts +9 -1
  41. package/dist/src/components/Link.d.ts.map +1 -1
  42. package/dist/src/components/Link.js +33 -1
  43. package/dist/src/components/Link.js.map +1 -1
  44. package/dist/src/components/SourceFile.d.ts.map +1 -1
  45. package/dist/src/components/SourceFile.js +17 -4
  46. package/dist/src/components/SourceFile.js.map +1 -1
  47. package/dist/src/components/index.d.ts +2 -0
  48. package/dist/src/components/index.d.ts.map +1 -1
  49. package/dist/src/components/index.js +2 -0
  50. package/dist/src/components/index.js.map +1 -1
  51. package/dist/src/components/inline-code.d.ts +16 -0
  52. package/dist/src/components/inline-code.d.ts.map +1 -0
  53. package/dist/src/components/inline-code.js +28 -0
  54. package/dist/src/components/inline-code.js.map +1 -0
  55. package/dist/src/components/table.d.ts +37 -0
  56. package/dist/src/components/table.d.ts.map +1 -0
  57. package/dist/src/components/table.js +74 -0
  58. package/dist/src/components/table.js.map +1 -0
  59. package/dist/src/context/source-file.d.ts +19 -0
  60. package/dist/src/context/source-file.d.ts.map +1 -0
  61. package/dist/src/context/source-file.js +50 -0
  62. package/dist/src/context/source-file.js.map +1 -0
  63. package/dist/src/context/table.d.ts +4 -0
  64. package/dist/src/context/table.d.ts.map +1 -0
  65. package/dist/src/context/table.js +8 -0
  66. package/dist/src/context/table.js.map +1 -0
  67. package/dist/src/symbols/heading-symbol.d.ts +14 -0
  68. package/dist/src/symbols/heading-symbol.d.ts.map +1 -0
  69. package/dist/src/symbols/heading-symbol.js +22 -0
  70. package/dist/src/symbols/heading-symbol.js.map +1 -0
  71. package/dist/test/Code.test.js +107 -3
  72. package/dist/test/Code.test.js.map +1 -1
  73. package/dist/test/heading.test.d.ts +2 -0
  74. package/dist/test/heading.test.d.ts.map +1 -0
  75. package/dist/test/heading.test.js +494 -0
  76. package/dist/test/heading.test.js.map +1 -0
  77. package/dist/test/inline-code.test.d.ts +2 -0
  78. package/dist/test/inline-code.test.d.ts.map +1 -0
  79. package/dist/test/inline-code.test.js +148 -0
  80. package/dist/test/inline-code.test.js.map +1 -0
  81. package/dist/test/table.test.d.ts +2 -0
  82. package/dist/test/table.test.d.ts.map +1 -0
  83. package/dist/test/table.test.js +303 -0
  84. package/dist/test/table.test.js.map +1 -0
  85. package/dist/test/vitest.d.js.map +1 -1
  86. package/dist/tsconfig.tsbuildinfo +1 -1
  87. package/docs/index.md +92 -0
  88. package/docs/tables.md +81 -0
  89. package/package.json +11 -6
  90. package/src/components/Code.tsx +35 -8
  91. package/src/components/Heading.tsx +103 -4
  92. package/src/components/Link.tsx +61 -2
  93. package/src/components/SourceFile.tsx +19 -2
  94. package/src/components/index.ts +2 -0
  95. package/src/components/inline-code.tsx +51 -0
  96. package/src/components/table.tsx +113 -0
  97. package/src/context/source-file.ts +79 -0
  98. package/src/context/table.ts +8 -0
  99. package/src/symbols/heading-symbol.ts +38 -0
  100. package/temp/api.json +552 -9
  101. package/test/Code.test.tsx +102 -2
  102. package/test/heading.test.tsx +464 -0
  103. package/test/inline-code.test.tsx +166 -0
  104. package/test/table.test.tsx +282 -0
  105. package/test/vitest.d.ts +4 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog - @alloy-js/markdown
2
2
 
3
+ ## 0.26.0
4
+
5
+ No changes, version bump only.
6
+
3
7
  ## 0.25.0
4
8
 
5
9
  No changes, version bump only.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @alloy-js/markdown
2
+
3
+ ## Inline code
4
+
5
+ `InlineCode` renders direct string children as literal code-span text, choosing
6
+ backtick delimiters longer than any run in the string and adding padding when
7
+ required to preserve leading/trailing backticks and spaces.
8
+
9
+ ```tsx
10
+ import { Heading, InlineCode } from "@alloy-js/markdown";
11
+
12
+ <Heading level={2}>
13
+ Using <InlineCode>{"a`b"}</InlineCode>
14
+ </Heading>;
15
+ // ## Using ``a`b``
16
+ ```
17
+
18
+ `InlineCode` can be composed inside headings, link-label fragments, and table
19
+ cells:
20
+
21
+ ```tsx
22
+ <>
23
+ [<InlineCode>{"a`b"}</InlineCode>](https://example.com)
24
+ </>
25
+ ```
26
+
27
+ Each CRLF, CR, or LF in a direct string becomes one space, matching
28
+ CommonMark code-span normalization. Other whitespace is preserved, including
29
+ all-space content. Empty strings and omitted content render as `<code></code>`
30
+ because Markdown has no empty code-span syntax; this requires a renderer that
31
+ permits inline HTML.
32
+
33
+ JSX components, arrays, refs, accessors, and other non-string children are wrapped
34
+ in single backticks unchanged. They are not evaluated to select delimiters,
35
+ normalize line breaks, or add padding. Callers are responsible for producing
36
+ valid single-backtick code-span content in these cases. For automatic escaping,
37
+ pass the final text as a direct string child (including a reactive string
38
+ expression such as `<InlineCode>{name.value}</InlineCode>`), not a component
39
+ that returns it.
40
+
41
+ Inside a Markdown table cell (including header cells), pipes in direct string
42
+ children are escaped as `\|` so they cannot split the cell. Outside the table
43
+ context, pipes remain literal. Existing backslashes are preserved in both cases.
44
+ As with other escaping, opaque JSX content is not inspected: callers must escape
45
+ any pipes produced by those children themselves.
@@ -1,17 +1,32 @@
1
1
  import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { List } from "@alloy-js/core";
2
+ import { computed, List, memo } from "@alloy-js/core";
3
3
  /**
4
- * Render a Markdown code block
4
+ * Render a Markdown code block. Direct string bodies use content-safe fences.
5
+ * JSX children render normally without being inspected for fence conflicts.
5
6
  */
6
7
  export function Code(props) {
7
- const tripleBackticks = "```";
8
+ const body = memo(() => props.children);
9
+ const info = computed(() => {
10
+ const info = props.lang ?? "";
11
+ if (/[\r\n]/.test(info)) {
12
+ throw new Error("Code lang must be a single-line Markdown info string.");
13
+ }
14
+ return info.trim();
15
+ });
16
+ const fence = computed(() => {
17
+ const marker = info.value.includes("`") ? "~" : "`";
18
+ const content = body();
19
+ const runs = typeof content === "string" ? content.match(marker === "`" ? /`+/g : /~+/g) ?? [] : [];
20
+ const length = runs.reduce((length, run) => Math.max(length, run.length + 1), 3);
21
+ return marker.repeat(length);
22
+ });
8
23
  return _$createComponent(List, {
9
24
  get children() {
10
- return [_$memo(() => tripleBackticks + props.lang), _$memo(() => props.children, false, "props.children"), tripleBackticks];
25
+ return [_$memo(() => fence.value + info.value), _$memo(() => body(), false, "body(…)"), _$memo(() => fence.value, false, "fence.value")];
11
26
  }
12
27
  }, {
13
28
  fileName: import.meta.url,
14
- lineNumber: 18,
29
+ lineNumber: 45,
15
30
  columnNumber: 5
16
31
  });
17
32
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../../../src/components/Code.tsx"],"sourcesContent":["import { List } from \"@alloy-js/core\";\nimport type { Children } from \"@alloy-js/core/jsx-runtime\";\n\nexport interface CodeProps {\n /** Language of the code block */\n lang?: string;\n\n /** Body of the code block */\n children?: Children;\n}\n\n/**\n * Render a Markdown code block\n */\nexport function Code(props: CodeProps) {\n const tripleBackticks = \"```\";\n return (\n <List>\n {tripleBackticks + props.lang}\n {props.children}\n {tripleBackticks}\n </List>\n );\n}\n"],"mappings":";AAAA,SAAS,IAAI,QAAQ,gBAAgB;AAWrC;AACA;AACA;AACA,OAAO,SAAS,IAAI,CAAC,KAAgB,EAAE;EACrC,MAAM,eAAe,GAAG,KAAK;EAC7B,yBACG,IAAI;IAAA;MAAA,qBACF,eAAe,GAAG,KAAK,CAAC,IAAI,gBAC5B,KAAK,CAAC,QAAQ,4BACd,eAAe;IAAA;EAAA;IAAA;IAAA;IAAA;EAAA;AAGtB","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["../../../../src/components/Code.tsx"],"sourcesContent":["import { computed, List, memo } from \"@alloy-js/core\";\nimport type { Children } from \"@alloy-js/core/jsx-runtime\";\n\nexport interface CodeProps {\n /**\n * Optional Markdown info string (language followed by optional metadata).\n * Must be a single line. Backticks are supported by using tilde fences.\n */\n lang?: string;\n\n /**\n * Body of the code block. Direct strings determine the fence length.\n * JSX children render unchanged and must not contain closing fences.\n */\n children?: Children;\n}\n\n/**\n * Render a Markdown code block. Direct string bodies use content-safe fences.\n * JSX children render normally without being inspected for fence conflicts.\n */\nexport function Code(props: CodeProps) {\n const body = memo(() => props.children);\n const info = computed(() => {\n const info = props.lang ?? \"\";\n if (/[\\r\\n]/.test(info)) {\n throw new Error(\"Code lang must be a single-line Markdown info string.\");\n }\n return info.trim();\n });\n const fence = computed(() => {\n const marker = info.value.includes(\"`\") ? \"~\" : \"`\";\n const content = body();\n const runs =\n typeof content === \"string\"\n ? (content.match(marker === \"`\" ? /`+/g : /~+/g) ?? [])\n : [];\n const length = runs.reduce(\n (length, run) => Math.max(length, run.length + 1),\n 3,\n );\n return marker.repeat(length);\n });\n return (\n <List>\n {fence.value + info.value}\n {body()}\n {fence.value}\n </List>\n );\n}\n"],"mappings":";AAAA,SAAS,QAAQ,EAAE,IAAI,EAAE,IAAI,QAAQ,gBAAgB;AAiBrD;AACA;AACA;AACA;AACA,OAAO,SAAS,IAAI,CAAC,KAAgB,EAAE;EACrC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,QAAQ,CAAC;EACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM;IAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,EAAE;IAC7B,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;MACvB,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC;IAC1E;IACA,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;EACpB,CAAC,CAAC;EACF,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM;IAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG;IACnD,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC;IACtB,MAAM,IAAI,GACR,OAAO,OAAO,KAAK,QAAQ,GACtB,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,GAAG,GAAG,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,GACpD,EAAE;IACR,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CACxB,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,EACjD,CACF,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;EAC9B,CAAC,CAAC;EACF,yBACG,IAAI;IAAA;MAAA,qBACF,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,gBACxB,IAAI,CAAC,CAAC,kCACN,KAAK,CAAC,KAAK;IAAA;EAAA;IAAA;IAAA;IAAA;EAAA;AAGlB","ignoreList":[]}
@@ -1,7 +1,71 @@
1
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
1
+ import { memo as _$memo, createIntrinsic as _$createIntrinsic, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { BasicScope, childrenArray, code, createSymbol, Declaration, memo, onCleanup, shallowRef, SourceFileContext, useContext, useScope } from "@alloy-js/core";
2
3
  import { useSectionContext } from "../context/section.js";
4
+ import { MarkdownFileContext } from "../context/source-file.js";
5
+ import { HeadingSymbol } from "../symbols/heading-symbol.js";
3
6
  export function Heading(props) {
4
7
  const level = props.level !== undefined ? props.level : useSectionContext().level;
5
- return [_$memo(() => "#".repeat(level)), " ", _$memo(() => props.children, false, "props.children")];
8
+ const children = memo(() => childrenArray(() => props.children));
9
+ const file = useContext(MarkdownFileContext);
10
+ const sourceFile = useContext(SourceFileContext);
11
+ const scope = useScope();
12
+ if (!file || !sourceFile || !(scope instanceof BasicScope)) {
13
+ if (props.refkey === undefined && props.id === undefined) {
14
+ return [_$memo(() => "#".repeat(level)), " ", children];
15
+ }
16
+ throw new Error("Heading must be rendered inside a Markdown SourceFile.");
17
+ }
18
+ const text = memo(() => headingText(children()));
19
+ const symbol = props.refkey === undefined ? undefined : createSymbol(HeadingSymbol, props.id ?? "", scope.symbols, {
20
+ refkeys: props.refkey,
21
+ ignoreNameConflict: true,
22
+ path: sourceFile.path,
23
+ text
24
+ });
25
+ const entry = {
26
+ text,
27
+ get id() {
28
+ const id = props.id;
29
+ if (id !== undefined && (id.length === 0 || /[\s"'<>&]/u.test(id))) {
30
+ throw new Error(`Invalid Markdown heading ID: ${JSON.stringify(id)}.`);
31
+ }
32
+ return id;
33
+ },
34
+ symbol,
35
+ anchor: shallowRef()
36
+ };
37
+ file.headings.add(entry);
38
+ onCleanup(() => {
39
+ file.headings.delete(entry);
40
+ symbol?.delete();
41
+ });
42
+ const heading = [() => entry.anchor.value !== undefined && [_$memo(() => code`<a id="${entry.anchor.value}"></a>`), _$createIntrinsic("hbr", {}, {
43
+ fileName: import.meta.url,
44
+ lineNumber: 90,
45
+ columnNumber: 13
46
+ }), _$createIntrinsic("hbr", {}, {
47
+ fileName: import.meta.url,
48
+ lineNumber: 91,
49
+ columnNumber: 13
50
+ })], _$memo(() => "#".repeat(level)), " ", children];
51
+ return symbol ? _$createComponent(Declaration, {
52
+ symbol: symbol,
53
+ children: heading
54
+ }, {
55
+ fileName: import.meta.url,
56
+ lineNumber: 99,
57
+ columnNumber: 5
58
+ }) : heading;
59
+ }
60
+ function headingText(children) {
61
+ let text = "";
62
+ for (const child of children) {
63
+ if (typeof child === "string" || typeof child === "number") {
64
+ text += child;
65
+ } else if (child !== null && child !== undefined && typeof child !== "boolean") {
66
+ return undefined;
67
+ }
68
+ }
69
+ return text.trim();
6
70
  }
7
71
  //# sourceMappingURL=Heading.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../../../src/components/Heading.tsx"],"sourcesContent":["import type { Refkey } from \"@alloy-js/core\";\nimport type { Children } from \"@alloy-js/core/jsx-runtime\";\n\nimport { useSectionContext } from \"../context/section.js\";\n\nexport interface HeadingProps {\n level?: number;\n children: Children;\n refkey?: Refkey;\n}\n\nexport function Heading(props: HeadingProps) {\n const level =\n props.level !== undefined ? props.level : useSectionContext().level;\n return (\n <>\n {\"#\".repeat(level)} {props.children}\n </>\n );\n}\n"],"mappings":";AAGA,SAAS,iBAAiB,QAAQ,uBAAuB;AAQzD,OAAO,SAAS,OAAO,CAAC,KAAmB,EAAE;EAC3C,MAAM,KAAK,GACT,KAAK,CAAC,KAAK,KAAK,SAAS,GAAG,KAAK,CAAC,KAAK,GAAG,iBAAiB,CAAC,CAAC,CAAC,KAAK;EACrE,qBAEK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAG,KAAK,CAAC,QAAQ;AAGzC","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["../../../../src/components/Heading.tsx"],"sourcesContent":["import {\n BasicScope,\n childrenArray,\n code,\n createSymbol,\n Declaration,\n memo,\n onCleanup,\n shallowRef,\n SourceFileContext,\n useContext,\n useScope,\n type Children,\n type Refkey,\n} from \"@alloy-js/core\";\n\nimport { useSectionContext } from \"../context/section.js\";\nimport {\n MarkdownFileContext,\n type HeadingEntry,\n} from \"../context/source-file.js\";\nimport { HeadingSymbol } from \"../symbols/heading-symbol.js\";\n\nexport interface HeadingProps {\n /** Heading depth. Defaults to the current section depth. */\n level?: number;\n /**\n * Heading content. Automatic IDs and default link text are derived from\n * string children; headings with JSX children need an explicit `id` to be\n * referenced.\n */\n children: Children;\n /** Key used to link to this heading. */\n refkey?: Refkey;\n /** Stable anchor ID independent of the display text. Must be unique in the file. */\n id?: string;\n}\n\nexport function Heading(props: HeadingProps) {\n const level =\n props.level !== undefined ? props.level : useSectionContext().level;\n const children = memo(() => childrenArray(() => props.children));\n const file = useContext(MarkdownFileContext);\n const sourceFile = useContext(SourceFileContext);\n const scope = useScope();\n if (!file || !sourceFile || !(scope instanceof BasicScope)) {\n if (props.refkey === undefined && props.id === undefined) {\n return (\n <>\n {\"#\".repeat(level)} {children}\n </>\n );\n }\n throw new Error(\"Heading must be rendered inside a Markdown SourceFile.\");\n }\n\n const text = memo(() => headingText(children()));\n const symbol =\n props.refkey === undefined\n ? undefined\n : createSymbol(HeadingSymbol, props.id ?? \"\", scope.symbols, {\n refkeys: props.refkey,\n ignoreNameConflict: true,\n path: sourceFile.path,\n text,\n });\n const entry: HeadingEntry = {\n text,\n get id() {\n const id = props.id;\n if (id !== undefined && (id.length === 0 || /[\\s\"'<>&]/u.test(id))) {\n throw new Error(`Invalid Markdown heading ID: ${JSON.stringify(id)}.`);\n }\n return id;\n },\n symbol,\n anchor: shallowRef<string>(),\n };\n file.headings.add(entry);\n onCleanup(() => {\n file.headings.delete(entry);\n symbol?.delete();\n });\n const heading = (\n <>\n {() =>\n entry.anchor.value !== undefined && (\n <>\n {code`<a id=\"${entry.anchor.value}\"></a>`}\n <hbr />\n <hbr />\n </>\n )\n }\n {\"#\".repeat(level)} {children}\n </>\n );\n return symbol ? (\n <Declaration symbol={symbol}>{heading}</Declaration>\n ) : (\n heading\n );\n}\n\nfunction headingText(children: Children[]): string | undefined {\n let text = \"\";\n for (const child of children) {\n if (typeof child === \"string\" || typeof child === \"number\") {\n text += child;\n } else if (\n child !== null &&\n child !== undefined &&\n typeof child !== \"boolean\"\n ) {\n return undefined;\n }\n }\n return text.trim();\n}\n"],"mappings":";AAAA,SACE,UAAU,EACV,aAAa,EACb,IAAI,EACJ,YAAY,EACZ,WAAW,EACX,IAAI,EACJ,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,QAAQ,QAGH,gBAAgB;AAEvB,SAAS,iBAAiB,QAAQ,uBAAuB;AACzD,SACE,mBAAmB,QAEd,2BAA2B;AAClC,SAAS,aAAa,QAAQ,8BAA8B;AAiB5D,OAAO,SAAS,OAAO,CAAC,KAAmB,EAAE;EAC3C,MAAM,KAAK,GACT,KAAK,CAAC,KAAK,KAAK,SAAS,GAAG,KAAK,CAAC,KAAK,GAAG,iBAAiB,CAAC,CAAC,CAAC,KAAK;EACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,aAAa,CAAC,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;EAChE,MAAM,IAAI,GAAG,UAAU,CAAC,mBAAmB,CAAC;EAC5C,MAAM,UAAU,GAAG,UAAU,CAAC,iBAAiB,CAAC;EAChD,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC;EACxB,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,KAAK,YAAY,UAAU,CAAC,EAAE;IAC1D,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,EAAE,KAAK,SAAS,EAAE;MACxD,qBAEK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,QAAG,QAAQ;IAGnC;IACA,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC;EAC3E;EAEA,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;EAChD,MAAM,MAAM,GACV,KAAK,CAAC,MAAM,KAAK,SAAS,GACtB,SAAS,GACT,YAAY,CAAC,aAAa,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE;IACzD,OAAO,EAAE,KAAK,CAAC,MAAM;IACrB,kBAAkB,EAAE,IAAI;IACxB,IAAI,EAAE,UAAU,CAAC,IAAI;IACrB;EACF,CAAC,CAAC;EACR,MAAM,KAAmB,GAAG;IAC1B,IAAI;IACJ,IAAI,EAAE,GAAG;MACP,MAAM,EAAE,GAAG,KAAK,CAAC,EAAE;MACnB,IAAI,EAAE,KAAK,SAAS,KAAK,EAAE,CAAC,MAAM,KAAK,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE;QAClE,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC;MACxE;MACA,OAAO,EAAE;IACX,CAAC;IACD,MAAM;IACN,MAAM,EAAE,UAAU,CAAS;EAC7B,CAAC;EACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;EACxB,SAAS,CAAC,MAAM;IACd,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC,CAAC;EAClB,CAAC,CAAC;EACF,MAAM,OAAO,IAER,MACC,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS,kBAE3B,IAAI,UAAU,KAAK,CAAC,MAAM,CAAC,KAAK,QAAQ;IAAA;IAAA;IAAA;EAAA;IAAA;IAAA;IAAA;EAAA,GAI5C,eAEF,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,QAAG,QAAQ,CAEhC;EACD,OAAO,MAAM,qBACV,WAAW;IAAC,MAAM,EAAE,MAAM;IAAA,UAAG;EAAO;IAAA;IAAA;IAAA;EAAA,KAErC,OACD;AACH;AAEA,SAAS,WAAW,CAAC,QAAoB,EAAsB;EAC7D,IAAI,IAAI,GAAG,EAAE;EACb,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE;IAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;MAC1D,IAAI,IAAI,KAAK;IACf,CAAC,MAAM,IACL,KAAK,KAAK,IAAI,IACd,KAAK,KAAK,SAAS,IACnB,OAAO,KAAK,KAAK,SAAS,EAC1B;MACA,OAAO,SAAS;IAClB;EACF;EACA,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;AACpB","ignoreList":[]}
@@ -1,8 +1,40 @@
1
1
  import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { resolve, SourceFileContext, unresolvedRefkey, useContext } from "@alloy-js/core";
3
+ import { dirname, relative } from "pathe";
4
+ import { useTableContext } from "../context/table.js";
5
+ import { HeadingSymbol } from "../symbols/heading-symbol.js";
2
6
  export function Link(props) {
3
7
  if ("refkey" in props) {
4
- return "refkey";
8
+ const sourceFile = useContext(SourceFileContext);
9
+ if (!sourceFile) {
10
+ throw new Error("Link references must be rendered inside a SourceFile.");
11
+ }
12
+ const table = useTableContext();
13
+ return () => {
14
+ const target = resolve(props.refkey);
15
+ if (!target.value) {
16
+ return unresolvedRefkey(props.refkey);
17
+ }
18
+ const symbol = target.value.symbol;
19
+ if (!(symbol instanceof HeadingSymbol)) {
20
+ throw new Error("Markdown Link refkey must reference a Heading.");
21
+ }
22
+ const path = sourceFile.path === symbol.path ? "" : relative(dirname(sourceFile.path), symbol.path).split("/").map(encodeUrlPart).join("/");
23
+ const href = `${path}#${encodeUrlPart(symbol.name)}`;
24
+ return `[${props.title ?? defaultTitle(symbol, table)}](${href})`;
25
+ };
5
26
  }
6
27
  return ["[", _$memo(() => props.title, false, "props.title"), "](", _$memo(() => props.href, false, "props.href"), ")"];
7
28
  }
29
+ function defaultTitle(symbol, table) {
30
+ const text = symbol.text();
31
+ if (text === undefined) {
32
+ throw new Error(`Link to Markdown heading ${JSON.stringify(symbol.name)} requires a title because the heading has non-string children.`);
33
+ }
34
+ const title = text.replace(/[\\`*_[\]<>&~]/g, "\\$&");
35
+ return table ? title.replace(/\|/g, "\\|") : title;
36
+ }
37
+ function encodeUrlPart(value) {
38
+ return encodeURIComponent(value).replace(/[!'()*]/g, character => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
39
+ }
8
40
  //# sourceMappingURL=Link.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../../../src/components/Link.tsx"],"sourcesContent":["import type { Refkey } from \"@alloy-js/core\";\n\nexport interface LinkPropsWithRefkey {\n refkey: Refkey;\n}\n\nexport interface LinkPropsWithHref {\n href: string;\n title: string;\n}\n\nexport type LinkProps = LinkPropsWithRefkey | LinkPropsWithHref;\n\nexport function Link(props: LinkProps) {\n if (\"refkey\" in props) {\n return \"refkey\";\n }\n\n return (\n <>\n [{props.title}]({props.href})\n </>\n );\n}\n"],"mappings":";AAaA,OAAO,SAAS,IAAI,CAAC,KAAgB,EAAE;EACrC,IAAI,QAAQ,IAAI,KAAK,EAAE;IACrB,OAAO,QAAQ;EACjB;EAEA,0BAEM,KAAK,CAAC,KAAK,4CAAI,KAAK,CAAC,IAAI;AAGjC","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["../../../../src/components/Link.tsx"],"sourcesContent":["import {\n resolve,\n SourceFileContext,\n unresolvedRefkey,\n useContext,\n type Refkey,\n} from \"@alloy-js/core\";\nimport { dirname, relative } from \"pathe\";\n\nimport { useTableContext } from \"../context/table.js\";\nimport { HeadingSymbol } from \"../symbols/heading-symbol.js\";\n\nexport interface LinkPropsWithRefkey {\n /** Key of the target heading, which may be declared later or in another file. */\n refkey: Refkey;\n /**\n * Override the link text. Defaults to the target heading's text, which\n * requires the heading to have string children.\n */\n title?: string;\n}\n\nexport interface LinkPropsWithHref {\n /** Link destination. */\n href: string;\n /** Link text. */\n title: string;\n}\n\nexport type LinkProps = LinkPropsWithRefkey | LinkPropsWithHref;\n\nexport function Link(props: LinkProps) {\n if (\"refkey\" in props) {\n const sourceFile = useContext(SourceFileContext);\n if (!sourceFile) {\n throw new Error(\"Link references must be rendered inside a SourceFile.\");\n }\n const table = useTableContext();\n return () => {\n const target = resolve(props.refkey);\n if (!target.value) {\n return unresolvedRefkey(props.refkey);\n }\n const symbol = target.value.symbol;\n if (!(symbol instanceof HeadingSymbol)) {\n throw new Error(\"Markdown Link refkey must reference a Heading.\");\n }\n const path =\n sourceFile.path === symbol.path\n ? \"\"\n : relative(dirname(sourceFile.path), symbol.path)\n .split(\"/\")\n .map(encodeUrlPart)\n .join(\"/\");\n const href = `${path}#${encodeUrlPart(symbol.name)}`;\n return `[${props.title ?? defaultTitle(symbol, table)}](${href})`;\n };\n }\n\n return (\n <>\n [{props.title}]({props.href})\n </>\n );\n}\n\nfunction defaultTitle(symbol: HeadingSymbol, table: boolean): string {\n const text = symbol.text();\n if (text === undefined) {\n throw new Error(\n `Link to Markdown heading ${JSON.stringify(symbol.name)} requires a title because the heading has non-string children.`,\n );\n }\n const title = text.replace(/[\\\\`*_[\\]<>&~]/g, \"\\\\$&\");\n return table ? title.replace(/\\|/g, \"\\\\|\") : title;\n}\n\nfunction encodeUrlPart(value: string): string {\n return encodeURIComponent(value).replace(\n /[!'()*]/g,\n (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`,\n );\n}\n"],"mappings":";AAAA,SACE,OAAO,EACP,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,QAEL,gBAAgB;AACvB,SAAS,OAAO,EAAE,QAAQ,QAAQ,OAAO;AAEzC,SAAS,eAAe,QAAQ,qBAAqB;AACrD,SAAS,aAAa,QAAQ,8BAA8B;AAqB5D,OAAO,SAAS,IAAI,CAAC,KAAgB,EAAE;EACrC,IAAI,QAAQ,IAAI,KAAK,EAAE;IACrB,MAAM,UAAU,GAAG,UAAU,CAAC,iBAAiB,CAAC;IAChD,IAAI,CAAC,UAAU,EAAE;MACf,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC;IAC1E;IACA,MAAM,KAAK,GAAG,eAAe,CAAC,CAAC;IAC/B,OAAO,MAAM;MACX,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;MACpC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;QACjB,OAAO,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC;MACvC;MACA,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM;MAClC,IAAI,EAAE,MAAM,YAAY,aAAa,CAAC,EAAE;QACtC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC;MACnE;MACA,MAAM,IAAI,GACR,UAAU,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,GAC3B,EAAE,GACF,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAC5C,KAAK,CAAC,GAAG,CAAC,CACV,GAAG,CAAC,aAAa,CAAC,CAClB,IAAI,CAAC,GAAG,CAAC;MAClB,MAAM,IAAI,GAAG,GAAG,IAAI,IAAI,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;MACpD,OAAO,IAAI,KAAK,CAAC,KAAK,IAAI,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,IAAI,GAAG;IACnE,CAAC;EACH;EAEA,0BAEM,KAAK,CAAC,KAAK,4CAAI,KAAK,CAAC,IAAI;AAGjC;AAEA,SAAS,YAAY,CAAC,MAAqB,EAAE,KAAc,EAAU;EACnE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;EAC1B,IAAI,IAAI,KAAK,SAAS,EAAE;IACtB,MAAM,IAAI,KAAK,CACb,4BAA4B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,gEACzD,CAAC;EACH;EACA,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,MAAM,CAAC;EACrD,OAAO,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,KAAK;AACpD;AAEA,SAAS,aAAa,CAAC,KAAa,EAAU;EAC5C,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC,OAAO,CACtC,UAAU,EACT,SAAS,IAAK,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,EACvE,CAAC;AACH","ignoreList":[]}
@@ -1,7 +1,10 @@
1
1
  import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { SourceFile as CoreSourceFile, List } from "@alloy-js/core";
2
+ import { BasicScope, SourceFile as CoreSourceFile, createScope, List, Scope, useScope } from "@alloy-js/core";
3
+ import { createMarkdownFileContext, MarkdownFileContext } from "../context/source-file.js";
3
4
  import { Link } from "./Link.js";
4
5
  export function SourceFile(props) {
6
+ const scope = createScope(BasicScope, props.path, useScope());
7
+ const file = createMarkdownFileContext();
5
8
  return _$createComponent(CoreSourceFile, {
6
9
  get path() {
7
10
  return props.path;
@@ -9,20 +12,38 @@ export function SourceFile(props) {
9
12
  filetype: "md",
10
13
  reference: Link,
11
14
  get children() {
12
- return _$createComponent(List, {
13
- doubleHardline: true,
15
+ return _$createComponent(Scope, {
16
+ value: scope,
14
17
  get children() {
15
- return props.children;
18
+ return _$createComponent(MarkdownFileContext.Provider, {
19
+ value: file,
20
+ get children() {
21
+ return _$createComponent(List, {
22
+ doubleHardline: true,
23
+ get children() {
24
+ return props.children;
25
+ }
26
+ }, {
27
+ fileName: import.meta.url,
28
+ lineNumber: 28,
29
+ columnNumber: 11
30
+ });
31
+ }
32
+ }, {
33
+ fileName: import.meta.url,
34
+ lineNumber: 27,
35
+ columnNumber: 9
36
+ });
16
37
  }
17
38
  }, {
18
39
  fileName: import.meta.url,
19
- lineNumber: 13,
40
+ lineNumber: 26,
20
41
  columnNumber: 7
21
42
  });
22
43
  }
23
44
  }, {
24
45
  fileName: import.meta.url,
25
- lineNumber: 12,
46
+ lineNumber: 25,
26
47
  columnNumber: 5
27
48
  });
28
49
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../../../src/components/SourceFile.tsx"],"sourcesContent":["import type { Children } from \"@alloy-js/core\";\nimport { SourceFile as CoreSourceFile, List } from \"@alloy-js/core\";\n\nimport { Link } from \"./Link.jsx\";\n\nexport interface SourceFileProps {\n path: string;\n children: Children;\n}\nexport function SourceFile(props: SourceFileProps) {\n return (\n <CoreSourceFile path={props.path} filetype=\"md\" reference={Link}>\n <List doubleHardline>{props.children}</List>\n </CoreSourceFile>\n );\n}\n"],"mappings":";AACA,SAAS,UAAU,IAAI,cAAc,EAAE,IAAI,QAAQ,gBAAgB;AAEnE,SAAS,IAAI;AAMb,OAAO,SAAS,UAAU,CAAC,KAAsB,EAAE;EACjD,yBACG,cAAc;IAAA,IAAC,IAAI;MAAA,OAAE,KAAK,CAAC,IAAI;IAAA;IAAE,QAAQ;IAAM,SAAS,EAAE,IAAI;IAAA;MAAA,yBAC5D,IAAI;QAAC,cAAc;QAAA;UAAA,OAAE,KAAK,CAAC,QAAQ;QAAA;MAAA;QAAA;QAAA;QAAA;MAAA;IAAA;EAAA;IAAA;IAAA;IAAA;EAAA;AAG1C","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["../../../../src/components/SourceFile.tsx"],"sourcesContent":["import type { Children } from \"@alloy-js/core\";\nimport {\n BasicScope,\n SourceFile as CoreSourceFile,\n createScope,\n List,\n Scope,\n useScope,\n} from \"@alloy-js/core\";\n\nimport {\n createMarkdownFileContext,\n MarkdownFileContext,\n} from \"../context/source-file.js\";\nimport { Link } from \"./Link.jsx\";\n\nexport interface SourceFileProps {\n path: string;\n children: Children;\n}\nexport function SourceFile(props: SourceFileProps) {\n const scope = createScope(BasicScope, props.path, useScope());\n const file = createMarkdownFileContext();\n return (\n <CoreSourceFile path={props.path} filetype=\"md\" reference={Link}>\n <Scope value={scope}>\n <MarkdownFileContext.Provider value={file}>\n <List doubleHardline>{props.children}</List>\n </MarkdownFileContext.Provider>\n </Scope>\n </CoreSourceFile>\n );\n}\n"],"mappings":";AACA,SACE,UAAU,EACV,UAAU,IAAI,cAAc,EAC5B,WAAW,EACX,IAAI,EACJ,KAAK,EACL,QAAQ,QACH,gBAAgB;AAEvB,SACE,yBAAyB,EACzB,mBAAmB,QACd,2BAA2B;AAClC,SAAS,IAAI;AAMb,OAAO,SAAS,UAAU,CAAC,KAAsB,EAAE;EACjD,MAAM,KAAK,GAAG,WAAW,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;EAC7D,MAAM,IAAI,GAAG,yBAAyB,CAAC,CAAC;EACxC,yBACG,cAAc;IAAA,IAAC,IAAI;MAAA,OAAE,KAAK,CAAC,IAAI;IAAA;IAAE,QAAQ;IAAM,SAAS,EAAE,IAAI;IAAA;MAAA,yBAC5D,KAAK;QAAC,KAAK,EAAE,KAAK;QAAA;UAAA,yBAChB,mBAAmB,CAAC,QAAQ;YAAC,KAAK,EAAE,IAAI;YAAA;cAAA,yBACtC,IAAI;gBAAC,cAAc;gBAAA;kBAAA,OAAE,KAAK,CAAC,QAAQ;gBAAA;cAAA;gBAAA;gBAAA;gBAAA;cAAA;YAAA;UAAA;YAAA;YAAA;YAAA;UAAA;QAAA;MAAA;QAAA;QAAA;QAAA;MAAA;IAAA;EAAA;IAAA;IAAA;IAAA;EAAA;AAK9C","ignoreList":[]}
@@ -1,8 +1,10 @@
1
1
  export * from "./Code.js";
2
2
  export * from "./Frontmatter.js";
3
3
  export * from "./Heading.js";
4
+ export * from "./inline-code.js";
4
5
  export * from "./Link.js";
5
6
  export * from "./List.js";
6
7
  export * from "./Section.js";
7
8
  export * from "./SourceFile.js";
9
+ export * from "./table.js";
8
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../../../src/components/index.ts"],"sourcesContent":["export * from \"./Code.jsx\";\nexport * from \"./Frontmatter.jsx\";\nexport * from \"./Heading.jsx\";\nexport * from \"./Link.jsx\";\nexport * from \"./List.jsx\";\nexport * from \"./Section.jsx\";\nexport * from \"./SourceFile.jsx\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["../../../../src/components/index.ts"],"sourcesContent":["export * from \"./Code.jsx\";\nexport * from \"./Frontmatter.jsx\";\nexport * from \"./Heading.jsx\";\nexport * from \"./inline-code.jsx\";\nexport * from \"./Link.jsx\";\nexport * from \"./List.jsx\";\nexport * from \"./Section.jsx\";\nexport * from \"./SourceFile.jsx\";\nexport * from \"./table.jsx\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,28 @@
1
+ import { useTableContext } from "../context/table.js";
2
+ /**
3
+ * Render a Markdown code span. Direct strings use adaptive delimiters and
4
+ * padding, with each CRLF, CR, or LF replaced by one space.
5
+ * Empty strings and omitted content use inline HTML.
6
+ * Direct string pipes are escaped inside table cells and left literal elsewhere.
7
+ */
8
+ export function InlineCode(props) {
9
+ const inTable = useTableContext();
10
+ return () => {
11
+ const content = props.children ?? "";
12
+ return typeof content === "string" ? inlineCode(inTable ? content.replace(/\|/g, "\\|") : content) : ["`", content, "`"];
13
+ };
14
+ }
15
+ function inlineCode(content) {
16
+ const text = content.replace(/\r\n|\r|\n/g, " ");
17
+ // CommonMark has no empty code-span syntax.
18
+ if (text.length === 0) return "<code></code>";
19
+ let delimiterLength = 1;
20
+ for (const match of text.matchAll(/`+/g)) {
21
+ delimiterLength = Math.max(delimiterLength, match[0].length + 1);
22
+ }
23
+ const delimiter = "`".repeat(delimiterLength);
24
+ const needsPadding = text.startsWith("`") || text.endsWith("`") || text.startsWith(" ") && text.endsWith(" ") && /[^ ]/.test(text);
25
+ const padding = needsPadding ? " " : "";
26
+ return delimiter + padding + text + padding + delimiter;
27
+ }
28
+ //# sourceMappingURL=inline-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../../../src/components/inline-code.tsx"],"sourcesContent":["import type { Children } from \"@alloy-js/core\";\n\nimport { useTableContext } from \"../context/table.js\";\n\nexport interface InlineCodeProps {\n /**\n * Direct strings are escaped automatically. JSX and other non-string\n * children are wrapped in single backticks unchanged; callers own escaping.\n */\n children?: Children;\n}\n\n/**\n * Render a Markdown code span. Direct strings use adaptive delimiters and\n * padding, with each CRLF, CR, or LF replaced by one space.\n * Empty strings and omitted content use inline HTML.\n * Direct string pipes are escaped inside table cells and left literal elsewhere.\n */\nexport function InlineCode(props: InlineCodeProps) {\n const inTable = useTableContext();\n return () => {\n const content = props.children ?? \"\";\n return typeof content === \"string\" ? (\n inlineCode(inTable ? content.replace(/\\|/g, \"\\\\|\") : content)\n ) : (\n <>\n {\"`\"}\n {content}\n {\"`\"}\n </>\n );\n };\n}\n\nfunction inlineCode(content: string): string {\n const text = content.replace(/\\r\\n|\\r|\\n/g, \" \");\n // CommonMark has no empty code-span syntax.\n if (text.length === 0) return \"<code></code>\";\n\n let delimiterLength = 1;\n for (const match of text.matchAll(/`+/g)) {\n delimiterLength = Math.max(delimiterLength, match[0].length + 1);\n }\n const delimiter = \"`\".repeat(delimiterLength);\n const needsPadding =\n text.startsWith(\"`\") ||\n text.endsWith(\"`\") ||\n (text.startsWith(\" \") && text.endsWith(\" \") && /[^ ]/.test(text));\n const padding = needsPadding ? \" \" : \"\";\n return delimiter + padding + text + padding + delimiter;\n}\n"],"mappings":"AAEA,SAAS,eAAe,QAAQ,qBAAqB;AAUrD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,UAAU,CAAC,KAAsB,EAAE;EACjD,MAAM,OAAO,GAAG,eAAe,CAAC,CAAC;EACjC,OAAO,MAAM;IACX,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,IAAI,EAAE;IACpC,OAAO,OAAO,OAAO,KAAK,QAAQ,GAChC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,IAG1D,GAAG,EACH,OAAO,EACP,GAAG,CAEP;EACH,CAAC;AACH;AAEA,SAAS,UAAU,CAAC,OAAe,EAAU;EAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;EAChD;EACA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,eAAe;EAE7C,IAAI,eAAe,GAAG,CAAC;EACvB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;IACxC,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;EAClE;EACA,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC;EAC7C,MAAM,YAAY,GAChB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IACpB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IACjB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAE;EACnE,MAAM,OAAO,GAAG,YAAY,GAAG,GAAG,GAAG,EAAE;EACvC,OAAO,SAAS,GAAG,OAAO,GAAG,IAAI,GAAG,OAAO,GAAG,SAAS;AACzD","ignoreList":[]}
@@ -0,0 +1,98 @@
1
+ import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { childrenArray, code, For, List, memo } from "@alloy-js/core";
3
+ import { TableContext } from "../context/table.js";
4
+ /**
5
+ * Render a GFM table with a header and optional body rows.
6
+ *
7
+ * Direct string cells are escaped, with newlines converted to inline HTML
8
+ * breaks. JSX output is not inspected; callers own its escaping and layout.
9
+ */
10
+ export function Table(props) {
11
+ const rows = memo(() => childrenArray(() => props.children));
12
+ return () => {
13
+ if (props.columns.length === 0) {
14
+ throw new Error("Table requires at least one column.");
15
+ }
16
+ const delimiters = props.columns.map(column => column.align === "center" ? ":---:" : column.align === "right" ? "---:" : column.align === "left" ? ":---" : "---");
17
+ return _$createComponent(List, {
18
+ get children() {
19
+ return [_$createComponent(TableRow, {
20
+ get children() {
21
+ return _$createComponent(For, {
22
+ get each() {
23
+ return props.columns;
24
+ },
25
+ joiner: "",
26
+ children: column => _$createComponent(TableCell, {
27
+ get children() {
28
+ return column.header;
29
+ }
30
+ }, {
31
+ fileName: import.meta.url,
32
+ lineNumber: 53,
33
+ columnNumber: 26
34
+ })
35
+ }, {
36
+ fileName: import.meta.url,
37
+ lineNumber: 52,
38
+ columnNumber: 11
39
+ });
40
+ }
41
+ }, {
42
+ fileName: import.meta.url,
43
+ lineNumber: 51,
44
+ columnNumber: 9
45
+ }), _$memo(() => code`| ${delimiters.join(" | ")} |`), _$createComponent(List, {
46
+ children: rows
47
+ }, {
48
+ fileName: import.meta.url,
49
+ lineNumber: 57,
50
+ columnNumber: 9
51
+ })];
52
+ }
53
+ }, {
54
+ fileName: import.meta.url,
55
+ lineNumber: 50,
56
+ columnNumber: 7
57
+ });
58
+ };
59
+ }
60
+ /** Render a single row. Provide one TableCell per column. */
61
+ export function TableRow(props) {
62
+ return code`|${props.children}`;
63
+ }
64
+ /**
65
+ * Escape direct string children without inspecting rendered JSX output.
66
+ * Context-aware Markdown components can escape their own pipes. Other JSX
67
+ * remains uninspected; callers own its escaping and physical line breaks.
68
+ */
69
+ export function TableCell(props) {
70
+ const content = memo(() => childrenArray(() => props.children).map(child => typeof child === "string" ? escapeTableText(child) : child));
71
+ return _$createComponent(TableContext.Provider, {
72
+ value: true,
73
+ children: code` ${content} |`
74
+ }, {
75
+ fileName: import.meta.url,
76
+ lineNumber: 90,
77
+ columnNumber: 5
78
+ });
79
+ }
80
+ function escapeTableText(text) {
81
+ return text.replace(/[&<>\\`*_[\]~|]|\r\n?|\n/g, character => {
82
+ switch (character) {
83
+ case "&":
84
+ return "&amp;";
85
+ case "<":
86
+ return "&lt;";
87
+ case ">":
88
+ return "&gt;";
89
+ case "\r":
90
+ case "\n":
91
+ case "\r\n":
92
+ return "<br>";
93
+ default:
94
+ return `\\${character}`;
95
+ }
96
+ });
97
+ }
98
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../../../src/components/table.tsx"],"sourcesContent":["import {\n childrenArray,\n code,\n For,\n List,\n memo,\n type Children,\n} from \"@alloy-js/core\";\n\nimport { TableContext } from \"../context/table.js\";\n\nexport interface TableColumn {\n /** Column heading. Direct strings are escaped; JSX is passed through. */\n header: Children;\n /** Alignment of the column's contents. */\n align?: \"left\" | \"center\" | \"right\";\n}\n\nexport interface TableProps {\n /** Columns in output order. At least one column is required. */\n columns: readonly TableColumn[];\n /** TableRow components, with one TableCell per column. */\n children?: Children;\n}\n\n/**\n * Render a GFM table with a header and optional body rows.\n *\n * Direct string cells are escaped, with newlines converted to inline HTML\n * breaks. JSX output is not inspected; callers own its escaping and layout.\n */\nexport function Table(props: TableProps) {\n const rows = memo(() => childrenArray(() => props.children));\n return () => {\n if (props.columns.length === 0) {\n throw new Error(\"Table requires at least one column.\");\n }\n\n const delimiters = props.columns.map((column) =>\n column.align === \"center\"\n ? \":---:\"\n : column.align === \"right\"\n ? \"---:\"\n : column.align === \"left\"\n ? \":---\"\n : \"---\",\n );\n\n return (\n <List>\n <TableRow>\n <For each={props.columns} joiner=\"\">\n {(column) => <TableCell>{column.header}</TableCell>}\n </For>\n </TableRow>\n {code`| ${delimiters.join(\" | \")} |`}\n <List>{rows}</List>\n </List>\n );\n };\n}\n\nexport interface TableRowProps {\n /** TableCell components. Use an empty joiner when composing cells with For. */\n children?: Children;\n}\n\n/** Render a single row. Provide one TableCell per column. */\nexport function TableRow(props: TableRowProps) {\n return code`|${props.children}`;\n}\n\nexport interface TableCellProps {\n /** Direct strings are escaped as literal text. JSX is passed through. */\n children?: Children;\n}\n\n/**\n * Escape direct string children without inspecting rendered JSX output.\n * Context-aware Markdown components can escape their own pipes. Other JSX\n * remains uninspected; callers own its escaping and physical line breaks.\n */\nexport function TableCell(props: TableCellProps) {\n const content = memo(() =>\n childrenArray(() => props.children).map((child) =>\n typeof child === \"string\" ? escapeTableText(child) : child,\n ),\n );\n return (\n <TableContext.Provider value={true}>\n {code` ${content} |`}\n </TableContext.Provider>\n );\n}\n\nfunction escapeTableText(text: string): string {\n return text.replace(/[&<>\\\\`*_[\\]~|]|\\r\\n?|\\n/g, (character) => {\n switch (character) {\n case \"&\":\n return \"&amp;\";\n case \"<\":\n return \"&lt;\";\n case \">\":\n return \"&gt;\";\n case \"\\r\":\n case \"\\n\":\n case \"\\r\\n\":\n return \"<br>\";\n default:\n return `\\\\${character}`;\n }\n });\n}\n"],"mappings":";AAAA,SACE,aAAa,EACb,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,IAAI,QAEC,gBAAgB;AAEvB,SAAS,YAAY,QAAQ,qBAAqB;AAgBlD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,KAAK,CAAC,KAAiB,EAAE;EACvC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,aAAa,CAAC,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;EAC5D,OAAO,MAAM;IACX,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;MAC9B,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC;IACxD;IAEA,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAE,MAAM,IAC1C,MAAM,CAAC,KAAK,KAAK,QAAQ,GACrB,OAAO,GACP,MAAM,CAAC,KAAK,KAAK,OAAO,GACtB,MAAM,GACN,MAAM,CAAC,KAAK,KAAK,MAAM,GACrB,MAAM,GACN,KACV,CAAC;IAED,yBACG,IAAI;MAAA;QAAA,0BACF,QAAQ;UAAA;YAAA,yBACN,GAAG;cAAA,IAAC,IAAI;gBAAA,OAAE,KAAK,CAAC,OAAO;cAAA;cAAE,MAAM;cAAA,UAC5B,MAAM,sBAAM,SAAS;gBAAA;kBAAA,OAAE,MAAM,CAAC,MAAM;gBAAA;cAAA;gBAAA;gBAAA;gBAAA;cAAA;YAAa;cAAA;cAAA;cAAA;YAAA;UAAA;QAAA;UAAA;UAAA;UAAA;QAAA,iBAGtD,IAAI,KAAK,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,qBACnC,IAAI;UAAA,UAAE;QAAI;UAAA;UAAA;UAAA;QAAA;MAAA;IAAA;MAAA;MAAA;MAAA;IAAA;EAGjB,CAAC;AACH;AAOA;AACA,OAAO,SAAS,QAAQ,CAAC,KAAoB,EAAE;EAC7C,OAAO,IAAI,IAAI,KAAK,CAAC,QAAQ,EAAE;AACjC;AAOA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,SAAS,CAAC,KAAqB,EAAE;EAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,MACnB,aAAa,CAAC,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAE,KAAK,IAC5C,OAAO,KAAK,KAAK,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,KACvD,CACF,CAAC;EACD,yBACG,YAAY,CAAC,QAAQ;IAAC,KAAK,EAAE,IAAI;IAAA,UAC/B,IAAI,IAAI,OAAO;EAAI;IAAA;IAAA;IAAA;EAAA;AAG1B;AAEA,SAAS,eAAe,CAAC,IAAY,EAAU;EAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,2BAA2B,EAAG,SAAS,IAAK;IAC9D,QAAQ,SAAS;MACf,KAAK,GAAG;QACN,OAAO,OAAO;MAChB,KAAK,GAAG;QACN,OAAO,MAAM;MACf,KAAK,GAAG;QACN,OAAO,MAAM;MACf,KAAK,IAAI;MACT,KAAK,IAAI;MACT,KAAK,MAAM;QACT,OAAO,MAAM;MACf;QACE,OAAO,KAAK,SAAS,EAAE;IAC3B;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,50 @@
1
+ import { createContext, effect, shallowReactive } from "@alloy-js/core";
2
+ import GithubSlugger from "github-slugger";
3
+ export const MarkdownFileContext = createContext();
4
+ export function createMarkdownFileContext() {
5
+ const headings = shallowReactive(new Set());
6
+ effect(() => allocateHeadingIds([...headings]));
7
+ return {
8
+ headings
9
+ };
10
+ }
11
+ function allocateHeadingIds(headings) {
12
+ // Renderers generate an ID for every heading, including those with an explicit ID.
13
+ const slugger = new GithubSlugger();
14
+ let opaque = false;
15
+ const automatic = headings.map(heading => {
16
+ const text = heading.text();
17
+ if (opaque && heading.symbol && heading.id === undefined) {
18
+ throw new Error("A Heading with a refkey requires an explicit id after a heading with non-string children.");
19
+ }
20
+ if (text === undefined) opaque = true;
21
+ return text === undefined ? undefined : slugger.slug(text);
22
+ });
23
+ const ids = new Set(automatic.filter(id => id !== undefined));
24
+ const explicit = new Set();
25
+ headings.forEach((heading, i) => {
26
+ const id = heading.id;
27
+ if (id === undefined) return;
28
+ if (explicit.has(id) || ids.has(id) && automatic[i] !== id) {
29
+ throw new Error(`Duplicate Markdown heading ID: ${JSON.stringify(id)}.`);
30
+ }
31
+ explicit.add(id);
32
+ });
33
+ for (const id of explicit) ids.add(id);
34
+ headings.forEach((heading, i) => {
35
+ let anchor = heading.id;
36
+ if (anchor === undefined && automatic[i] === "" && heading.symbol) {
37
+ anchor = "section";
38
+ for (let n = 1; ids.has(anchor); n++) anchor = `section-${n}`;
39
+ ids.add(anchor);
40
+ }
41
+ heading.anchor.value = anchor;
42
+ if (!heading.symbol) return;
43
+ const name = anchor ?? automatic[i];
44
+ if (name === undefined) {
45
+ throw new Error("A Heading with a refkey and non-string children requires an explicit id.");
46
+ }
47
+ heading.symbol.name = name;
48
+ });
49
+ }
50
+ //# sourceMappingURL=source-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../../../src/context/source-file.ts"],"sourcesContent":["import {\n createContext,\n effect,\n shallowReactive,\n type Ref,\n} from \"@alloy-js/core\";\nimport GithubSlugger from \"github-slugger\";\n\nimport type { HeadingSymbol } from \"../symbols/heading-symbol.js\";\n\nexport interface HeadingEntry {\n /** Trimmed heading text, or `undefined` when the heading has JSX children. */\n text: () => string | undefined;\n /** Explicit anchor ID. */\n id?: string;\n /** Link target, present when the heading has a refkey. */\n symbol?: HeadingSymbol;\n /** HTML anchor emitted before the heading, if any. */\n anchor: Ref<string | undefined>;\n}\n\nexport interface MarkdownFileContext {\n /** Headings in the file, in mount order. */\n headings: Set<HeadingEntry>;\n}\n\nexport const MarkdownFileContext = createContext<MarkdownFileContext>();\n\nexport function createMarkdownFileContext(): MarkdownFileContext {\n const headings = shallowReactive(new Set<HeadingEntry>());\n effect(() => allocateHeadingIds([...headings]));\n return { headings };\n}\n\nfunction allocateHeadingIds(headings: HeadingEntry[]) {\n // Renderers generate an ID for every heading, including those with an explicit ID.\n const slugger = new GithubSlugger();\n let opaque = false;\n const automatic = headings.map((heading) => {\n const text = heading.text();\n if (opaque && heading.symbol && heading.id === undefined) {\n throw new Error(\n \"A Heading with a refkey requires an explicit id after a heading with non-string children.\",\n );\n }\n if (text === undefined) opaque = true;\n return text === undefined ? undefined : slugger.slug(text);\n });\n const ids = new Set(automatic.filter((id) => id !== undefined));\n\n const explicit = new Set<string>();\n headings.forEach((heading, i) => {\n const id = heading.id;\n if (id === undefined) return;\n if (explicit.has(id) || (ids.has(id) && automatic[i] !== id)) {\n throw new Error(`Duplicate Markdown heading ID: ${JSON.stringify(id)}.`);\n }\n explicit.add(id);\n });\n for (const id of explicit) ids.add(id);\n\n headings.forEach((heading, i) => {\n let anchor = heading.id;\n if (anchor === undefined && automatic[i] === \"\" && heading.symbol) {\n anchor = \"section\";\n for (let n = 1; ids.has(anchor); n++) anchor = `section-${n}`;\n ids.add(anchor);\n }\n heading.anchor.value = anchor;\n if (!heading.symbol) return;\n const name = anchor ?? automatic[i];\n if (name === undefined) {\n throw new Error(\n \"A Heading with a refkey and non-string children requires an explicit id.\",\n );\n }\n heading.symbol.name = name;\n });\n}\n"],"mappings":"AAAA,SACE,aAAa,EACb,MAAM,EACN,eAAe,QAEV,gBAAgB;AACvB,OAAO,aAAa,MAAM,gBAAgB;AAoB1C,OAAO,MAAM,mBAAmB,GAAG,aAAa,CAAsB,CAAC;AAEvE,OAAO,SAAS,yBAAyB,GAAwB;EAC/D,MAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,GAAG,CAAe,CAAC,CAAC;EACzD,MAAM,CAAC,MAAM,kBAAkB,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;EAC/C,OAAO;IAAE;EAAS,CAAC;AACrB;AAEA,SAAS,kBAAkB,CAAC,QAAwB,EAAE;EACpD;EACA,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,CAAC;EACnC,IAAI,MAAM,GAAG,KAAK;EAClB,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAE,OAAO,IAAK;IAC1C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,IAAI,MAAM,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,EAAE,KAAK,SAAS,EAAE;MACxD,MAAM,IAAI,KAAK,CACb,2FACF,CAAC;IACH;IACA,IAAI,IAAI,KAAK,SAAS,EAAE,MAAM,GAAG,IAAI;IACrC,OAAO,IAAI,KAAK,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;EAC5D,CAAC,CAAC;EACF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,MAAM,CAAE,EAAE,IAAK,EAAE,KAAK,SAAS,CAAC,CAAC;EAE/D,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAS,CAAC;EAClC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK;IAC/B,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE;IACrB,IAAI,EAAE,KAAK,SAAS,EAAE;IACtB,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,IAAK,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,EAAG,EAAE;MAC5D,MAAM,IAAI,KAAK,CAAC,kCAAkC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC;IAC1E;IACA,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;EAClB,CAAC,CAAC;EACF,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;EAEtC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK;IAC/B,IAAI,MAAM,GAAG,OAAO,CAAC,EAAE;IACvB,IAAI,MAAM,KAAK,SAAS,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,OAAO,CAAC,MAAM,EAAE;MACjE,MAAM,GAAG,SAAS;MAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,CAAC,EAAE;MAC7D,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC;IACjB;IACA,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,MAAM;IAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;IACrB,MAAM,IAAI,GAAG,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC;IACnC,IAAI,IAAI,KAAK,SAAS,EAAE;MACtB,MAAM,IAAI,KAAK,CACb,0EACF,CAAC;IACH;IACA,OAAO,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI;EAC5B,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ import { createContext, useContext } from "@alloy-js/core";
2
+
3
+ /** Whether inline Markdown is being rendered inside a table cell. */
4
+ export const TableContext = createContext(false);
5
+ export function useTableContext() {
6
+ return useContext(TableContext) === true;
7
+ }
8
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../../../src/context/table.ts"],"sourcesContent":["import { createContext, useContext } from \"@alloy-js/core\";\n\n/** Whether inline Markdown is being rendered inside a table cell. */\nexport const TableContext = createContext<boolean>(false);\n\nexport function useTableContext(): boolean {\n return useContext(TableContext) === true;\n}\n"],"mappings":"AAAA,SAAS,aAAa,EAAE,UAAU,QAAQ,gBAAgB;;AAE1D;AACA,OAAO,MAAM,YAAY,GAAG,aAAa,CAAU,KAAK,CAAC;AAEzD,OAAO,SAAS,eAAe,GAAY;EACzC,OAAO,UAAU,CAAC,YAAY,CAAC,KAAK,IAAI;AAC1C","ignoreList":[]}
@@ -0,0 +1,22 @@
1
+ import { createSymbol, OutputSymbol } from "@alloy-js/core";
2
+ export class HeadingSymbol extends OutputSymbol {
3
+ /** Path of the file declaring the heading. */
4
+ path;
5
+ /** Trimmed heading text, or `undefined` when the heading has JSX children. */
6
+ text;
7
+ constructor(name, spaces, options) {
8
+ super(name, spaces, options);
9
+ this.path = options.path;
10
+ this.text = options.text;
11
+ }
12
+ copy() {
13
+ const copy = createSymbol(HeadingSymbol, this.name, undefined, {
14
+ ...this.getCopyOptions(),
15
+ path: this.path,
16
+ text: this.text
17
+ });
18
+ this.initializeCopy(copy);
19
+ return copy;
20
+ }
21
+ }
22
+ //# sourceMappingURL=heading-symbol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../../../src/symbols/heading-symbol.ts"],"sourcesContent":["import {\n createSymbol,\n OutputSymbol,\n type OutputSpace,\n type OutputSymbolOptions,\n} from \"@alloy-js/core\";\n\nexport interface HeadingSymbolOptions extends OutputSymbolOptions {\n path: string;\n text: () => string | undefined;\n}\n\nexport class HeadingSymbol extends OutputSymbol {\n /** Path of the file declaring the heading. */\n readonly path: string;\n /** Trimmed heading text, or `undefined` when the heading has JSX children. */\n readonly text: () => string | undefined;\n\n constructor(\n name: string,\n spaces: OutputSpace | OutputSpace[] | undefined,\n options: HeadingSymbolOptions,\n ) {\n super(name, spaces, options);\n this.path = options.path;\n this.text = options.text;\n }\n\n copy() {\n const copy = createSymbol(HeadingSymbol, this.name, undefined, {\n ...this.getCopyOptions(),\n path: this.path,\n text: this.text,\n });\n this.initializeCopy(copy);\n return copy;\n }\n}\n"],"mappings":"AAAA,SACE,YAAY,EACZ,YAAY,QAGP,gBAAgB;AAOvB,OAAO,MAAM,aAAa,SAAS,YAAY,CAAC;EAC9C;EACS,IAAI;EACb;EACS,IAAI;EAEb,WAAW,CACT,IAAY,EACZ,MAA+C,EAC/C,OAA6B,EAC7B;IACA,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC;IAC5B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI;IACxB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI;EAC1B;EAEA,IAAI,GAAG;IACL,MAAM,IAAI,GAAG,YAAY,CAAC,aAAa,EAAE,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE;MAC7D,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;MACxB,IAAI,EAAE,IAAI,CAAC,IAAI;MACf,IAAI,EAAE,IAAI,CAAC;IACb,CAAC,CAAC;IACF,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;IACzB,OAAO,IAAI;EACb;AACF","ignoreList":[]}