@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
@@ -1,6 +1,7 @@
1
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { List } from "@alloy-js/core";
3
- import { d } from "@alloy-js/core/testing";
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { List, ref } from "@alloy-js/core";
3
+ import { d, printTree, renderToString, renderTree } from "@alloy-js/core/testing";
4
+ import { marked } from "marked";
4
5
  import { expect, it } from "vitest";
5
6
  import { Code } from "../src/components/Code.js";
6
7
  import { mdTest } from "./utils.js";
@@ -34,4 +35,107 @@ it("renders with children", () => {
34
35
  \`\`\`
35
36
  `);
36
37
  });
38
+ it("omits an absent language instead of emitting undefined", () => {
39
+ const output = renderToString(_$createComponent(Code, {
40
+ children: "plain text"
41
+ }));
42
+ expect(output).toBe("```\nplain text\n```");
43
+ const tokens = marked.lexer(output);
44
+ expect(tokens).toHaveLength(1);
45
+ expect(tokens[0]).toMatchObject({
46
+ type: "code",
47
+ lang: "",
48
+ text: "plain text"
49
+ });
50
+ });
51
+ it.each(["before\n```\nafter", "before\n``````\nafter"])("keeps conflicting fences in a single parsed code block: %s", body => {
52
+ const output = renderToString(_$createComponent(Code, {
53
+ lang: "md",
54
+ children: body
55
+ }));
56
+ const tokens = marked.lexer(output);
57
+ expect(tokens).toHaveLength(1);
58
+ expect(tokens[0]).toMatchObject({
59
+ type: "code",
60
+ lang: "md",
61
+ text: body
62
+ });
63
+ });
64
+ it("updates fences when a direct string body changes", () => {
65
+ const body = ref("before\n```\nafter");
66
+ const tree = renderTree(_$createComponent(Code, {
67
+ lang: "md",
68
+ get children() {
69
+ return body.value;
70
+ }
71
+ }));
72
+ expect(printTree(tree)).toBe("````md\nbefore\n```\nafter\n````");
73
+ body.value = "before\n``````\nafter";
74
+ const tokens = marked.lexer(printTree(tree));
75
+ expect(tokens).toHaveLength(1);
76
+ expect(tokens[0]).toMatchObject({
77
+ type: "code",
78
+ lang: "md",
79
+ text: body.value
80
+ });
81
+ });
82
+ it("leaves JSX children unchanged without inspecting them for fence conflicts", () => {
83
+ const run = ref("``");
84
+ let renders = 0;
85
+ function Body() {
86
+ renders++;
87
+ return _$createComponent(List, {
88
+ get children() {
89
+ return ["before", [run, "`"], "after"];
90
+ }
91
+ });
92
+ }
93
+ const tree = renderTree(_$createComponent(Code, {
94
+ lang: "md",
95
+ get children() {
96
+ return _$createIntrinsic("group", {
97
+ get children() {
98
+ return _$createComponent(Body, {});
99
+ }
100
+ });
101
+ }
102
+ }));
103
+ expect(printTree(tree)).toBe("```md\nbefore\n```\nafter\n```");
104
+ run.value = "`````";
105
+ const output = printTree(tree);
106
+ expect(output).toBe("```md\nbefore\n``````\nafter\n```");
107
+ expect(renders).toBe(1);
108
+ });
109
+ it("preserves info strings containing backticks with safe tilde fences", () => {
110
+ const body = "before\n~~~\nafter\n";
111
+ const output = renderToString(_$createComponent(Code, {
112
+ lang: ' md title="`example`" ',
113
+ children: body
114
+ }));
115
+ expect(output).toBe('~~~~md title="`example`"\nbefore\n~~~\nafter\n\n~~~~');
116
+ const tokens = marked.lexer(output);
117
+ expect(tokens).toHaveLength(1);
118
+ expect(tokens[0]).toMatchObject({
119
+ type: "code",
120
+ lang: 'md title="`example`"',
121
+ text: body
122
+ });
123
+ });
124
+ it("preserves trailing blank lines in string bodies", () => {
125
+ const body = "first\nsecond\n\n";
126
+ const tokens = marked.lexer(renderToString(_$createComponent(Code, {
127
+ children: body
128
+ })));
129
+ expect(tokens).toHaveLength(1);
130
+ expect(tokens[0]).toMatchObject({
131
+ type: "code",
132
+ text: body
133
+ });
134
+ });
135
+ it.each(["md\ninjected", "md\r", "\nmd"])("rejects multiline info strings: %j", lang => {
136
+ expect(() => renderToString(_$createComponent(Code, {
137
+ lang: lang,
138
+ children: "body"
139
+ }))).toThrow("Code lang must be a single-line Markdown info string.");
140
+ });
37
141
  //# sourceMappingURL=Code.test.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../test/Code.test.tsx"],"sourcesContent":["import { List } from \"@alloy-js/core\";\nimport { d } from \"@alloy-js/core/testing\";\nimport { expect, it } from \"vitest\";\n\nimport { Code } from \"../src/components/Code.jsx\";\nimport { mdTest } from \"./utils.jsx\";\n\nit(\"renders with js value\", () => {\n const template = mdTest(\n <Code lang=\"ts\" children={\"const foo = 123;\\nconsole.log(foo);\"} />,\n );\n\n expect(template).toRenderTo(d`\n \\`\\`\\`ts\n const foo = 123;\n console.log(foo);\n \\`\\`\\`\n `);\n});\n\nit(\"renders with children\", () => {\n const template = mdTest(\n <Code lang=\"ts\">\n <List>\n <>const foo = 123;</>\n <>console.log(foo);</>\n </List>\n </Code>,\n );\n\n expect(template).toRenderTo(d`\n \\`\\`\\`ts\n const foo = 123;\n console.log(foo);\n \\`\\`\\`\n `);\n});\n"],"mappings":";AAAA,SAAS,IAAI,QAAQ,gBAAgB;AACrC,SAAS,CAAC,QAAQ,wBAAwB;AAC1C,SAAS,MAAM,EAAE,EAAE,QAAQ,QAAQ;AAEnC,SAAS,IAAI;AACb,SAAS,MAAM;AAEf,EAAE,CAAC,uBAAuB,EAAE,MAAM;EAChC,MAAM,QAAQ,GAAG,MAAM,mBACpB,IAAI;IAAC,IAAI;IAAM,QAAQ,EAAE;EAAqC,EACjE,CAAC;EAED,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC;AAC/B;AACA;AACA;AACA;AACA,GAAG,CAAC;AACJ,CAAC,CAAC;AAEF,EAAE,CAAC,uBAAuB,EAAE,MAAM;EAChC,MAAM,QAAQ,GAAG,MAAM,mBACpB,IAAI;IAAC,IAAI;IAAA;MAAA,yBACP,IAAI;QAAA;UAAA;QAAA;MAAA;IAAA;EAAA,EAKT,CAAC;EAED,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC;AAC/B;AACA;AACA;AACA;AACA,GAAG,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["../../test/Code.test.tsx"],"sourcesContent":["import { List, ref } from \"@alloy-js/core\";\nimport {\n d,\n printTree,\n renderToString,\n renderTree,\n} from \"@alloy-js/core/testing\";\nimport { marked } from \"marked\";\nimport { expect, it } from \"vitest\";\n\nimport { Code } from \"../src/components/Code.jsx\";\nimport { mdTest } from \"./utils.jsx\";\n\nit(\"renders with js value\", () => {\n const template = mdTest(\n <Code lang=\"ts\" children={\"const foo = 123;\\nconsole.log(foo);\"} />,\n );\n\n expect(template).toRenderTo(d`\n \\`\\`\\`ts\n const foo = 123;\n console.log(foo);\n \\`\\`\\`\n `);\n});\n\nit(\"renders with children\", () => {\n const template = mdTest(\n <Code lang=\"ts\">\n <List>\n <>const foo = 123;</>\n <>console.log(foo);</>\n </List>\n </Code>,\n );\n\n expect(template).toRenderTo(d`\n \\`\\`\\`ts\n const foo = 123;\n console.log(foo);\n \\`\\`\\`\n `);\n});\n\nit(\"omits an absent language instead of emitting undefined\", () => {\n const output = renderToString(<Code>plain text</Code>);\n expect(output).toBe(\"```\\nplain text\\n```\");\n const tokens = marked.lexer(output);\n expect(tokens).toHaveLength(1);\n expect(tokens[0]).toMatchObject({\n type: \"code\",\n lang: \"\",\n text: \"plain text\",\n });\n});\n\nit.each([\"before\\n```\\nafter\", \"before\\n``````\\nafter\"])(\n \"keeps conflicting fences in a single parsed code block: %s\",\n (body) => {\n const output = renderToString(<Code lang=\"md\">{body}</Code>);\n const tokens = marked.lexer(output);\n expect(tokens).toHaveLength(1);\n expect(tokens[0]).toMatchObject({ type: \"code\", lang: \"md\", text: body });\n },\n);\n\nit(\"updates fences when a direct string body changes\", () => {\n const body = ref(\"before\\n```\\nafter\");\n const tree = renderTree(<Code lang=\"md\">{body.value}</Code>);\n expect(printTree(tree)).toBe(\"````md\\nbefore\\n```\\nafter\\n````\");\n body.value = \"before\\n``````\\nafter\";\n const tokens = marked.lexer(printTree(tree));\n expect(tokens).toHaveLength(1);\n expect(tokens[0]).toMatchObject({\n type: \"code\",\n lang: \"md\",\n text: body.value,\n });\n});\n\nit(\"leaves JSX children unchanged without inspecting them for fence conflicts\", () => {\n const run = ref(\"``\");\n let renders = 0;\n function Body() {\n renders++;\n return (\n <List>\n before\n <>{run}`</>\n after\n </List>\n );\n }\n const tree = renderTree(\n <Code lang=\"md\">\n <group>\n <Body />\n </group>\n </Code>,\n );\n expect(printTree(tree)).toBe(\"```md\\nbefore\\n```\\nafter\\n```\");\n run.value = \"`````\";\n const output = printTree(tree);\n expect(output).toBe(\"```md\\nbefore\\n``````\\nafter\\n```\");\n expect(renders).toBe(1);\n});\n\nit(\"preserves info strings containing backticks with safe tilde fences\", () => {\n const body = \"before\\n~~~\\nafter\\n\";\n const output = renderToString(\n <Code lang={' md title=\"`example`\" '}>{body}</Code>,\n );\n expect(output).toBe('~~~~md title=\"`example`\"\\nbefore\\n~~~\\nafter\\n\\n~~~~');\n const tokens = marked.lexer(output);\n expect(tokens).toHaveLength(1);\n expect(tokens[0]).toMatchObject({\n type: \"code\",\n lang: 'md title=\"`example`\"',\n text: body,\n });\n});\n\nit(\"preserves trailing blank lines in string bodies\", () => {\n const body = \"first\\nsecond\\n\\n\";\n const tokens = marked.lexer(renderToString(<Code>{body}</Code>));\n expect(tokens).toHaveLength(1);\n expect(tokens[0]).toMatchObject({ type: \"code\", text: body });\n});\n\nit.each([\"md\\ninjected\", \"md\\r\", \"\\nmd\"])(\n \"rejects multiline info strings: %j\",\n (lang) => {\n expect(() => renderToString(<Code lang={lang}>body</Code>)).toThrow(\n \"Code lang must be a single-line Markdown info string.\",\n );\n },\n);\n"],"mappings":";AAAA,SAAS,IAAI,EAAE,GAAG,QAAQ,gBAAgB;AAC1C,SACE,CAAC,EACD,SAAS,EACT,cAAc,EACd,UAAU,QACL,wBAAwB;AAC/B,SAAS,MAAM,QAAQ,QAAQ;AAC/B,SAAS,MAAM,EAAE,EAAE,QAAQ,QAAQ;AAEnC,SAAS,IAAI;AACb,SAAS,MAAM;AAEf,EAAE,CAAC,uBAAuB,EAAE,MAAM;EAChC,MAAM,QAAQ,GAAG,MAAM,mBACpB,IAAI;IAAC,IAAI;IAAM,QAAQ,EAAE;EAAqC,EACjE,CAAC;EAED,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC;AAC/B;AACA;AACA;AACA;AACA,GAAG,CAAC;AACJ,CAAC,CAAC;AAEF,EAAE,CAAC,uBAAuB,EAAE,MAAM;EAChC,MAAM,QAAQ,GAAG,MAAM,mBACpB,IAAI;IAAC,IAAI;IAAA;MAAA,yBACP,IAAI;QAAA;UAAA;QAAA;MAAA;IAAA;EAAA,EAKT,CAAC;EAED,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC;AAC/B;AACA;AACA;AACA;AACA,GAAG,C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,CAAC,IAAI,CAAC,sDAAsD,CAAC;EAC3E,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;EACnC,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;EAC9B,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;IAC9B,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,sBAAsB;IAC5B,IAAI,EAAE;EACR,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,EAAE,CAAC,iDAAiD,EAAE,MAAM;EAC1D,MAAM,IAAI,GAAG,mBAAmB;EAChC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,cAAc,mBAAE,IAAI;IAAA,UAAE;EAAI,EAAQ,CAAC,CAAC;EAChE,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;EAC9B,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM;IAAE,IAAI,EAAE;EAAK,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF,EAAE,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CACvC,oCAAoC,EACnC,IAAI,IAAK;EACR,MAAM,CAAC,MAAM,cAAc,mBAAE,IAAI;IAAC,IAAI,EAAE,IAAI;IAAA;EAAA,EAAa,CAAC,CAAC,CAAC,OAAO,CACjE,uDACF,CAAC;AACH,CACF,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=heading.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heading.test.d.ts","sourceRoot":"","sources":["../../test/heading.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,494 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { getDiagnosticsForTree, Output, printTree, ref, refkey, renderTree, SourceDirectory, Show } from "@alloy-js/core";
3
+ import { PackageDirectory } from "@alloy-js/typescript";
4
+ import { expect, it } from "vitest";
5
+ import { TableContext } from "../src/context/table.js";
6
+ import { Heading, InlineCode, Link, Section, SourceFile } from "../src/index.js";
7
+ import { mdTest } from "./utils.js";
8
+ it("renders Markdown files inside a TypeScript package directory", () => {
9
+ const key = refkey();
10
+ expect(_$createComponent(Output, {
11
+ get children() {
12
+ return _$createComponent(PackageDirectory, {
13
+ name: "example",
14
+ path: "example",
15
+ version: "1.0.0",
16
+ get children() {
17
+ return [_$createComponent(SourceFile, {
18
+ path: "README.md",
19
+ children: "Plain README"
20
+ }), _$createComponent(SourceFile, {
21
+ path: "guide.md",
22
+ get children() {
23
+ return _$createComponent(Heading, {
24
+ refkey: key,
25
+ children: "Guide"
26
+ });
27
+ }
28
+ }), _$createComponent(SourceFile, {
29
+ path: "index.md",
30
+ children: key
31
+ })];
32
+ }
33
+ });
34
+ }
35
+ })).toRenderTo({
36
+ "example/README.md": "Plain README",
37
+ "example/guide.md": "# Guide",
38
+ "example/index.md": "[Guide](guide.md#guide)",
39
+ "example/package.json": expect.anything(),
40
+ "example/tsconfig.json": expect.anything()
41
+ });
42
+ });
43
+ it("requires explicit IDs for references after opaque heading children", () => {
44
+ const key = refkey();
45
+ expect(() => renderTree(mdTest([_$createComponent(Heading, {
46
+ id: "code-api",
47
+ get children() {
48
+ return _$createComponent(InlineCode, {
49
+ children: "API"
50
+ });
51
+ }
52
+ }), _$createComponent(Heading, {
53
+ refkey: key,
54
+ children: "API"
55
+ }), key]))).toThrow("requires an explicit id after a heading with non-string children");
56
+ expect(mdTest([_$createComponent(Heading, {
57
+ id: "code-api",
58
+ get children() {
59
+ return _$createComponent(InlineCode, {
60
+ children: "API"
61
+ });
62
+ }
63
+ }), _$createComponent(Heading, {
64
+ refkey: key,
65
+ id: "plain-api",
66
+ children: "API"
67
+ }), key])).toRenderTo(`
68
+ <a id="code-api"></a>
69
+
70
+ # \`API\`
71
+
72
+ <a id="plain-api"></a>
73
+
74
+ # API
75
+
76
+ [API](#plain-api)
77
+ `);
78
+ });
79
+ it("updates explicit heading IDs and their references reactively", () => {
80
+ const anchor = ref("old");
81
+ const key = refkey();
82
+ const tree = renderTree(mdTest([_$createComponent(Heading, {
83
+ refkey: key,
84
+ get id() {
85
+ return anchor.value;
86
+ },
87
+ children: "Title"
88
+ }), key]));
89
+ expect(printTree(tree)).toBe('<a id="old"></a>\n\n# Title\n\n[Title](#old)');
90
+ anchor.value = "new";
91
+ expect(printTree(tree)).toBe('<a id="new"></a>\n\n# Title\n\n[Title](#new)');
92
+ });
93
+ it("validates reactive heading IDs", () => {
94
+ const anchor = ref("valid");
95
+ const tree = renderTree(mdTest([_$createComponent(Heading, {
96
+ get id() {
97
+ return anchor.value;
98
+ },
99
+ children: "Title"
100
+ })]));
101
+ expect(() => {
102
+ anchor.value = 'bad"id';
103
+ printTree(tree);
104
+ }).toThrow("Invalid Markdown heading ID");
105
+ });
106
+ it("rejects collisions introduced by a reactive heading ID", () => {
107
+ const anchor = ref("old");
108
+ const tree = renderTree(mdTest([_$createComponent(Heading, {
109
+ get id() {
110
+ return anchor.value;
111
+ },
112
+ children: "First"
113
+ }), _$createComponent(Heading, {
114
+ children: "Second"
115
+ })]));
116
+ expect(() => {
117
+ anchor.value = "second";
118
+ printTree(tree);
119
+ }).toThrow("Duplicate Markdown heading ID");
120
+ });
121
+ it("updates selected link refkeys and unresolved diagnostics reactively", () => {
122
+ const first = refkey();
123
+ const second = refkey();
124
+ const missing = refkey("missing-selected-heading");
125
+ const selected = ref(first);
126
+ const tree = renderTree(mdTest([_$createComponent(Heading, {
127
+ refkey: first,
128
+ children: "First"
129
+ }), _$createComponent(Heading, {
130
+ refkey: second,
131
+ children: "Second"
132
+ }), _$createComponent(Link, {
133
+ get refkey() {
134
+ return selected.value;
135
+ }
136
+ })]));
137
+ expect(printTree(tree)).toBe("# First\n\n# Second\n\n[First](#first)");
138
+ selected.value = second;
139
+ expect(printTree(tree)).toBe("# First\n\n# Second\n\n[Second](#second)");
140
+ expect(getDiagnosticsForTree(tree)).toEqual([]);
141
+ selected.value = missing;
142
+ expect(printTree(tree)).toBe("# First\n\n# Second\n\n<Unresolved Symbol: refkey[smissing-selected-heading]>");
143
+ expect(getDiagnosticsForTree(tree)).toMatchObject([{
144
+ severity: "warning",
145
+ message: "Unresolved refkey: refkey[smissing-selected-heading]"
146
+ }]);
147
+ selected.value = first;
148
+ expect(printTree(tree)).toBe("# First\n\n# Second\n\n[First](#first)");
149
+ expect(getDiagnosticsForTree(tree)).toEqual([]);
150
+ });
151
+ it("resolves forward and backward references in the same file", () => {
152
+ const key = refkey();
153
+ const template = mdTest([_$createComponent(Link, {
154
+ refkey: key
155
+ }), _$createComponent(Heading, {
156
+ refkey: key,
157
+ children: "Hello world!"
158
+ }), key, _$createComponent(Link, {
159
+ refkey: key,
160
+ title: "Back to top"
161
+ })]);
162
+ expect(template).toRenderTo(`
163
+ [Hello world!](#hello-world)
164
+
165
+ # Hello world!
166
+
167
+ [Hello world!](#hello-world)
168
+
169
+ [Back to top](#hello-world)
170
+ `);
171
+ expect(getDiagnosticsForTree(renderTree(template))).toEqual([]);
172
+ });
173
+ it("resolves relative links across directories and encodes paths and fragments", () => {
174
+ const first = refkey();
175
+ const second = refkey();
176
+ const template = _$createComponent(Output, {
177
+ get children() {
178
+ return [_$createComponent(SourceDirectory, {
179
+ path: "guide",
180
+ get children() {
181
+ return _$createComponent(SourceFile, {
182
+ path: "intro.md",
183
+ get children() {
184
+ return [_$createComponent(Heading, {
185
+ refkey: first,
186
+ children: "Introduction"
187
+ }), second];
188
+ }
189
+ });
190
+ }
191
+ }), _$createComponent(SourceDirectory, {
192
+ path: "reference",
193
+ get children() {
194
+ return _$createComponent(SourceFile, {
195
+ path: "API types).md",
196
+ get children() {
197
+ return [_$createComponent(Heading, {
198
+ refkey: second,
199
+ children: "Café"
200
+ }), first];
201
+ }
202
+ });
203
+ }
204
+ })];
205
+ }
206
+ });
207
+ expect(template).toRenderTo({
208
+ "guide/intro.md": "# Introduction\n\n[Café](../reference/API%20types%29.md#caf%C3%A9)",
209
+ "reference/API types).md": "# Café\n\n[Introduction](../guide/intro.md#introduction)"
210
+ });
211
+ expect(getDiagnosticsForTree(renderTree(template))).toEqual([]);
212
+ });
213
+ it("counts unreferenced and nested section headings when deconflicting slugs", () => {
214
+ const second = refkey();
215
+ const third = refkey();
216
+ expect(mdTest([_$createComponent(Section, {
217
+ heading: "Hello",
218
+ children: "Body"
219
+ }), _$createComponent(Heading, {
220
+ refkey: second,
221
+ children: "Hello"
222
+ }), _$createComponent(Heading, {
223
+ children: "Hello-1"
224
+ }), _$createComponent(Heading, {
225
+ refkey: third,
226
+ children: "Hello"
227
+ }), second, third])).toRenderTo(`
228
+ # Hello
229
+
230
+ Body
231
+
232
+ # Hello
233
+
234
+ # Hello-1
235
+
236
+ # Hello
237
+
238
+ [Hello](#hello-1)
239
+
240
+ [Hello](#hello-2)
241
+ `);
242
+ });
243
+ it("uses explicit IDs independently of heading text", () => {
244
+ const key = refkey();
245
+ expect(mdTest([_$createComponent(Link, {
246
+ refkey: key
247
+ }), _$createComponent(Heading, {
248
+ refkey: key,
249
+ id: "stable-api",
250
+ children: "New display name"
251
+ })])).toRenderTo(`
252
+ [New display name](#stable-api)
253
+
254
+ <a id="stable-api"></a>
255
+
256
+ # New display name
257
+ `);
258
+ });
259
+ it("keeps heading ID allocation local to each file", () => {
260
+ const key = refkey();
261
+ expect(_$createComponent(Output, {
262
+ get children() {
263
+ return [_$createComponent(SourceFile, {
264
+ path: "one.md",
265
+ get children() {
266
+ return [_$createComponent(Heading, {
267
+ children: "Same"
268
+ }), key];
269
+ }
270
+ }), _$createComponent(SourceFile, {
271
+ path: "two.md",
272
+ get children() {
273
+ return _$createComponent(Heading, {
274
+ refkey: key,
275
+ children: "Same"
276
+ });
277
+ }
278
+ })];
279
+ }
280
+ })).toRenderTo({
281
+ "one.md": "# Same\n\n[Same](two.md#same)",
282
+ "two.md": "# Same"
283
+ });
284
+ });
285
+ it("reports unresolved refkeys using core diagnostics", () => {
286
+ const key = refkey("missing-heading");
287
+ const tree = renderTree(mdTest([_$createComponent(Link, {
288
+ refkey: key
289
+ })]));
290
+ expect(tree).toRenderTo("<Unresolved Symbol: refkey[smissing-heading]>");
291
+ expect(getDiagnosticsForTree(tree)).toMatchObject([{
292
+ severity: "warning",
293
+ message: "Unresolved refkey: refkey[smissing-heading]"
294
+ }]);
295
+ });
296
+ it.each(["", 'bad"id'])("rejects an invalid explicit heading ID %j", id => {
297
+ expect(() => renderTree(mdTest([_$createComponent(Heading, {
298
+ id: id,
299
+ children: "Title"
300
+ })]))).toThrow("Invalid Markdown heading ID");
301
+ });
302
+ it("provides an explicit anchor when the automatic slug would be empty", () => {
303
+ const key = refkey();
304
+ expect(mdTest([_$createComponent(Heading, {
305
+ refkey: key,
306
+ children: "!!!"
307
+ }), key])).toRenderTo(`
308
+ <a id="section"></a>
309
+
310
+ # !!!
311
+
312
+ [!!!](#section)
313
+ `);
314
+ });
315
+ it("rejects colliding explicit and automatic IDs", () => {
316
+ expect(() => renderTree(mdTest([_$createComponent(Heading, {
317
+ id: "second",
318
+ children: "First"
319
+ }), _$createComponent(Heading, {
320
+ children: "Second"
321
+ })]))).toThrow("Duplicate Markdown heading ID");
322
+ });
323
+ it("preserves direct href links", () => {
324
+ expect(mdTest([_$createComponent(Link, {
325
+ href: "https://example.com",
326
+ title: "Example"
327
+ })])).toRenderTo("[Example](https://example.com)");
328
+ });
329
+ it("trims heading text and escapes the default link label", () => {
330
+ const name = "";
331
+ const key = refkey();
332
+ const path = refkey();
333
+ expect(mdTest([_$createComponent(Heading, {
334
+ refkey: key,
335
+ get children() {
336
+ return ["Model ", name];
337
+ }
338
+ }), _$createComponent(Heading, {
339
+ refkey: path,
340
+ children: "Use ~/config_file"
341
+ }), key, path])).toRenderTo(`
342
+ # Model
343
+
344
+ # Use ~/config_file
345
+
346
+ [Model](#model)
347
+
348
+ [Use \\~/config\\_file](#use-config_file)
349
+ `);
350
+ });
351
+ it("requires an explicit ID to reference a heading with JSX children", () => {
352
+ const key = refkey();
353
+ expect(() => renderTree(mdTest([_$createComponent(Heading, {
354
+ refkey: key,
355
+ get children() {
356
+ return ["Use ", _$createComponent(InlineCode, {
357
+ children: "Foo"
358
+ })];
359
+ }
360
+ })]))).toThrow("requires an explicit id");
361
+ });
362
+ it("renders JSX heading children once and links to their explicit ID", () => {
363
+ const key = refkey();
364
+ let calls = 0;
365
+ function Name() {
366
+ calls++;
367
+ return _$createComponent(InlineCode, {
368
+ children: "Foo"
369
+ });
370
+ }
371
+ expect(mdTest([_$createComponent(Heading, {
372
+ refkey: key,
373
+ id: "foo",
374
+ get children() {
375
+ return ["Use ", _$createComponent(Name, {})];
376
+ }
377
+ }), _$createComponent(Link, {
378
+ refkey: key,
379
+ title: "Foo"
380
+ })])).toRenderTo(`
381
+ <a id="foo"></a>
382
+
383
+ # Use \`Foo\`
384
+
385
+ [Foo](#foo)
386
+ `);
387
+ expect(calls).toBe(1);
388
+ expect(() => renderTree(mdTest([_$createComponent(Heading, {
389
+ refkey: key,
390
+ id: "foo",
391
+ get children() {
392
+ return _$createComponent(InlineCode, {
393
+ children: "Foo"
394
+ });
395
+ }
396
+ }), key]))).toThrow("requires a title");
397
+ });
398
+ it("updates a reactive heading and its reference label and slug", () => {
399
+ const name = ref("Alpha");
400
+ const key = refkey();
401
+ const tree = renderTree(mdTest([_$createComponent(Heading, {
402
+ refkey: key,
403
+ get children() {
404
+ return name.value;
405
+ }
406
+ }), key]));
407
+ expect(printTree(tree)).toBe("# Alpha\n\n[Alpha](#alpha)");
408
+ name.value = "Beta";
409
+ expect(printTree(tree)).toBe("# Beta\n\n[Beta](#beta)");
410
+ });
411
+ it("reclaims duplicate suffixes when an earlier heading is removed", () => {
412
+ const show = ref(true);
413
+ const key = refkey();
414
+ const tree = renderTree(mdTest([_$createComponent(Show, {
415
+ get when() {
416
+ return show.value;
417
+ },
418
+ get children() {
419
+ return _$createComponent(Heading, {
420
+ children: "Hello"
421
+ });
422
+ }
423
+ }), _$createComponent(Heading, {
424
+ refkey: key,
425
+ children: "Hello"
426
+ }), key]));
427
+ expect(printTree(tree)).toBe("# Hello\n\n# Hello\n\n[Hello](#hello-1)");
428
+ show.value = false;
429
+ expect(printTree(tree)).toBe("# Hello\n\n[Hello](#hello)");
430
+ });
431
+ it("forgets removed headings when the only heading remounts", () => {
432
+ const show = ref(true);
433
+ const key = refkey();
434
+ const tree = renderTree(mdTest([_$createComponent(Show, {
435
+ get when() {
436
+ return show.value;
437
+ },
438
+ get children() {
439
+ return [_$createComponent(Heading, {
440
+ refkey: key,
441
+ children: "Hello"
442
+ }), _$createIntrinsic("hbr", {}), _$createIntrinsic("hbr", {}), key];
443
+ }
444
+ })]));
445
+ expect(printTree(tree)).toBe("# Hello\n\n[Hello](#hello)");
446
+ show.value = false;
447
+ expect(printTree(tree)).toBe("");
448
+ show.value = true;
449
+ expect(printTree(tree)).toBe("# Hello\n\n[Hello](#hello)");
450
+ });
451
+ it("allocates punctuation fallback IDs after automatic IDs", () => {
452
+ const empty = refkey();
453
+ const key = refkey();
454
+ expect(mdTest([_$createComponent(Heading, {
455
+ refkey: empty,
456
+ children: "!!!"
457
+ }), _$createComponent(Heading, {
458
+ refkey: key,
459
+ children: "Section"
460
+ }), empty, key])).toRenderTo(`
461
+ <a id="section-1"></a>
462
+
463
+ # !!!
464
+
465
+ # Section
466
+
467
+ [!!!](#section-1)
468
+
469
+ [Section](#section)
470
+ `);
471
+ });
472
+ it("escapes default label pipes only in a table cell context", () => {
473
+ const key = refkey();
474
+ expect(mdTest([_$createComponent(Heading, {
475
+ refkey: key,
476
+ children: "A | B"
477
+ }), _$createComponent(TableContext.Provider, {
478
+ value: true,
479
+ get children() {
480
+ return _$createComponent(Link, {
481
+ refkey: key
482
+ });
483
+ }
484
+ }), _$createComponent(Link, {
485
+ refkey: key
486
+ })])).toRenderTo(`
487
+ # A | B
488
+
489
+ [A \\| B](#a--b)
490
+
491
+ [A | B](#a--b)
492
+ `);
493
+ });
494
+ //# sourceMappingURL=heading.test.js.map