@alloy-js/markdown 0.14.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.
Files changed (58) hide show
  1. package/LICENSE +7 -0
  2. package/api-extractor.json +4 -0
  3. package/dist/src/components/Heading.d.ts +9 -0
  4. package/dist/src/components/Heading.d.ts.map +1 -0
  5. package/dist/src/components/Heading.js +6 -0
  6. package/dist/src/components/Link.d.ts +11 -0
  7. package/dist/src/components/Link.d.ts.map +1 -0
  8. package/dist/src/components/Link.js +7 -0
  9. package/dist/src/components/List.d.ts +16 -0
  10. package/dist/src/components/List.d.ts.map +1 -0
  11. package/dist/src/components/List.js +26 -0
  12. package/dist/src/components/Section.d.ts +7 -0
  13. package/dist/src/components/Section.d.ts.map +1 -0
  14. package/dist/src/components/Section.js +32 -0
  15. package/dist/src/components/SourceFile.d.ts +7 -0
  16. package/dist/src/components/SourceFile.d.ts.map +1 -0
  17. package/dist/src/components/SourceFile.js +20 -0
  18. package/dist/src/components/index.d.ts +2 -0
  19. package/dist/src/components/index.d.ts.map +1 -0
  20. package/dist/src/components/index.js +0 -0
  21. package/dist/src/context/section.d.ts +7 -0
  22. package/dist/src/context/section.d.ts.map +1 -0
  23. package/dist/src/context/section.js +11 -0
  24. package/dist/src/index.d.ts +2 -0
  25. package/dist/src/index.d.ts.map +1 -0
  26. package/dist/src/index.js +1 -0
  27. package/dist/test/list.test.d.ts +2 -0
  28. package/dist/test/list.test.d.ts.map +1 -0
  29. package/dist/test/list.test.js +49 -0
  30. package/dist/test/paragraph.test.d.ts +2 -0
  31. package/dist/test/paragraph.test.d.ts.map +1 -0
  32. package/dist/test/paragraph.test.js +36 -0
  33. package/dist/test/section.test.d.ts +2 -0
  34. package/dist/test/section.test.d.ts.map +1 -0
  35. package/dist/test/section.test.js +61 -0
  36. package/dist/test/utils.d.ts +3 -0
  37. package/dist/test/utils.d.ts.map +1 -0
  38. package/dist/test/utils.js +13 -0
  39. package/dist/test/vitest.d.js +1 -0
  40. package/dist/tsconfig.tsbuildinfo +1 -0
  41. package/package.json +34 -0
  42. package/src/components/Heading.tsx +19 -0
  43. package/src/components/Link.tsx +24 -0
  44. package/src/components/List.tsx +50 -0
  45. package/src/components/Section.tsx +24 -0
  46. package/src/components/SourceFile.tsx +14 -0
  47. package/src/components/index.ts +0 -0
  48. package/src/context/section.ts +17 -0
  49. package/src/index.ts +1 -0
  50. package/temp/api.json +177 -0
  51. package/test/list.test.tsx +53 -0
  52. package/test/paragraph.test.tsx +42 -0
  53. package/test/section.test.tsx +55 -0
  54. package/test/utils.tsx +10 -0
  55. package/test/vitest.d.ts +16 -0
  56. package/tsconfig.json +11 -0
  57. package/tsdoc-metadata.json +11 -0
  58. package/vitest.config.ts +10 -0
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2024 Microsoft
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "../../api-extractor.base.json"
4
+ }
@@ -0,0 +1,9 @@
1
+ import { Refkey } from "@alloy-js/core";
2
+ import { Children } from "@alloy-js/core/jsx-runtime";
3
+ export interface HeadingProps {
4
+ level?: number;
5
+ children: Children;
6
+ refkey?: Refkey;
7
+ }
8
+ export declare function Heading(props: HeadingProps): Children;
9
+ //# sourceMappingURL=Heading.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Heading.d.ts","sourceRoot":"","sources":["../../../src/components/Heading.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAGtD,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,YAQ1C"}
@@ -0,0 +1,6 @@
1
+ import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { useSectionContext } from "../context/section.js";
3
+ export function Heading(props) {
4
+ const level = props.level !== undefined ? props.level : useSectionContext().level;
5
+ return [_$memo(() => "#".repeat(level)), " ", _$memo(() => props.children)];
6
+ }
@@ -0,0 +1,11 @@
1
+ import { Refkey } from "@alloy-js/core";
2
+ export interface LinkPropsWithRefkey {
3
+ refkey: Refkey;
4
+ }
5
+ export interface LinkPropsWithHref {
6
+ href: string;
7
+ title: string;
8
+ }
9
+ export type LinkProps = LinkPropsWithRefkey | LinkPropsWithHref;
10
+ export declare function Link(props: LinkProps): import("@alloy-js/core").Children;
11
+ //# sourceMappingURL=Link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../../src/components/Link.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,SAAS,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAEhE,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,qCAUpC"}
@@ -0,0 +1,7 @@
1
+ import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ export function Link(props) {
3
+ if ("refkey" in props) {
4
+ return "refkey";
5
+ }
6
+ return ["[", _$memo(() => props.title), "](", _$memo(() => props.href), ")"];
7
+ }
@@ -0,0 +1,16 @@
1
+ import { Children } from "@alloy-js/core/jsx-runtime";
2
+ export interface CommonListProps {
3
+ children: Children;
4
+ tasks?: boolean;
5
+ }
6
+ export interface OrderedListProps extends CommonListProps {
7
+ ordered: true;
8
+ start?: number;
9
+ }
10
+ export interface UnorderedListProps extends CommonListProps {
11
+ ordered?: false | undefined;
12
+ bullet?: "*" | "-" | "+";
13
+ }
14
+ export type ListProps = OrderedListProps | UnorderedListProps;
15
+ export declare function List(props: ListProps): Children;
16
+ //# sourceMappingURL=List.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../../src/components/List.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAQ,MAAM,4BAA4B,CAAC;AAE5D,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,OAAO,EAAE,IAAI,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,OAAO,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IAC5B,MAAM,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CAC1B;AAED,MAAM,MAAM,SAAS,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;AAE9D,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,YA6BpC"}
@@ -0,0 +1,26 @@
1
+ import { createComponent as _$createComponent, memo as _$memo, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { childrenArray, For } from "@alloy-js/core";
3
+ import { memo } from "@alloy-js/core/jsx-runtime";
4
+ export function List(props) {
5
+ const children = memo(() => {
6
+ return childrenArray(() => props.children, {
7
+ preserveFragments: true
8
+ }).filter(c => Boolean(c));
9
+ });
10
+ const start = props.start ?? 1;
11
+ return _$createComponent(For, {
12
+ each: children,
13
+ children: (child, index) => {
14
+ // sure would be great to align based on the number of digits for
15
+ // ordered lists, but GitHub has issues parsing them sometimes. This is
16
+ // much more reliable.
17
+ const alignSize = props.ordered ? 3 : 2;
18
+ return _$createIntrinsic("align", {
19
+ width: alignSize,
20
+ get children() {
21
+ return [_$memo(() => _$memo(() => !!props.ordered)() ? [index + start, "."] : props.bullet), " ", _$memo(() => props.tasks && "[ ] "), child];
22
+ }
23
+ });
24
+ }
25
+ });
26
+ }
@@ -0,0 +1,7 @@
1
+ import { Children } from "@alloy-js/core/jsx-runtime";
2
+ export interface SectionProps {
3
+ heading?: Children;
4
+ children: Children;
5
+ }
6
+ export declare function Section(props: SectionProps): Children;
7
+ //# sourceMappingURL=Section.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Section.d.ts","sourceRoot":"","sources":["../../../src/components/Section.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAItD,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,YAa1C"}
@@ -0,0 +1,32 @@
1
+ import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { List } from "@alloy-js/core";
3
+ import { SectionContext, useSectionContext } from "../context/section.js";
4
+ import { Heading } from "./Heading.js";
5
+ export function Section(props) {
6
+ const sectionContext = useSectionContext();
7
+ return _$createComponent(List, {
8
+ doubleHardline: true,
9
+ get children() {
10
+ return [_$memo(() => _$memo(() => !!props.heading)() && _$createComponent(Heading, {
11
+ get children() {
12
+ return props.heading;
13
+ }
14
+ })), _$createComponent(SectionContext.Provider, {
15
+ get value() {
16
+ return {
17
+ ...sectionContext,
18
+ level: sectionContext.level + 1
19
+ };
20
+ },
21
+ get children() {
22
+ return _$createComponent(List, {
23
+ doubleHardline: true,
24
+ get children() {
25
+ return props.children;
26
+ }
27
+ });
28
+ }
29
+ })];
30
+ }
31
+ });
32
+ }
@@ -0,0 +1,7 @@
1
+ import { Children } from "@alloy-js/core";
2
+ export interface SourceFileProps {
3
+ path: string;
4
+ children: Children;
5
+ }
6
+ export declare function SourceFile(props: SourceFileProps): Children;
7
+ //# sourceMappingURL=SourceFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SourceFile.d.ts","sourceRoot":"","sources":["../../../src/components/SourceFile.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsC,MAAM,gBAAgB,CAAC;AAG9E,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;CACpB;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,YAMhD"}
@@ -0,0 +1,20 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { SourceFile as CoreSourceFile, List } from "@alloy-js/core";
3
+ import { Link } from "./Link.js";
4
+ export function SourceFile(props) {
5
+ return _$createComponent(CoreSourceFile, {
6
+ get path() {
7
+ return props.path;
8
+ },
9
+ filetype: "md",
10
+ reference: Link,
11
+ get children() {
12
+ return _$createComponent(List, {
13
+ doubleHardline: true,
14
+ get children() {
15
+ return props.children;
16
+ }
17
+ });
18
+ }
19
+ });
20
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":""}
File without changes
@@ -0,0 +1,7 @@
1
+ import { ComponentContext } from "@alloy-js/core";
2
+ export interface SectionContext {
3
+ level: number;
4
+ }
5
+ export declare const SectionContext: ComponentContext<SectionContext>;
6
+ export declare function useSectionContext(): SectionContext;
7
+ //# sourceMappingURL=section.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"section.d.ts","sourceRoot":"","sources":["../../../src/context/section.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA6B,MAAM,gBAAgB,CAAC;AAE7E,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,cAAc,EAAE,gBAAgB,CAAC,cAAc,CACf,CAAC;AAE9C,wBAAgB,iBAAiB,IAAI,cAAc,CAOlD"}
@@ -0,0 +1,11 @@
1
+ import { createContext, useContext } from "@alloy-js/core";
2
+ export const SectionContext = createContext({
3
+ level: 1
4
+ });
5
+ export function useSectionContext() {
6
+ const context = useContext(SectionContext);
7
+ if (context === undefined) {
8
+ throw new Error("useSectionContext must be used within a Section");
9
+ }
10
+ return context;
11
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./components/index.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "./components/index.js";
@@ -0,0 +1,2 @@
1
+ import "@alloy-js/core/testing";
2
+ //# sourceMappingURL=list.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.test.d.ts","sourceRoot":"","sources":["../../test/list.test.tsx"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { createIntrinsic as _$createIntrinsic, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import "@alloy-js/core/testing";
3
+ import { d } from "@alloy-js/core/testing";
4
+ import { expect, it } from "vitest";
5
+ import { List } from "../src/components/List.js";
6
+ import { mdTest } from "./utils.js";
7
+ it("renders ordered lists", () => {
8
+ const template = mdTest(_$createComponent(List, {
9
+ ordered: true,
10
+ get children() {
11
+ return [["Item 1"], ["Item 2"], ["Item 3", _$createIntrinsic("hbr", {}), _$createComponent(List, {
12
+ ordered: true,
13
+ start: 10,
14
+ get children() {
15
+ return [["Item 3.1"], ["Item 3.2"]];
16
+ }
17
+ })]];
18
+ }
19
+ }));
20
+ expect(template).toRenderTo(d`
21
+ 1. Item 1
22
+ 2. Item 2
23
+ 3. Item 3
24
+ 10. Item 3.1
25
+ 11. Item 3.2
26
+ `);
27
+ });
28
+ it("renders task lists", () => {
29
+ const template = mdTest(_$createComponent(List, {
30
+ tasks: true,
31
+ bullet: "-",
32
+ get children() {
33
+ return [["Item 1"], ["Item 2"], ["Item 3", _$createIntrinsic("hbr", {}), _$createComponent(List, {
34
+ tasks: true,
35
+ ordered: true,
36
+ get children() {
37
+ return [["Item 3.1"], ["Item 3.2"]];
38
+ }
39
+ })]];
40
+ }
41
+ }));
42
+ expect(template).toRenderTo(d`
43
+ - [ ] Item 1
44
+ - [ ] Item 2
45
+ - [ ] Item 3
46
+ 1. [ ] Item 3.1
47
+ 2. [ ] Item 3.2
48
+ `);
49
+ });
@@ -0,0 +1,2 @@
1
+ import "@alloy-js/core/testing";
2
+ //# sourceMappingURL=paragraph.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paragraph.test.d.ts","sourceRoot":"","sources":["../../test/paragraph.test.tsx"],"names":[],"mappings":"AACA,OAAO,wBAAwB,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { Prose } from "@alloy-js/core";
3
+ import "@alloy-js/core/testing";
4
+ import { expect, it } from "vitest";
5
+ import { Section } from "../src/components/Section.js";
6
+ import { mdTest } from "./utils.js";
7
+ it("renders a section", () => {
8
+ const template = mdTest(_$createComponent(Section, {
9
+ heading: "hello",
10
+ get children() {
11
+ return [_$createComponent(Prose, {
12
+ children: "This is some text content that should be wrapped and such. We can put *italic* and **bold** text here, and it should be rendered correctly. We can also put in some code: `const x = 1;` and it should be rendered correctly. We can also put in some links: [Alloy](https://alloy-framework.github.io/alloy). It's pretty nice."
13
+ }), _$createComponent(Prose, {
14
+ children: "Subsequent paragraphs should have a blank line between them."
15
+ })];
16
+ }
17
+ }));
18
+ expect(template).toRenderTo(`
19
+ # hello
20
+
21
+ This is some text content that should be
22
+ wrapped and such. We can put *italic*
23
+ and **bold** text here, and it should be
24
+ rendered correctly. We can also put in
25
+ some code: \`const x = 1;\` and it should
26
+ be rendered correctly. We can also put
27
+ in some links:
28
+ [Alloy](https://alloy-framework.github.io/alloy).
29
+ It's pretty nice.
30
+
31
+ Subsequent paragraphs should have a
32
+ blank line between them.
33
+ `, {
34
+ printWidth: 40
35
+ });
36
+ });
@@ -0,0 +1,2 @@
1
+ import "@alloy-js/core/testing";
2
+ //# sourceMappingURL=section.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"section.test.d.ts","sourceRoot":"","sources":["../../test/section.test.tsx"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import "@alloy-js/core/testing";
3
+ import { expect, it } from "vitest";
4
+ import { Section } from "../src/components/Section.js";
5
+ import { mdTest } from "./utils.js";
6
+ it("renders a section", () => {
7
+ const template = mdTest([_$createComponent(Section, {
8
+ heading: "hello",
9
+ children: "world"
10
+ })]);
11
+ expect(template).toRenderTo(`
12
+ # hello
13
+
14
+ world
15
+ `);
16
+ });
17
+ it("renders multiple sections", () => {
18
+ const template = mdTest([_$createComponent(Section, {
19
+ heading: "hello",
20
+ children: "world"
21
+ }), _$createComponent(Section, {
22
+ heading: "hello",
23
+ children: "world"
24
+ })]);
25
+ expect(template).toRenderTo(`
26
+ # hello
27
+
28
+ world
29
+
30
+ # hello
31
+
32
+ world
33
+ `);
34
+ });
35
+ it("renders nested sections", () => {
36
+ const template = mdTest([_$createComponent(Section, {
37
+ heading: "hello",
38
+ get children() {
39
+ return ["world", _$createComponent(Section, {
40
+ heading: "subhello",
41
+ children: "subworld"
42
+ })];
43
+ }
44
+ }), _$createComponent(Section, {
45
+ heading: "hello",
46
+ children: "world"
47
+ })]);
48
+ expect(template).toRenderTo(`
49
+ # hello
50
+
51
+ world
52
+
53
+ ## subhello
54
+
55
+ subworld
56
+
57
+ # hello
58
+
59
+ world
60
+ `);
61
+ });
@@ -0,0 +1,3 @@
1
+ import { Children } from "@alloy-js/core";
2
+ export declare function mdTest(children: Children): Children;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../test/utils.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAU,MAAM,gBAAgB,CAAC;AAGlD,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,YAMxC"}
@@ -0,0 +1,13 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { Output } from "@alloy-js/core";
3
+ import { SourceFile } from "../src/components/SourceFile.js";
4
+ export function mdTest(children) {
5
+ return _$createComponent(Output, {
6
+ get children() {
7
+ return _$createComponent(SourceFile, {
8
+ path: "test.md",
9
+ children: children
10
+ });
11
+ }
12
+ });
13
+ }
@@ -0,0 +1 @@
1
+ import "vitest";