flatmarkdown-ast2html 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -8
- package/dist/index.d.cts +4 -212
- package/dist/index.d.ts +4 -212
- package/dist/index.global.js +32 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -12,6 +12,31 @@ bun add flatmarkdown-ast2html
|
|
|
12
12
|
npm install flatmarkdown-ast2html
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## Browser / WebView (IIFE)
|
|
16
|
+
|
|
17
|
+
A minified IIFE build is included for non-module environments (plain `<script>` tags, WebView2, Electron, etc.).
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<script src="https://unpkg.com/flatmarkdown-ast2html@0.1.2/dist/index.global.js"></script>
|
|
21
|
+
<script>
|
|
22
|
+
var html = FmAst2Html.renderToHtml(astJson);
|
|
23
|
+
document.getElementById('content').innerHTML = html;
|
|
24
|
+
</script>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The global `FmAst2Html` object exposes `renderToHtml(ast, options?)`.
|
|
28
|
+
|
|
29
|
+
To pin a specific version, use `@0.1.2` in the URL. Without a version tag, unpkg serves the latest.
|
|
30
|
+
|
|
31
|
+
## Build
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install
|
|
35
|
+
npm run build # outputs dist/ with ESM, CJS, IIFE, and .d.ts
|
|
36
|
+
npm test # runs vitest
|
|
37
|
+
npm publush #
|
|
38
|
+
```
|
|
39
|
+
|
|
15
40
|
## Quick Start
|
|
16
41
|
|
|
17
42
|
```ts
|
|
@@ -185,14 +210,6 @@ renderToHtml(ast, {
|
|
|
185
210
|
|
|
186
211
|
All node types are exported as individual TypeScript interfaces, plus the `AstNode` discriminated union.
|
|
187
212
|
|
|
188
|
-
## Build
|
|
189
|
-
|
|
190
|
-
```bash
|
|
191
|
-
bun install
|
|
192
|
-
bun run build # outputs dist/ with ESM, CJS, and .d.ts
|
|
193
|
-
bun test # runs vitest
|
|
194
|
-
```
|
|
195
|
-
|
|
196
213
|
## License
|
|
197
214
|
|
|
198
215
|
MIT
|
package/dist/index.d.cts
CHANGED
|
@@ -1,214 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
interface ParagraphNode {
|
|
6
|
-
type: 'paragraph';
|
|
7
|
-
children?: AstNode[];
|
|
8
|
-
}
|
|
9
|
-
interface HeadingNode {
|
|
10
|
-
type: 'heading';
|
|
11
|
-
level: number;
|
|
12
|
-
setext: boolean;
|
|
13
|
-
children?: AstNode[];
|
|
14
|
-
}
|
|
15
|
-
interface CodeBlockNode {
|
|
16
|
-
type: 'code_block';
|
|
17
|
-
fenced: boolean;
|
|
18
|
-
info: string;
|
|
19
|
-
literal: string;
|
|
20
|
-
}
|
|
21
|
-
interface BlockQuoteNode {
|
|
22
|
-
type: 'block_quote';
|
|
23
|
-
children?: AstNode[];
|
|
24
|
-
}
|
|
25
|
-
interface MultilineBlockQuoteNode {
|
|
26
|
-
type: 'multiline_block_quote';
|
|
27
|
-
children?: AstNode[];
|
|
28
|
-
}
|
|
29
|
-
interface ListNode {
|
|
30
|
-
type: 'list';
|
|
31
|
-
list_type: string;
|
|
32
|
-
start: number | null;
|
|
33
|
-
tight: boolean;
|
|
34
|
-
delimiter: string;
|
|
35
|
-
children?: AstNode[];
|
|
36
|
-
}
|
|
37
|
-
interface ItemNode {
|
|
38
|
-
type: 'item';
|
|
39
|
-
list_type: string;
|
|
40
|
-
start: number;
|
|
41
|
-
tight: boolean;
|
|
42
|
-
children?: AstNode[];
|
|
43
|
-
}
|
|
44
|
-
interface TaskItemNode {
|
|
45
|
-
type: 'task_item';
|
|
46
|
-
symbol: string | null;
|
|
47
|
-
children?: AstNode[];
|
|
48
|
-
}
|
|
49
|
-
interface TableNode {
|
|
50
|
-
type: 'table';
|
|
51
|
-
alignments: string[];
|
|
52
|
-
num_columns: number;
|
|
53
|
-
num_rows: number;
|
|
54
|
-
children?: AstNode[];
|
|
55
|
-
}
|
|
56
|
-
interface TableRowNode {
|
|
57
|
-
type: 'table_row';
|
|
58
|
-
header: boolean;
|
|
59
|
-
children?: AstNode[];
|
|
60
|
-
}
|
|
61
|
-
interface TableCellNode {
|
|
62
|
-
type: 'table_cell';
|
|
63
|
-
children?: AstNode[];
|
|
64
|
-
}
|
|
65
|
-
interface ThematicBreakNode {
|
|
66
|
-
type: 'thematic_break';
|
|
67
|
-
}
|
|
68
|
-
interface HtmlBlockNode {
|
|
69
|
-
type: 'html_block';
|
|
70
|
-
block_type: number;
|
|
71
|
-
literal: string;
|
|
72
|
-
}
|
|
73
|
-
interface FootnoteDefinitionNode {
|
|
74
|
-
type: 'footnote_definition';
|
|
75
|
-
name: string;
|
|
76
|
-
children?: AstNode[];
|
|
77
|
-
}
|
|
78
|
-
interface DescriptionListNode {
|
|
79
|
-
type: 'description_list';
|
|
80
|
-
children?: AstNode[];
|
|
81
|
-
}
|
|
82
|
-
interface DescriptionItemNode {
|
|
83
|
-
type: 'description_item';
|
|
84
|
-
children?: AstNode[];
|
|
85
|
-
}
|
|
86
|
-
interface DescriptionTermNode {
|
|
87
|
-
type: 'description_term';
|
|
88
|
-
children?: AstNode[];
|
|
89
|
-
}
|
|
90
|
-
interface DescriptionDetailsNode {
|
|
91
|
-
type: 'description_details';
|
|
92
|
-
children?: AstNode[];
|
|
93
|
-
}
|
|
94
|
-
interface AlertNode {
|
|
95
|
-
type: 'alert';
|
|
96
|
-
alert_type: string;
|
|
97
|
-
title: string | null;
|
|
98
|
-
children?: AstNode[];
|
|
99
|
-
}
|
|
100
|
-
interface FrontMatterNode {
|
|
101
|
-
type: 'front_matter';
|
|
102
|
-
value: string;
|
|
103
|
-
}
|
|
104
|
-
interface HeexBlockNode {
|
|
105
|
-
type: 'heex_block';
|
|
106
|
-
children?: AstNode[];
|
|
107
|
-
}
|
|
108
|
-
interface SubtextNode {
|
|
109
|
-
type: 'subtext';
|
|
110
|
-
children?: AstNode[];
|
|
111
|
-
}
|
|
112
|
-
interface TextNode {
|
|
113
|
-
type: 'text';
|
|
114
|
-
value: string;
|
|
115
|
-
}
|
|
116
|
-
interface SoftbreakNode {
|
|
117
|
-
type: 'softbreak';
|
|
118
|
-
}
|
|
119
|
-
interface LinebreakNode {
|
|
120
|
-
type: 'linebreak';
|
|
121
|
-
}
|
|
122
|
-
interface EmphNode {
|
|
123
|
-
type: 'emph';
|
|
124
|
-
children?: AstNode[];
|
|
125
|
-
}
|
|
126
|
-
interface StrongNode {
|
|
127
|
-
type: 'strong';
|
|
128
|
-
children?: AstNode[];
|
|
129
|
-
}
|
|
130
|
-
interface StrikethroughNode {
|
|
131
|
-
type: 'strikethrough';
|
|
132
|
-
children?: AstNode[];
|
|
133
|
-
}
|
|
134
|
-
interface UnderlineNode {
|
|
135
|
-
type: 'underline';
|
|
136
|
-
children?: AstNode[];
|
|
137
|
-
}
|
|
138
|
-
interface HighlightNode {
|
|
139
|
-
type: 'highlight';
|
|
140
|
-
children?: AstNode[];
|
|
141
|
-
}
|
|
142
|
-
interface SuperscriptNode {
|
|
143
|
-
type: 'superscript';
|
|
144
|
-
children?: AstNode[];
|
|
145
|
-
}
|
|
146
|
-
interface SubscriptNode {
|
|
147
|
-
type: 'subscript';
|
|
148
|
-
children?: AstNode[];
|
|
149
|
-
}
|
|
150
|
-
interface SpoileredTextNode {
|
|
151
|
-
type: 'spoilered_text';
|
|
152
|
-
children?: AstNode[];
|
|
153
|
-
}
|
|
154
|
-
interface CodeNode {
|
|
155
|
-
type: 'code';
|
|
156
|
-
literal: string;
|
|
157
|
-
}
|
|
158
|
-
interface LinkNode {
|
|
159
|
-
type: 'link';
|
|
160
|
-
url: string;
|
|
161
|
-
title: string;
|
|
162
|
-
children?: AstNode[];
|
|
163
|
-
}
|
|
164
|
-
interface ImageNode {
|
|
165
|
-
type: 'image';
|
|
166
|
-
url: string;
|
|
167
|
-
title: string;
|
|
168
|
-
children?: AstNode[];
|
|
169
|
-
}
|
|
170
|
-
interface FootnoteReferenceNode {
|
|
171
|
-
type: 'footnote_reference';
|
|
172
|
-
name: string;
|
|
173
|
-
ref_num: number;
|
|
174
|
-
ix: number;
|
|
175
|
-
}
|
|
176
|
-
interface ShortcodeNode {
|
|
177
|
-
type: 'shortcode';
|
|
178
|
-
code: string;
|
|
179
|
-
emoji: string;
|
|
180
|
-
}
|
|
181
|
-
interface MathNode {
|
|
182
|
-
type: 'math';
|
|
183
|
-
dollar_math: boolean;
|
|
184
|
-
display_math: boolean;
|
|
185
|
-
literal: string;
|
|
186
|
-
}
|
|
187
|
-
interface HtmlInlineNode {
|
|
188
|
-
type: 'html_inline';
|
|
189
|
-
value: string;
|
|
190
|
-
}
|
|
191
|
-
interface HeexInlineNode {
|
|
192
|
-
type: 'heex_inline';
|
|
193
|
-
value: string;
|
|
194
|
-
}
|
|
195
|
-
interface RawNode {
|
|
196
|
-
type: 'raw';
|
|
197
|
-
value: string;
|
|
198
|
-
}
|
|
199
|
-
interface EscapedNode {
|
|
200
|
-
type: 'escaped';
|
|
201
|
-
}
|
|
202
|
-
interface EscapedTagNode {
|
|
203
|
-
type: 'escaped_tag';
|
|
204
|
-
value: string;
|
|
205
|
-
}
|
|
206
|
-
interface WikilinkNode {
|
|
207
|
-
type: 'wikilink';
|
|
208
|
-
url: string;
|
|
209
|
-
children?: AstNode[];
|
|
210
|
-
}
|
|
211
|
-
type AstNode = DocumentNode | ParagraphNode | HeadingNode | CodeBlockNode | BlockQuoteNode | MultilineBlockQuoteNode | ListNode | ItemNode | TaskItemNode | TableNode | TableRowNode | TableCellNode | ThematicBreakNode | HtmlBlockNode | FootnoteDefinitionNode | DescriptionListNode | DescriptionItemNode | DescriptionTermNode | DescriptionDetailsNode | AlertNode | FrontMatterNode | HeexBlockNode | SubtextNode | TextNode | SoftbreakNode | LinebreakNode | EmphNode | StrongNode | StrikethroughNode | UnderlineNode | HighlightNode | SuperscriptNode | SubscriptNode | SpoileredTextNode | CodeNode | LinkNode | ImageNode | FootnoteReferenceNode | ShortcodeNode | MathNode | HtmlInlineNode | HeexInlineNode | RawNode | EscapedNode | EscapedTagNode | WikilinkNode;
|
|
1
|
+
import { AstNode } from 'flatmarkdown-ast';
|
|
2
|
+
export { AlertNode, AstNode, BlockQuoteNode, CodeBlockNode, CodeNode, DescriptionDetailsNode, DescriptionItemNode, DescriptionListNode, DescriptionTermNode, DocumentNode, EmphNode, EscapedNode, EscapedTagNode, FootnoteDefinitionNode, FootnoteReferenceNode, FrontMatterNode, HeadingNode, HeexBlockNode, HeexInlineNode, HighlightNode, HtmlBlockNode, HtmlInlineNode, ImageNode, ItemNode, LinebreakNode, LinkNode, ListNode, MathNode, MultilineBlockQuoteNode, ParagraphNode, RawNode, ShortcodeNode, SoftbreakNode, SpoileredTextNode, StrikethroughNode, StrongNode, SubscriptNode, SubtextNode, SuperscriptNode, TableCellNode, TableNode, TableRowNode, TaskItemNode, TextNode, ThematicBreakNode, UnderlineNode, WikilinkNode } from 'flatmarkdown-ast';
|
|
3
|
+
|
|
212
4
|
interface WikiLinkOptions {
|
|
213
5
|
/** Tag name. Default: 'a'. Use 'Link' for React Router, etc. */
|
|
214
6
|
tagName?: string;
|
|
@@ -232,4 +24,4 @@ interface RenderOptions {
|
|
|
232
24
|
*/
|
|
233
25
|
declare function renderToHtml(ast: AstNode | string, options?: RenderOptions): string;
|
|
234
26
|
|
|
235
|
-
export { type
|
|
27
|
+
export { type RenderOptions, type WikiLinkOptions, renderToHtml };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,214 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
interface ParagraphNode {
|
|
6
|
-
type: 'paragraph';
|
|
7
|
-
children?: AstNode[];
|
|
8
|
-
}
|
|
9
|
-
interface HeadingNode {
|
|
10
|
-
type: 'heading';
|
|
11
|
-
level: number;
|
|
12
|
-
setext: boolean;
|
|
13
|
-
children?: AstNode[];
|
|
14
|
-
}
|
|
15
|
-
interface CodeBlockNode {
|
|
16
|
-
type: 'code_block';
|
|
17
|
-
fenced: boolean;
|
|
18
|
-
info: string;
|
|
19
|
-
literal: string;
|
|
20
|
-
}
|
|
21
|
-
interface BlockQuoteNode {
|
|
22
|
-
type: 'block_quote';
|
|
23
|
-
children?: AstNode[];
|
|
24
|
-
}
|
|
25
|
-
interface MultilineBlockQuoteNode {
|
|
26
|
-
type: 'multiline_block_quote';
|
|
27
|
-
children?: AstNode[];
|
|
28
|
-
}
|
|
29
|
-
interface ListNode {
|
|
30
|
-
type: 'list';
|
|
31
|
-
list_type: string;
|
|
32
|
-
start: number | null;
|
|
33
|
-
tight: boolean;
|
|
34
|
-
delimiter: string;
|
|
35
|
-
children?: AstNode[];
|
|
36
|
-
}
|
|
37
|
-
interface ItemNode {
|
|
38
|
-
type: 'item';
|
|
39
|
-
list_type: string;
|
|
40
|
-
start: number;
|
|
41
|
-
tight: boolean;
|
|
42
|
-
children?: AstNode[];
|
|
43
|
-
}
|
|
44
|
-
interface TaskItemNode {
|
|
45
|
-
type: 'task_item';
|
|
46
|
-
symbol: string | null;
|
|
47
|
-
children?: AstNode[];
|
|
48
|
-
}
|
|
49
|
-
interface TableNode {
|
|
50
|
-
type: 'table';
|
|
51
|
-
alignments: string[];
|
|
52
|
-
num_columns: number;
|
|
53
|
-
num_rows: number;
|
|
54
|
-
children?: AstNode[];
|
|
55
|
-
}
|
|
56
|
-
interface TableRowNode {
|
|
57
|
-
type: 'table_row';
|
|
58
|
-
header: boolean;
|
|
59
|
-
children?: AstNode[];
|
|
60
|
-
}
|
|
61
|
-
interface TableCellNode {
|
|
62
|
-
type: 'table_cell';
|
|
63
|
-
children?: AstNode[];
|
|
64
|
-
}
|
|
65
|
-
interface ThematicBreakNode {
|
|
66
|
-
type: 'thematic_break';
|
|
67
|
-
}
|
|
68
|
-
interface HtmlBlockNode {
|
|
69
|
-
type: 'html_block';
|
|
70
|
-
block_type: number;
|
|
71
|
-
literal: string;
|
|
72
|
-
}
|
|
73
|
-
interface FootnoteDefinitionNode {
|
|
74
|
-
type: 'footnote_definition';
|
|
75
|
-
name: string;
|
|
76
|
-
children?: AstNode[];
|
|
77
|
-
}
|
|
78
|
-
interface DescriptionListNode {
|
|
79
|
-
type: 'description_list';
|
|
80
|
-
children?: AstNode[];
|
|
81
|
-
}
|
|
82
|
-
interface DescriptionItemNode {
|
|
83
|
-
type: 'description_item';
|
|
84
|
-
children?: AstNode[];
|
|
85
|
-
}
|
|
86
|
-
interface DescriptionTermNode {
|
|
87
|
-
type: 'description_term';
|
|
88
|
-
children?: AstNode[];
|
|
89
|
-
}
|
|
90
|
-
interface DescriptionDetailsNode {
|
|
91
|
-
type: 'description_details';
|
|
92
|
-
children?: AstNode[];
|
|
93
|
-
}
|
|
94
|
-
interface AlertNode {
|
|
95
|
-
type: 'alert';
|
|
96
|
-
alert_type: string;
|
|
97
|
-
title: string | null;
|
|
98
|
-
children?: AstNode[];
|
|
99
|
-
}
|
|
100
|
-
interface FrontMatterNode {
|
|
101
|
-
type: 'front_matter';
|
|
102
|
-
value: string;
|
|
103
|
-
}
|
|
104
|
-
interface HeexBlockNode {
|
|
105
|
-
type: 'heex_block';
|
|
106
|
-
children?: AstNode[];
|
|
107
|
-
}
|
|
108
|
-
interface SubtextNode {
|
|
109
|
-
type: 'subtext';
|
|
110
|
-
children?: AstNode[];
|
|
111
|
-
}
|
|
112
|
-
interface TextNode {
|
|
113
|
-
type: 'text';
|
|
114
|
-
value: string;
|
|
115
|
-
}
|
|
116
|
-
interface SoftbreakNode {
|
|
117
|
-
type: 'softbreak';
|
|
118
|
-
}
|
|
119
|
-
interface LinebreakNode {
|
|
120
|
-
type: 'linebreak';
|
|
121
|
-
}
|
|
122
|
-
interface EmphNode {
|
|
123
|
-
type: 'emph';
|
|
124
|
-
children?: AstNode[];
|
|
125
|
-
}
|
|
126
|
-
interface StrongNode {
|
|
127
|
-
type: 'strong';
|
|
128
|
-
children?: AstNode[];
|
|
129
|
-
}
|
|
130
|
-
interface StrikethroughNode {
|
|
131
|
-
type: 'strikethrough';
|
|
132
|
-
children?: AstNode[];
|
|
133
|
-
}
|
|
134
|
-
interface UnderlineNode {
|
|
135
|
-
type: 'underline';
|
|
136
|
-
children?: AstNode[];
|
|
137
|
-
}
|
|
138
|
-
interface HighlightNode {
|
|
139
|
-
type: 'highlight';
|
|
140
|
-
children?: AstNode[];
|
|
141
|
-
}
|
|
142
|
-
interface SuperscriptNode {
|
|
143
|
-
type: 'superscript';
|
|
144
|
-
children?: AstNode[];
|
|
145
|
-
}
|
|
146
|
-
interface SubscriptNode {
|
|
147
|
-
type: 'subscript';
|
|
148
|
-
children?: AstNode[];
|
|
149
|
-
}
|
|
150
|
-
interface SpoileredTextNode {
|
|
151
|
-
type: 'spoilered_text';
|
|
152
|
-
children?: AstNode[];
|
|
153
|
-
}
|
|
154
|
-
interface CodeNode {
|
|
155
|
-
type: 'code';
|
|
156
|
-
literal: string;
|
|
157
|
-
}
|
|
158
|
-
interface LinkNode {
|
|
159
|
-
type: 'link';
|
|
160
|
-
url: string;
|
|
161
|
-
title: string;
|
|
162
|
-
children?: AstNode[];
|
|
163
|
-
}
|
|
164
|
-
interface ImageNode {
|
|
165
|
-
type: 'image';
|
|
166
|
-
url: string;
|
|
167
|
-
title: string;
|
|
168
|
-
children?: AstNode[];
|
|
169
|
-
}
|
|
170
|
-
interface FootnoteReferenceNode {
|
|
171
|
-
type: 'footnote_reference';
|
|
172
|
-
name: string;
|
|
173
|
-
ref_num: number;
|
|
174
|
-
ix: number;
|
|
175
|
-
}
|
|
176
|
-
interface ShortcodeNode {
|
|
177
|
-
type: 'shortcode';
|
|
178
|
-
code: string;
|
|
179
|
-
emoji: string;
|
|
180
|
-
}
|
|
181
|
-
interface MathNode {
|
|
182
|
-
type: 'math';
|
|
183
|
-
dollar_math: boolean;
|
|
184
|
-
display_math: boolean;
|
|
185
|
-
literal: string;
|
|
186
|
-
}
|
|
187
|
-
interface HtmlInlineNode {
|
|
188
|
-
type: 'html_inline';
|
|
189
|
-
value: string;
|
|
190
|
-
}
|
|
191
|
-
interface HeexInlineNode {
|
|
192
|
-
type: 'heex_inline';
|
|
193
|
-
value: string;
|
|
194
|
-
}
|
|
195
|
-
interface RawNode {
|
|
196
|
-
type: 'raw';
|
|
197
|
-
value: string;
|
|
198
|
-
}
|
|
199
|
-
interface EscapedNode {
|
|
200
|
-
type: 'escaped';
|
|
201
|
-
}
|
|
202
|
-
interface EscapedTagNode {
|
|
203
|
-
type: 'escaped_tag';
|
|
204
|
-
value: string;
|
|
205
|
-
}
|
|
206
|
-
interface WikilinkNode {
|
|
207
|
-
type: 'wikilink';
|
|
208
|
-
url: string;
|
|
209
|
-
children?: AstNode[];
|
|
210
|
-
}
|
|
211
|
-
type AstNode = DocumentNode | ParagraphNode | HeadingNode | CodeBlockNode | BlockQuoteNode | MultilineBlockQuoteNode | ListNode | ItemNode | TaskItemNode | TableNode | TableRowNode | TableCellNode | ThematicBreakNode | HtmlBlockNode | FootnoteDefinitionNode | DescriptionListNode | DescriptionItemNode | DescriptionTermNode | DescriptionDetailsNode | AlertNode | FrontMatterNode | HeexBlockNode | SubtextNode | TextNode | SoftbreakNode | LinebreakNode | EmphNode | StrongNode | StrikethroughNode | UnderlineNode | HighlightNode | SuperscriptNode | SubscriptNode | SpoileredTextNode | CodeNode | LinkNode | ImageNode | FootnoteReferenceNode | ShortcodeNode | MathNode | HtmlInlineNode | HeexInlineNode | RawNode | EscapedNode | EscapedTagNode | WikilinkNode;
|
|
1
|
+
import { AstNode } from 'flatmarkdown-ast';
|
|
2
|
+
export { AlertNode, AstNode, BlockQuoteNode, CodeBlockNode, CodeNode, DescriptionDetailsNode, DescriptionItemNode, DescriptionListNode, DescriptionTermNode, DocumentNode, EmphNode, EscapedNode, EscapedTagNode, FootnoteDefinitionNode, FootnoteReferenceNode, FrontMatterNode, HeadingNode, HeexBlockNode, HeexInlineNode, HighlightNode, HtmlBlockNode, HtmlInlineNode, ImageNode, ItemNode, LinebreakNode, LinkNode, ListNode, MathNode, MultilineBlockQuoteNode, ParagraphNode, RawNode, ShortcodeNode, SoftbreakNode, SpoileredTextNode, StrikethroughNode, StrongNode, SubscriptNode, SubtextNode, SuperscriptNode, TableCellNode, TableNode, TableRowNode, TaskItemNode, TextNode, ThematicBreakNode, UnderlineNode, WikilinkNode } from 'flatmarkdown-ast';
|
|
3
|
+
|
|
212
4
|
interface WikiLinkOptions {
|
|
213
5
|
/** Tag name. Default: 'a'. Use 'Link' for React Router, etc. */
|
|
214
6
|
tagName?: string;
|
|
@@ -232,4 +24,4 @@ interface RenderOptions {
|
|
|
232
24
|
*/
|
|
233
25
|
declare function renderToHtml(ast: AstNode | string, options?: RenderOptions): string;
|
|
234
26
|
|
|
235
|
-
export { type
|
|
27
|
+
export { type RenderOptions, type WikiLinkOptions, renderToHtml };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";var FmAst2Html=(()=>{var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var b=(e,t)=>{for(var r in t)o(e,r,{get:t[r],enumerable:!0})},_=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of f(t))!k.call(e,a)&&a!==r&&o(e,a,{get:()=>t[a],enumerable:!(s=g(t,a))||s.enumerable});return e};var A=e=>_(o({},"__esModule",{value:!0}),e);var C={};b(C,{renderToHtml:()=>p});function R(e={}){return{options:e,inHeaderRow:!1,tableAlignments:[],cellIndex:0,tightList:!1}}function i(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function n(e,t){return e.children?e.children.map(r=>c(r,t)).join(""):""}function d(e){return e.type==="text"?e.value:"children"in e&&e.children?e.children.map(d).join(""):""}function c(e,t){switch(e.type){case"document":return n(e,t);case"paragraph":{let r=n(e,t);return t.tightList?`${r}
|
|
2
|
+
`:`<p>${r}</p>
|
|
3
|
+
`}case"heading":{let r=`h${e.level}`;return`<${r}>${n(e,t)}</${r}>
|
|
4
|
+
`}case"code_block":{let r=e.info;return`<pre><code${r?` class="language-${i(r)}"`:""}>${i(e.literal)}</code></pre>
|
|
5
|
+
`}case"block_quote":return`<blockquote>
|
|
6
|
+
${n(e,t)}</blockquote>
|
|
7
|
+
`;case"multiline_block_quote":return`<blockquote>
|
|
8
|
+
${n(e,t)}</blockquote>
|
|
9
|
+
`;case"list":return e.list_type==="ordered"?`<ol${e.start!=null&&e.start!==1?` start="${e.start}"`:""}>
|
|
10
|
+
${n(e,t)}</ol>
|
|
11
|
+
`:`<ul>
|
|
12
|
+
${n(e,t)}</ul>
|
|
13
|
+
`;case"item":{let r={...t,tightList:e.tight};return`<li>${n(e,r)}</li>
|
|
14
|
+
`}case"task_item":{let r=e.symbol!=null?' checked=""':"",s={...t,tightList:!0};return`<li><input type="checkbox"${r} disabled="" />${n(e,s)}</li>
|
|
15
|
+
`}case"table":{let r={...t,tableAlignments:e.alignments};return`<table>
|
|
16
|
+
${n(e,r)}</table>
|
|
17
|
+
`}case"table_row":return`<tr>
|
|
18
|
+
${(e.children||[]).map((s,a)=>{let l={...t,inHeaderRow:e.header,cellIndex:a};return c(s,l)}).join("")}</tr>
|
|
19
|
+
`;case"table_cell":{let r=t.inHeaderRow?"th":"td",s=t.tableAlignments[t.cellIndex],a=s&&s!=="none"?` align="${s}"`:"";return`<${r}${a}>${n(e,t)}</${r}>
|
|
20
|
+
`}case"thematic_break":return`<hr />
|
|
21
|
+
`;case"html_block":return e.literal;case"footnote_definition":return`<div class="footnote" id="fn-${i(e.name)}">
|
|
22
|
+
${n(e,t)}</div>
|
|
23
|
+
`;case"description_list":return`<dl>
|
|
24
|
+
${n(e,t)}</dl>
|
|
25
|
+
`;case"description_item":return n(e,t);case"description_term":return`<dt>${n(e,t)}</dt>
|
|
26
|
+
`;case"description_details":return`<dd>${n(e,t)}</dd>
|
|
27
|
+
`;case"alert":return`<div class="alert alert-${i(e.alert_type)}">
|
|
28
|
+
${n(e,t)}</div>
|
|
29
|
+
`;case"front_matter":return"";case"heex_block":return n(e,t);case"subtext":return n(e,t);case"text":return i(e.value);case"softbreak":return`
|
|
30
|
+
`;case"linebreak":return`<br />
|
|
31
|
+
`;case"emph":return`<em>${n(e,t)}</em>`;case"strong":return`<strong>${n(e,t)}</strong>`;case"strikethrough":return`<del>${n(e,t)}</del>`;case"underline":return`<u>${n(e,t)}</u>`;case"highlight":return`<mark>${n(e,t)}</mark>`;case"superscript":return`<sup>${n(e,t)}</sup>`;case"subscript":return`<sub>${n(e,t)}</sub>`;case"spoilered_text":return`<span class="spoiler">${n(e,t)}</span>`;case"code":return`<code>${i(e.literal)}</code>`;case"link":{let r=e.title?` title="${i(e.title)}"`:"";return`<a href="${i(e.url)}"${r}>${n(e,t)}</a>`}case"image":{let r=d(e),s=e.title?` title="${i(e.title)}"`:"";return`<img src="${i(e.url)}" alt="${i(r)}"${s} />`}case"wikilink":{let r=t.options.wikilink,s=r?.tagName??"a",a=r?.urlAttr??"href",l=r?.urlPrefix??"",$=r?.attrs??{"data-wikilink":"true"},h=`${l}${e.url}`,u=`${a}="${i(h)}"`;for(let[m,N]of Object.entries($))u+=` ${m}="${i(N)}"`;return`<${s} ${u}>${n(e,t)}</${s}>`}case"footnote_reference":return`<sup><a href="#fn-${i(e.name)}">[${e.ix+1}]</a></sup>`;case"shortcode":return e.emoji;case"math":return e.display_math?`<pre><code class="math math-display">${i(e.literal)}</code></pre>
|
|
32
|
+
`:`<code class="math math-inline">${i(e.literal)}</code>`;case"html_inline":return e.value;case"heex_inline":return e.value;case"raw":return e.value;case"escaped":return"";case"escaped_tag":return i(e.value);default:{let r=e;return""}}}function p(e,t){let r=typeof e=="string"?JSON.parse(e):e;return c(r,R(t))}return A(C);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flatmarkdown-ast2html",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A library to convert FlatMarkdown AST to HTML.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -38,6 +38,9 @@
|
|
|
38
38
|
],
|
|
39
39
|
"author": "Hidekazu Kubota",
|
|
40
40
|
"license": "MIT",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"flatmarkdown-ast": "^0.1.0"
|
|
43
|
+
},
|
|
41
44
|
"devDependencies": {
|
|
42
45
|
"tsup": "^8.0.0",
|
|
43
46
|
"vitest": "^3.0.0",
|