@foldkit/markdown 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +127 -0
- package/content.d.ts +4 -0
- package/dist/ast/ast.d.ts +322 -0
- package/dist/ast/ast.d.ts.map +1 -0
- package/dist/ast/ast.js +116 -0
- package/dist/ast/index.d.ts +2 -0
- package/dist/ast/index.d.ts.map +1 -0
- package/dist/ast/index.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/island/index.d.ts +2 -0
- package/dist/island/index.d.ts.map +1 -0
- package/dist/island/index.js +1 -0
- package/dist/island/island.d.ts +20 -0
- package/dist/island/island.d.ts.map +1 -0
- package/dist/island/island.js +1 -0
- package/dist/view/index.d.ts +2 -0
- package/dist/view/index.d.ts.map +1 -0
- package/dist/view/index.js +1 -0
- package/dist/view/view.d.ts +87 -0
- package/dist/view/view.d.ts.map +1 -0
- package/dist/view/view.js +164 -0
- package/dist/vite/normalize.d.ts +18 -0
- package/dist/vite/normalize.d.ts.map +1 -0
- package/dist/vite/normalize.js +157 -0
- package/dist/vite/public.d.ts +3 -0
- package/dist/vite/public.d.ts.map +1 -0
- package/dist/vite/public.js +1 -0
- package/dist/vite/vite.d.ts +19 -0
- package/dist/vite/vite.d.ts.map +1 -0
- package/dist/vite/vite.js +58 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Devin Jameson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# @foldkit/markdown
|
|
2
|
+
|
|
3
|
+
Markdown compiled at build time into typed Foldkit views, with live component islands.
|
|
4
|
+
|
|
5
|
+
A Vite plugin parses each imported `.md` file with remark, validates it against an Effect Schema vocabulary, and emits a typed document module. The browser receives data, never a parser. A pure fold renders the document as Foldkit `Html`, so markdown content participates in the vdom, DevTools, and time travel like any other view.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @foldkit/markdown
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
Add the plugin to `vite.config.ts`:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { markdown } from '@foldkit/markdown/vite'
|
|
19
|
+
|
|
20
|
+
export default defineConfig({
|
|
21
|
+
plugins: [tailwindcss(), foldkit(), markdown()],
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Type `.md` imports by adding the ambient declaration to your `tsconfig.json`:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"compilerOptions": {
|
|
30
|
+
"types": ["@foldkit/markdown/content"]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
If you run tests with Vitest, add `markdown()` with the same options to the `plugins` in `vitest.config.ts` as well, so test runs compile and validate `.md` imports exactly the way the app build does.
|
|
36
|
+
|
|
37
|
+
## Render a document
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import * as Markdown from '@foldkit/markdown'
|
|
41
|
+
|
|
42
|
+
import aboutRaw from './content/about.md'
|
|
43
|
+
|
|
44
|
+
const about = Markdown.decodeDocument(aboutRaw)
|
|
45
|
+
|
|
46
|
+
const view = (model: Model): Html => h.div([], [Markdown.view(about)])
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`Markdown.view` renders every node through unstyled semantic defaults. Restyle any node by overriding its view:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
Markdown.view(about, {
|
|
53
|
+
views: {
|
|
54
|
+
Paragraph: (paragraph, content) =>
|
|
55
|
+
h.p([h.Class('leading-relaxed text-stone-700')], content),
|
|
56
|
+
Link: ({ url }, content) =>
|
|
57
|
+
h.a([h.Href(url), h.Class('underline underline-offset-2')], content),
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`Markdown.viewBlocks` returns one `Html` per top-level block instead, for when the blocks should land directly inside your own container element.
|
|
63
|
+
|
|
64
|
+
## Islands
|
|
65
|
+
|
|
66
|
+
Directives reserve space in the prose for live application views. A leaf directive stands alone; a container directive wraps nested markdown:
|
|
67
|
+
|
|
68
|
+
```markdown
|
|
69
|
+
The count lives in the Model like everything else on this page.
|
|
70
|
+
|
|
71
|
+
::Counter{label="Clicks while reading"}
|
|
72
|
+
|
|
73
|
+
:::Note{tone="calm"}
|
|
74
|
+
Islands can wrap _markdown_ too.
|
|
75
|
+
:::
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Declare each island's attributes as a Schema struct, once, in a module both your Vite config and your views import:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
export const islandAttributes = {
|
|
82
|
+
Counter: S.Struct({ label: S.optionalKey(S.String) }),
|
|
83
|
+
Note: S.Struct({ tone: S.optionalKey(S.String) }),
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Pass the definitions to the plugin and every directive validates at build time. An unknown island name, an unknown attribute, or an attribute value outside its schema fails the build with the file and line:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
markdown({ islands: islandAttributes })
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`islandsFor` pairs the same definitions with typed views: attributes arrive decoded through each island's schema, and the record must cover every declared name. State stays in your Model; the markdown only decides placement. The third argument is the zero-based occurrence of that island name in the document, for identifiers that must be unique per instance, like an `h.submodel` slotId:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
Markdown.view(post, {
|
|
97
|
+
islands: Markdown.islandsFor(islandAttributes, {
|
|
98
|
+
Counter: ({ label }, _content, occurrenceIndex) =>
|
|
99
|
+
h.submodel({
|
|
100
|
+
slotId: `counter-${occurrenceIndex}`,
|
|
101
|
+
model: model.counter,
|
|
102
|
+
view: Counter.view,
|
|
103
|
+
toParentMessage: message => GotCounterMessage({ message }),
|
|
104
|
+
}),
|
|
105
|
+
Note: (_attributes, content) =>
|
|
106
|
+
h.aside([h.Class('rounded border p-4')], content),
|
|
107
|
+
}),
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Attribute values are strings on the wire, so transforming field schemas decode past them: `S.NumberFromString` turns `::Chart{height="240"}` into `height: number`. A plain `islands` record of untyped views (`Readonly<Record<string, IslandView>>`) also works when you want to skip the schemas.
|
|
112
|
+
|
|
113
|
+
## Vocabulary
|
|
114
|
+
|
|
115
|
+
The schema accepts CommonMark plus GFM tables and strikethrough: headings, paragraphs, emphasis, strong, strikethrough, inline code, links, images, hard breaks, nested lists, code blocks, blockquotes, thematic breaks, and tables. Directives (`::Name`, `:::Name`) become Island nodes.
|
|
116
|
+
|
|
117
|
+
Anything outside the vocabulary fails the build with an error naming the construct and its line. Raw HTML is rejected by design; islands are the escape hatch. Reference-style links, footnotes, task lists, YAML frontmatter, and directive labels (`::Name[label]`) are not supported; keep document metadata in application code. Link and image URLs must be relative or use the `http:`, `https:`, `mailto:`, or `tel:` schemes; executable schemes like `javascript:` fail the build.
|
|
118
|
+
|
|
119
|
+
## One-off compilation
|
|
120
|
+
|
|
121
|
+
`parseMarkdown` runs the same parse-and-validate pipeline outside Vite, for scripts and tests:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { parseMarkdown } from '@foldkit/markdown/vite'
|
|
125
|
+
|
|
126
|
+
const document = parseMarkdown('# Title', { islands: islandAttributes })
|
|
127
|
+
```
|
package/content.d.ts
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { Option, Schema as S } from 'effect';
|
|
2
|
+
import type { Array } from 'effect';
|
|
3
|
+
/** Plain text. */
|
|
4
|
+
export type Text = Readonly<{
|
|
5
|
+
_tag: 'Text';
|
|
6
|
+
value: string;
|
|
7
|
+
}>;
|
|
8
|
+
/** Inline code span. */
|
|
9
|
+
export type InlineCode = Readonly<{
|
|
10
|
+
_tag: 'InlineCode';
|
|
11
|
+
value: string;
|
|
12
|
+
}>;
|
|
13
|
+
/** Hard line break. */
|
|
14
|
+
export type HardBreak = Readonly<{
|
|
15
|
+
_tag: 'HardBreak';
|
|
16
|
+
}>;
|
|
17
|
+
/** Emphasized content, usually rendered as `em`. */
|
|
18
|
+
export type Emphasis = Readonly<{
|
|
19
|
+
_tag: 'Emphasis';
|
|
20
|
+
content: ReadonlyArray<Inline>;
|
|
21
|
+
}>;
|
|
22
|
+
/** Strongly emphasized content, usually rendered as `strong`. */
|
|
23
|
+
export type Strong = Readonly<{
|
|
24
|
+
_tag: 'Strong';
|
|
25
|
+
content: ReadonlyArray<Inline>;
|
|
26
|
+
}>;
|
|
27
|
+
/** Struck-through content, usually rendered as `del`. */
|
|
28
|
+
export type Strikethrough = Readonly<{
|
|
29
|
+
_tag: 'Strikethrough';
|
|
30
|
+
content: ReadonlyArray<Inline>;
|
|
31
|
+
}>;
|
|
32
|
+
/** Hyperlink with inline content. */
|
|
33
|
+
export type Link = Readonly<{
|
|
34
|
+
_tag: 'Link';
|
|
35
|
+
url: string;
|
|
36
|
+
maybeTitle: Option.Option<string>;
|
|
37
|
+
content: ReadonlyArray<Inline>;
|
|
38
|
+
}>;
|
|
39
|
+
/** Image with alt text. */
|
|
40
|
+
export type Image = Readonly<{
|
|
41
|
+
_tag: 'Image';
|
|
42
|
+
url: string;
|
|
43
|
+
alt: string;
|
|
44
|
+
maybeTitle: Option.Option<string>;
|
|
45
|
+
}>;
|
|
46
|
+
/** Any inline node. */
|
|
47
|
+
export type Inline = Text | InlineCode | HardBreak | Emphasis | Strong | Strikethrough | Link | Image;
|
|
48
|
+
/** The wire form of {@link Inline}, as emitted into compiled markdown modules. */
|
|
49
|
+
export type InlineEncoded = Readonly<{
|
|
50
|
+
_tag: 'Text';
|
|
51
|
+
value: string;
|
|
52
|
+
}> | Readonly<{
|
|
53
|
+
_tag: 'InlineCode';
|
|
54
|
+
value: string;
|
|
55
|
+
}> | Readonly<{
|
|
56
|
+
_tag: 'HardBreak';
|
|
57
|
+
}> | Readonly<{
|
|
58
|
+
_tag: 'Emphasis';
|
|
59
|
+
content: ReadonlyArray<InlineEncoded>;
|
|
60
|
+
}> | Readonly<{
|
|
61
|
+
_tag: 'Strong';
|
|
62
|
+
content: ReadonlyArray<InlineEncoded>;
|
|
63
|
+
}> | Readonly<{
|
|
64
|
+
_tag: 'Strikethrough';
|
|
65
|
+
content: ReadonlyArray<InlineEncoded>;
|
|
66
|
+
}> | Readonly<{
|
|
67
|
+
_tag: 'Link';
|
|
68
|
+
url: string;
|
|
69
|
+
maybeTitle: string | null | undefined;
|
|
70
|
+
content: ReadonlyArray<InlineEncoded>;
|
|
71
|
+
}> | Readonly<{
|
|
72
|
+
_tag: 'Image';
|
|
73
|
+
url: string;
|
|
74
|
+
alt: string;
|
|
75
|
+
maybeTitle: string | null | undefined;
|
|
76
|
+
}>;
|
|
77
|
+
/** Schema for {@link Text}. */
|
|
78
|
+
export declare const Text: import("foldkit/schema").CallableTaggedStruct<"Text", {
|
|
79
|
+
value: S.String;
|
|
80
|
+
}>;
|
|
81
|
+
/** Schema for {@link InlineCode}. */
|
|
82
|
+
export declare const InlineCode: import("foldkit/schema").CallableTaggedStruct<"InlineCode", {
|
|
83
|
+
value: S.String;
|
|
84
|
+
}>;
|
|
85
|
+
/** Schema for {@link HardBreak}. */
|
|
86
|
+
export declare const HardBreak: import("foldkit/schema").CallableTaggedStruct<"HardBreak", {}>;
|
|
87
|
+
/** Schema for {@link Inline}. */
|
|
88
|
+
export declare const Inline: S.Codec<Inline, InlineEncoded>;
|
|
89
|
+
/** Schema for {@link Emphasis}. */
|
|
90
|
+
export declare const Emphasis: import("foldkit/schema").CallableTaggedStruct<"Emphasis", {
|
|
91
|
+
content: S.$Array<S.Codec<Inline, InlineEncoded, never, never>>;
|
|
92
|
+
}>;
|
|
93
|
+
/** Schema for {@link Strong}. */
|
|
94
|
+
export declare const Strong: import("foldkit/schema").CallableTaggedStruct<"Strong", {
|
|
95
|
+
content: S.$Array<S.Codec<Inline, InlineEncoded, never, never>>;
|
|
96
|
+
}>;
|
|
97
|
+
/** Schema for {@link Strikethrough}. */
|
|
98
|
+
export declare const Strikethrough: import("foldkit/schema").CallableTaggedStruct<"Strikethrough", {
|
|
99
|
+
content: S.$Array<S.Codec<Inline, InlineEncoded, never, never>>;
|
|
100
|
+
}>;
|
|
101
|
+
/** Schema for {@link Link}. */
|
|
102
|
+
export declare const Link: import("foldkit/schema").CallableTaggedStruct<"Link", {
|
|
103
|
+
url: S.String;
|
|
104
|
+
maybeTitle: S.OptionFromNullishOr<S.String>;
|
|
105
|
+
content: S.$Array<S.Codec<Inline, InlineEncoded, never, never>>;
|
|
106
|
+
}>;
|
|
107
|
+
/** Schema for {@link Image}. */
|
|
108
|
+
export declare const Image: import("foldkit/schema").CallableTaggedStruct<"Image", {
|
|
109
|
+
url: S.String;
|
|
110
|
+
alt: S.String;
|
|
111
|
+
maybeTitle: S.OptionFromNullishOr<S.String>;
|
|
112
|
+
}>;
|
|
113
|
+
/** Heading depth, `1` through `6`. */
|
|
114
|
+
export declare const HeadingLevel: S.Literals<readonly [1, 2, 3, 4, 5, 6]>;
|
|
115
|
+
export type HeadingLevel = typeof HeadingLevel.Type;
|
|
116
|
+
/** Column alignment of a table, from the delimiter row of the source. */
|
|
117
|
+
export declare const Alignment: S.Literals<readonly ["None", "Left", "Center", "Right"]>;
|
|
118
|
+
export type Alignment = typeof Alignment.Type;
|
|
119
|
+
/** Section heading. */
|
|
120
|
+
export type Heading = Readonly<{
|
|
121
|
+
_tag: 'Heading';
|
|
122
|
+
level: HeadingLevel;
|
|
123
|
+
content: ReadonlyArray<Inline>;
|
|
124
|
+
}>;
|
|
125
|
+
/** Paragraph of inline content. */
|
|
126
|
+
export type Paragraph = Readonly<{
|
|
127
|
+
_tag: 'Paragraph';
|
|
128
|
+
content: ReadonlyArray<Inline>;
|
|
129
|
+
}>;
|
|
130
|
+
/** Fenced code block. `maybeMeta` carries everything after the language on the opening fence. */
|
|
131
|
+
export type CodeBlock = Readonly<{
|
|
132
|
+
_tag: 'CodeBlock';
|
|
133
|
+
maybeLanguage: Option.Option<string>;
|
|
134
|
+
maybeMeta: Option.Option<string>;
|
|
135
|
+
value: string;
|
|
136
|
+
}>;
|
|
137
|
+
/** Single list item holding block content, so lists nest. */
|
|
138
|
+
export type ListItem = Readonly<{
|
|
139
|
+
_tag: 'ListItem';
|
|
140
|
+
blocks: ReadonlyArray<Block>;
|
|
141
|
+
}>;
|
|
142
|
+
/** Ordered or unordered list. */
|
|
143
|
+
export type List = Readonly<{
|
|
144
|
+
_tag: 'List';
|
|
145
|
+
isOrdered: boolean;
|
|
146
|
+
maybeStartNumber: Option.Option<number>;
|
|
147
|
+
items: Array.NonEmptyReadonlyArray<ListItem>;
|
|
148
|
+
}>;
|
|
149
|
+
/** Block quotation holding block content. */
|
|
150
|
+
export type Blockquote = Readonly<{
|
|
151
|
+
_tag: 'Blockquote';
|
|
152
|
+
blocks: ReadonlyArray<Block>;
|
|
153
|
+
}>;
|
|
154
|
+
/** Thematic break, usually rendered as `hr`. */
|
|
155
|
+
export type ThematicBreak = Readonly<{
|
|
156
|
+
_tag: 'ThematicBreak';
|
|
157
|
+
}>;
|
|
158
|
+
/** Single table cell of inline content. */
|
|
159
|
+
export type TableCell = Readonly<{
|
|
160
|
+
_tag: 'TableCell';
|
|
161
|
+
content: ReadonlyArray<Inline>;
|
|
162
|
+
}>;
|
|
163
|
+
/** Single table row. */
|
|
164
|
+
export type TableRow = Readonly<{
|
|
165
|
+
_tag: 'TableRow';
|
|
166
|
+
cells: ReadonlyArray<TableCell>;
|
|
167
|
+
}>;
|
|
168
|
+
/** GFM table. The first source row is the header row. */
|
|
169
|
+
export type Table = Readonly<{
|
|
170
|
+
_tag: 'Table';
|
|
171
|
+
alignments: ReadonlyArray<Alignment>;
|
|
172
|
+
headerRow: TableRow;
|
|
173
|
+
bodyRows: ReadonlyArray<TableRow>;
|
|
174
|
+
}>;
|
|
175
|
+
/**
|
|
176
|
+
* Directive node reserved for live application views. A leaf directive
|
|
177
|
+
* (`::Name{attr="value"}`) has no blocks; a container directive
|
|
178
|
+
* (`:::Name` ... `:::`) carries its nested markdown as blocks.
|
|
179
|
+
*/
|
|
180
|
+
export type Island = Readonly<{
|
|
181
|
+
_tag: 'Island';
|
|
182
|
+
name: string;
|
|
183
|
+
attributes: Readonly<Record<string, string>>;
|
|
184
|
+
blocks: ReadonlyArray<Block>;
|
|
185
|
+
}>;
|
|
186
|
+
/** Any block node. */
|
|
187
|
+
export type Block = Heading | Paragraph | CodeBlock | List | Blockquote | ThematicBreak | Table | Island;
|
|
188
|
+
/** The wire form of {@link ListItem}. */
|
|
189
|
+
export type ListItemEncoded = Readonly<{
|
|
190
|
+
_tag: 'ListItem';
|
|
191
|
+
blocks: ReadonlyArray<BlockEncoded>;
|
|
192
|
+
}>;
|
|
193
|
+
/** The wire form of {@link TableCell}. */
|
|
194
|
+
export type TableCellEncoded = Readonly<{
|
|
195
|
+
_tag: 'TableCell';
|
|
196
|
+
content: ReadonlyArray<InlineEncoded>;
|
|
197
|
+
}>;
|
|
198
|
+
/** The wire form of {@link TableRow}. */
|
|
199
|
+
export type TableRowEncoded = Readonly<{
|
|
200
|
+
_tag: 'TableRow';
|
|
201
|
+
cells: ReadonlyArray<TableCellEncoded>;
|
|
202
|
+
}>;
|
|
203
|
+
/** The wire form of {@link Block}, as emitted into compiled markdown modules. */
|
|
204
|
+
export type BlockEncoded = Readonly<{
|
|
205
|
+
_tag: 'Heading';
|
|
206
|
+
level: HeadingLevel;
|
|
207
|
+
content: ReadonlyArray<InlineEncoded>;
|
|
208
|
+
}> | Readonly<{
|
|
209
|
+
_tag: 'Paragraph';
|
|
210
|
+
content: ReadonlyArray<InlineEncoded>;
|
|
211
|
+
}> | Readonly<{
|
|
212
|
+
_tag: 'CodeBlock';
|
|
213
|
+
maybeLanguage: string | null | undefined;
|
|
214
|
+
maybeMeta: string | null | undefined;
|
|
215
|
+
value: string;
|
|
216
|
+
}> | Readonly<{
|
|
217
|
+
_tag: 'List';
|
|
218
|
+
isOrdered: boolean;
|
|
219
|
+
maybeStartNumber: number | null | undefined;
|
|
220
|
+
items: Array.NonEmptyReadonlyArray<ListItemEncoded>;
|
|
221
|
+
}> | Readonly<{
|
|
222
|
+
_tag: 'Blockquote';
|
|
223
|
+
blocks: ReadonlyArray<BlockEncoded>;
|
|
224
|
+
}> | Readonly<{
|
|
225
|
+
_tag: 'ThematicBreak';
|
|
226
|
+
}> | Readonly<{
|
|
227
|
+
_tag: 'Table';
|
|
228
|
+
alignments: ReadonlyArray<Alignment>;
|
|
229
|
+
headerRow: TableRowEncoded;
|
|
230
|
+
bodyRows: ReadonlyArray<TableRowEncoded>;
|
|
231
|
+
}> | Readonly<{
|
|
232
|
+
_tag: 'Island';
|
|
233
|
+
name: string;
|
|
234
|
+
attributes: Readonly<Record<string, string>>;
|
|
235
|
+
blocks: ReadonlyArray<BlockEncoded>;
|
|
236
|
+
}>;
|
|
237
|
+
/** Schema for {@link Block}. */
|
|
238
|
+
export declare const Block: S.Codec<Block, BlockEncoded>;
|
|
239
|
+
/** Schema for {@link Heading}. */
|
|
240
|
+
export declare const Heading: import("foldkit/schema").CallableTaggedStruct<"Heading", {
|
|
241
|
+
level: S.Literals<readonly [1, 2, 3, 4, 5, 6]>;
|
|
242
|
+
content: S.$Array<S.Codec<Inline, InlineEncoded, never, never>>;
|
|
243
|
+
}>;
|
|
244
|
+
/** Schema for {@link Paragraph}. */
|
|
245
|
+
export declare const Paragraph: import("foldkit/schema").CallableTaggedStruct<"Paragraph", {
|
|
246
|
+
content: S.$Array<S.Codec<Inline, InlineEncoded, never, never>>;
|
|
247
|
+
}>;
|
|
248
|
+
/** Schema for {@link CodeBlock}. */
|
|
249
|
+
export declare const CodeBlock: import("foldkit/schema").CallableTaggedStruct<"CodeBlock", {
|
|
250
|
+
maybeLanguage: S.OptionFromNullishOr<S.String>;
|
|
251
|
+
maybeMeta: S.OptionFromNullishOr<S.String>;
|
|
252
|
+
value: S.String;
|
|
253
|
+
}>;
|
|
254
|
+
/** Schema for {@link ListItem}. */
|
|
255
|
+
export declare const ListItem: import("foldkit/schema").CallableTaggedStruct<"ListItem", {
|
|
256
|
+
blocks: S.$Array<S.Codec<Block, BlockEncoded, never, never>>;
|
|
257
|
+
}>;
|
|
258
|
+
/** Schema for {@link List}. */
|
|
259
|
+
export declare const List: import("foldkit/schema").CallableTaggedStruct<"List", {
|
|
260
|
+
isOrdered: S.Boolean;
|
|
261
|
+
maybeStartNumber: S.OptionFromNullishOr<S.Number>;
|
|
262
|
+
items: S.NonEmptyArray<import("foldkit/schema").CallableTaggedStruct<"ListItem", {
|
|
263
|
+
blocks: S.$Array<S.Codec<Block, BlockEncoded, never, never>>;
|
|
264
|
+
}>>;
|
|
265
|
+
}>;
|
|
266
|
+
/** Schema for {@link Blockquote}. */
|
|
267
|
+
export declare const Blockquote: import("foldkit/schema").CallableTaggedStruct<"Blockquote", {
|
|
268
|
+
blocks: S.$Array<S.Codec<Block, BlockEncoded, never, never>>;
|
|
269
|
+
}>;
|
|
270
|
+
/** Schema for {@link ThematicBreak}. */
|
|
271
|
+
export declare const ThematicBreak: import("foldkit/schema").CallableTaggedStruct<"ThematicBreak", {}>;
|
|
272
|
+
/** Schema for {@link TableCell}. */
|
|
273
|
+
export declare const TableCell: import("foldkit/schema").CallableTaggedStruct<"TableCell", {
|
|
274
|
+
content: S.$Array<S.Codec<Inline, InlineEncoded, never, never>>;
|
|
275
|
+
}>;
|
|
276
|
+
/** Schema for {@link TableRow}. */
|
|
277
|
+
export declare const TableRow: import("foldkit/schema").CallableTaggedStruct<"TableRow", {
|
|
278
|
+
cells: S.$Array<import("foldkit/schema").CallableTaggedStruct<"TableCell", {
|
|
279
|
+
content: S.$Array<S.Codec<Inline, InlineEncoded, never, never>>;
|
|
280
|
+
}>>;
|
|
281
|
+
}>;
|
|
282
|
+
/** Schema for {@link Table}. */
|
|
283
|
+
export declare const Table: import("foldkit/schema").CallableTaggedStruct<"Table", {
|
|
284
|
+
alignments: S.$Array<S.Literals<readonly ["None", "Left", "Center", "Right"]>>;
|
|
285
|
+
headerRow: import("foldkit/schema").CallableTaggedStruct<"TableRow", {
|
|
286
|
+
cells: S.$Array<import("foldkit/schema").CallableTaggedStruct<"TableCell", {
|
|
287
|
+
content: S.$Array<S.Codec<Inline, InlineEncoded, never, never>>;
|
|
288
|
+
}>>;
|
|
289
|
+
}>;
|
|
290
|
+
bodyRows: S.$Array<import("foldkit/schema").CallableTaggedStruct<"TableRow", {
|
|
291
|
+
cells: S.$Array<import("foldkit/schema").CallableTaggedStruct<"TableCell", {
|
|
292
|
+
content: S.$Array<S.Codec<Inline, InlineEncoded, never, never>>;
|
|
293
|
+
}>>;
|
|
294
|
+
}>>;
|
|
295
|
+
}>;
|
|
296
|
+
/** Schema for {@link Island}. */
|
|
297
|
+
export declare const Island: import("foldkit/schema").CallableTaggedStruct<"Island", {
|
|
298
|
+
name: S.String;
|
|
299
|
+
attributes: S.$Record<S.String, S.String>;
|
|
300
|
+
blocks: S.$Array<S.Codec<Block, BlockEncoded, never, never>>;
|
|
301
|
+
}>;
|
|
302
|
+
/** A compiled markdown document: the block sequence of one source file. */
|
|
303
|
+
export declare const MarkdownDocument: S.Struct<{
|
|
304
|
+
readonly blocks: S.$Array<S.Codec<Block, BlockEncoded, never, never>>;
|
|
305
|
+
}>;
|
|
306
|
+
export type MarkdownDocument = typeof MarkdownDocument.Type;
|
|
307
|
+
/** The wire form of {@link MarkdownDocument}. */
|
|
308
|
+
export type MarkdownDocumentEncoded = typeof MarkdownDocument.Encoded;
|
|
309
|
+
/**
|
|
310
|
+
* Decodes the default export of a compiled markdown module into a typed
|
|
311
|
+
* {@link MarkdownDocument}. Throws on input outside the markdown vocabulary.
|
|
312
|
+
*/
|
|
313
|
+
export declare const decodeDocument: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => S.Struct.ReadonlySide<{
|
|
314
|
+
readonly blocks: S.$Array<S.Codec<Block, BlockEncoded, never, never>>;
|
|
315
|
+
}, "Type">;
|
|
316
|
+
/** Encodes a {@link MarkdownDocument} into its JSON-safe wire form. */
|
|
317
|
+
export declare const encodeDocument: (input: S.Struct.ReadonlySide<{
|
|
318
|
+
readonly blocks: S.$Array<S.Codec<Block, BlockEncoded, never, never>>;
|
|
319
|
+
}, "Type">, options?: import("effect/SchemaAST").ParseOptions) => S.Struct.ReadonlySide<{
|
|
320
|
+
readonly blocks: S.$Array<S.Codec<Block, BlockEncoded, never, never>>;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** Schema for {@link Text}. */
|
|
4
|
+
export const Text = ts('Text', { value: S.String });
|
|
5
|
+
/** Schema for {@link InlineCode}. */
|
|
6
|
+
export const InlineCode = ts('InlineCode', { value: S.String });
|
|
7
|
+
/** Schema for {@link HardBreak}. */
|
|
8
|
+
export const HardBreak = ts('HardBreak');
|
|
9
|
+
// NOTE: Manual type definitions and the explicit annotation are required
|
|
10
|
+
// because TypeScript cannot infer types for self-recursive schemas built
|
|
11
|
+
// through S.suspend. Deriving the member types from their schemas instead
|
|
12
|
+
// (`type Emphasis = typeof Emphasis.Type`) recreates the circularity through
|
|
13
|
+
// the union alias and fails with TS2456, so the unions and their members stay
|
|
14
|
+
// hand-written.
|
|
15
|
+
/** Schema for {@link Inline}. */
|
|
16
|
+
export const Inline = S.suspend(() => S.Union([
|
|
17
|
+
Text,
|
|
18
|
+
InlineCode,
|
|
19
|
+
HardBreak,
|
|
20
|
+
Emphasis,
|
|
21
|
+
Strong,
|
|
22
|
+
Strikethrough,
|
|
23
|
+
Link,
|
|
24
|
+
Image,
|
|
25
|
+
]));
|
|
26
|
+
/** Schema for {@link Emphasis}. */
|
|
27
|
+
export const Emphasis = ts('Emphasis', { content: S.Array(Inline) });
|
|
28
|
+
/** Schema for {@link Strong}. */
|
|
29
|
+
export const Strong = ts('Strong', { content: S.Array(Inline) });
|
|
30
|
+
/** Schema for {@link Strikethrough}. */
|
|
31
|
+
export const Strikethrough = ts('Strikethrough', { content: S.Array(Inline) });
|
|
32
|
+
/** Schema for {@link Link}. */
|
|
33
|
+
export const Link = ts('Link', {
|
|
34
|
+
url: S.String,
|
|
35
|
+
maybeTitle: S.OptionFromNullishOr(S.String, { onNoneEncoding: null }),
|
|
36
|
+
content: S.Array(Inline),
|
|
37
|
+
});
|
|
38
|
+
/** Schema for {@link Image}. */
|
|
39
|
+
export const Image = ts('Image', {
|
|
40
|
+
url: S.String,
|
|
41
|
+
alt: S.String,
|
|
42
|
+
maybeTitle: S.OptionFromNullishOr(S.String, { onNoneEncoding: null }),
|
|
43
|
+
});
|
|
44
|
+
// BLOCK
|
|
45
|
+
/** Heading depth, `1` through `6`. */
|
|
46
|
+
export const HeadingLevel = S.Literals([1, 2, 3, 4, 5, 6]);
|
|
47
|
+
/** Column alignment of a table, from the delimiter row of the source. */
|
|
48
|
+
export const Alignment = S.Literals(['None', 'Left', 'Center', 'Right']);
|
|
49
|
+
// NOTE: Manual type definitions and the explicit annotation are required
|
|
50
|
+
// because TypeScript cannot infer types for self-recursive schemas built
|
|
51
|
+
// through S.suspend. Deriving the member types from their schemas instead
|
|
52
|
+
// (`type Emphasis = typeof Emphasis.Type`) recreates the circularity through
|
|
53
|
+
// the union alias and fails with TS2456, so the unions and their members stay
|
|
54
|
+
// hand-written.
|
|
55
|
+
/** Schema for {@link Block}. */
|
|
56
|
+
export const Block = S.suspend(() => S.Union([
|
|
57
|
+
Heading,
|
|
58
|
+
Paragraph,
|
|
59
|
+
CodeBlock,
|
|
60
|
+
List,
|
|
61
|
+
Blockquote,
|
|
62
|
+
ThematicBreak,
|
|
63
|
+
Table,
|
|
64
|
+
Island,
|
|
65
|
+
]));
|
|
66
|
+
/** Schema for {@link Heading}. */
|
|
67
|
+
export const Heading = ts('Heading', {
|
|
68
|
+
level: HeadingLevel,
|
|
69
|
+
content: S.Array(Inline),
|
|
70
|
+
});
|
|
71
|
+
/** Schema for {@link Paragraph}. */
|
|
72
|
+
export const Paragraph = ts('Paragraph', { content: S.Array(Inline) });
|
|
73
|
+
/** Schema for {@link CodeBlock}. */
|
|
74
|
+
export const CodeBlock = ts('CodeBlock', {
|
|
75
|
+
maybeLanguage: S.OptionFromNullishOr(S.String, { onNoneEncoding: null }),
|
|
76
|
+
maybeMeta: S.OptionFromNullishOr(S.String, { onNoneEncoding: null }),
|
|
77
|
+
value: S.String,
|
|
78
|
+
});
|
|
79
|
+
/** Schema for {@link ListItem}. */
|
|
80
|
+
export const ListItem = ts('ListItem', { blocks: S.Array(Block) });
|
|
81
|
+
/** Schema for {@link List}. */
|
|
82
|
+
export const List = ts('List', {
|
|
83
|
+
isOrdered: S.Boolean,
|
|
84
|
+
maybeStartNumber: S.OptionFromNullishOr(S.Number, { onNoneEncoding: null }),
|
|
85
|
+
items: S.NonEmptyArray(ListItem),
|
|
86
|
+
});
|
|
87
|
+
/** Schema for {@link Blockquote}. */
|
|
88
|
+
export const Blockquote = ts('Blockquote', { blocks: S.Array(Block) });
|
|
89
|
+
/** Schema for {@link ThematicBreak}. */
|
|
90
|
+
export const ThematicBreak = ts('ThematicBreak');
|
|
91
|
+
/** Schema for {@link TableCell}. */
|
|
92
|
+
export const TableCell = ts('TableCell', { content: S.Array(Inline) });
|
|
93
|
+
/** Schema for {@link TableRow}. */
|
|
94
|
+
export const TableRow = ts('TableRow', { cells: S.Array(TableCell) });
|
|
95
|
+
/** Schema for {@link Table}. */
|
|
96
|
+
export const Table = ts('Table', {
|
|
97
|
+
alignments: S.Array(Alignment),
|
|
98
|
+
headerRow: TableRow,
|
|
99
|
+
bodyRows: S.Array(TableRow),
|
|
100
|
+
});
|
|
101
|
+
/** Schema for {@link Island}. */
|
|
102
|
+
export const Island = ts('Island', {
|
|
103
|
+
name: S.String,
|
|
104
|
+
attributes: S.Record(S.String, S.String),
|
|
105
|
+
blocks: S.Array(Block),
|
|
106
|
+
});
|
|
107
|
+
// DOCUMENT
|
|
108
|
+
/** A compiled markdown document: the block sequence of one source file. */
|
|
109
|
+
export const MarkdownDocument = S.Struct({ blocks: S.Array(Block) });
|
|
110
|
+
/**
|
|
111
|
+
* Decodes the default export of a compiled markdown module into a typed
|
|
112
|
+
* {@link MarkdownDocument}. Throws on input outside the markdown vocabulary.
|
|
113
|
+
*/
|
|
114
|
+
export const decodeDocument = S.decodeUnknownSync(MarkdownDocument);
|
|
115
|
+
/** Encodes a {@link MarkdownDocument} into its JSON-safe wire form. */
|
|
116
|
+
export const encodeDocument = S.encodeSync(MarkdownDocument);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ast/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ast.js';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/island/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './island.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Schema as S } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Schema for one island's attributes: a struct that decodes the directive's
|
|
4
|
+
* string attributes into typed values. Use transforming field schemas to
|
|
5
|
+
* decode past strings, for example `S.NumberFromString` for numeric
|
|
6
|
+
* attributes.
|
|
7
|
+
*/
|
|
8
|
+
export type IslandDefinition = S.Struct<S.Struct.Fields> & Readonly<{
|
|
9
|
+
DecodingServices: never;
|
|
10
|
+
EncodingServices: never;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Attribute schemas by island directive name. One definition record serves
|
|
14
|
+
* both halves of the pipeline: the Vite plugin validates every directive
|
|
15
|
+
* against it at build time (unknown names, unknown attributes, and attribute
|
|
16
|
+
* values outside the schema all fail the build), and `islandsFor` decodes
|
|
17
|
+
* attributes with it before dispatching to the matching typed island view.
|
|
18
|
+
*/
|
|
19
|
+
export type IslandDefinitions = Readonly<Record<string, IslandDefinition>>;
|
|
20
|
+
//# sourceMappingURL=island.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"island.d.ts","sourceRoot":"","sources":["../../src/island/island.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAEpC;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GACtD,QAAQ,CAAC;IAAE,gBAAgB,EAAE,KAAK,CAAC;IAAC,gBAAgB,EAAE,KAAK,CAAA;CAAE,CAAC,CAAA;AAEhE;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAA"}
|