@willwang-io/react-djot 0.1.4 → 0.1.6
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 +151 -1
- package/dist/index.cjs +1293 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +253 -11
- package/dist/index.d.ts +253 -11
- package/dist/index.js +1294 -109
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
type DjotAttributes = Record<string, string>;
|
|
4
4
|
interface DjotBaseNode {
|
|
5
|
+
autoAttributes?: DjotAttributes;
|
|
5
6
|
attributes?: DjotAttributes;
|
|
6
7
|
tag: string;
|
|
7
8
|
}
|
|
@@ -9,12 +10,17 @@ interface DjotParentNode extends DjotBaseNode {
|
|
|
9
10
|
children: DjotNode[];
|
|
10
11
|
}
|
|
11
12
|
interface DjotDocNode extends DjotParentNode {
|
|
13
|
+
autoReferences?: Record<string, DjotReferenceNode>;
|
|
14
|
+
footnotes?: Record<string, DjotFootnoteNode>;
|
|
15
|
+
references?: Record<string, DjotReferenceNode>;
|
|
12
16
|
tag: "doc";
|
|
13
17
|
}
|
|
14
18
|
interface DjotSectionNode extends DjotParentNode {
|
|
15
|
-
autoAttributes?: DjotAttributes;
|
|
16
19
|
tag: "section";
|
|
17
20
|
}
|
|
21
|
+
interface DjotDivNode extends DjotParentNode {
|
|
22
|
+
tag: "div";
|
|
23
|
+
}
|
|
18
24
|
interface DjotParaNode extends DjotParentNode {
|
|
19
25
|
tag: "para";
|
|
20
26
|
}
|
|
@@ -28,6 +34,74 @@ interface DjotEmphNode extends DjotParentNode {
|
|
|
28
34
|
interface DjotStrongNode extends DjotParentNode {
|
|
29
35
|
tag: "strong";
|
|
30
36
|
}
|
|
37
|
+
interface DjotMarkNode extends DjotParentNode {
|
|
38
|
+
tag: "mark";
|
|
39
|
+
}
|
|
40
|
+
interface DjotHighlightedNode extends DjotParentNode {
|
|
41
|
+
tag: "highlighted";
|
|
42
|
+
}
|
|
43
|
+
interface DjotSuperscriptNode extends DjotParentNode {
|
|
44
|
+
tag: "superscript";
|
|
45
|
+
}
|
|
46
|
+
interface DjotSupeNode extends DjotParentNode {
|
|
47
|
+
tag: "supe";
|
|
48
|
+
}
|
|
49
|
+
interface DjotSubscriptNode extends DjotParentNode {
|
|
50
|
+
tag: "subscript";
|
|
51
|
+
}
|
|
52
|
+
interface DjotInsertNode extends DjotParentNode {
|
|
53
|
+
tag: "insert";
|
|
54
|
+
}
|
|
55
|
+
interface DjotDeleteNode extends DjotParentNode {
|
|
56
|
+
tag: "delete";
|
|
57
|
+
}
|
|
58
|
+
interface DjotSpanNode extends DjotParentNode {
|
|
59
|
+
tag: "span";
|
|
60
|
+
}
|
|
61
|
+
type DjotTableAlignment = "default" | "left" | "right" | "center" | (string & {});
|
|
62
|
+
interface DjotTableNode extends DjotParentNode {
|
|
63
|
+
tag: "table";
|
|
64
|
+
}
|
|
65
|
+
interface DjotCaptionNode extends DjotParentNode {
|
|
66
|
+
tag: "caption";
|
|
67
|
+
}
|
|
68
|
+
interface DjotRowNode extends DjotParentNode {
|
|
69
|
+
head: boolean;
|
|
70
|
+
tag: "row";
|
|
71
|
+
}
|
|
72
|
+
interface DjotCellNode extends DjotParentNode {
|
|
73
|
+
align: DjotTableAlignment;
|
|
74
|
+
head: boolean;
|
|
75
|
+
tag: "cell";
|
|
76
|
+
}
|
|
77
|
+
interface DjotFootnoteReferenceNode extends DjotBaseNode {
|
|
78
|
+
tag: "footnote_reference";
|
|
79
|
+
text: string;
|
|
80
|
+
}
|
|
81
|
+
interface DjotFootnoteNode extends DjotParentNode {
|
|
82
|
+
label: string;
|
|
83
|
+
tag: "footnote";
|
|
84
|
+
}
|
|
85
|
+
interface DjotDoubleQuotedNode extends DjotParentNode {
|
|
86
|
+
tag: "double_quoted";
|
|
87
|
+
}
|
|
88
|
+
interface DjotSingleQuotedNode extends DjotParentNode {
|
|
89
|
+
tag: "single_quoted";
|
|
90
|
+
}
|
|
91
|
+
type DjotSmartPunctuationType = "left_double_quote" | "right_double_quote" | "left_single_quote" | "right_single_quote" | "em_dash" | "en_dash" | "ellipses" | (string & {});
|
|
92
|
+
interface DjotSmartPunctuationNode extends DjotBaseNode {
|
|
93
|
+
tag: "smart_punctuation";
|
|
94
|
+
text: string;
|
|
95
|
+
type: DjotSmartPunctuationType;
|
|
96
|
+
}
|
|
97
|
+
interface DjotInlineMathNode extends DjotBaseNode {
|
|
98
|
+
tag: "inline_math";
|
|
99
|
+
text: string;
|
|
100
|
+
}
|
|
101
|
+
interface DjotDisplayMathNode extends DjotBaseNode {
|
|
102
|
+
tag: "display_math";
|
|
103
|
+
text: string;
|
|
104
|
+
}
|
|
31
105
|
interface DjotCodeNode extends DjotBaseNode {
|
|
32
106
|
tag: "code";
|
|
33
107
|
text: string;
|
|
@@ -37,24 +111,78 @@ interface DjotCodeBlockNode extends DjotBaseNode {
|
|
|
37
111
|
tag: "code_block";
|
|
38
112
|
text: string;
|
|
39
113
|
}
|
|
40
|
-
interface
|
|
114
|
+
interface DjotRawBlockNode extends DjotBaseNode {
|
|
115
|
+
format: string;
|
|
116
|
+
tag: "raw_block";
|
|
117
|
+
text: string;
|
|
118
|
+
}
|
|
119
|
+
interface DjotRawInlineNode extends DjotBaseNode {
|
|
120
|
+
format: string;
|
|
121
|
+
tag: "raw_inline";
|
|
122
|
+
text: string;
|
|
123
|
+
}
|
|
124
|
+
interface DjotSymbNode extends DjotBaseNode {
|
|
125
|
+
alias: string;
|
|
126
|
+
tag: "symb";
|
|
127
|
+
}
|
|
128
|
+
interface DjotUrlNode extends DjotBaseNode {
|
|
129
|
+
tag: "url";
|
|
130
|
+
text: string;
|
|
131
|
+
}
|
|
132
|
+
interface DjotEmailNode extends DjotBaseNode {
|
|
133
|
+
tag: "email";
|
|
134
|
+
text: string;
|
|
135
|
+
}
|
|
136
|
+
interface DjotReferenceNode extends DjotBaseNode {
|
|
41
137
|
destination: string;
|
|
138
|
+
label: string;
|
|
139
|
+
tag: "reference";
|
|
140
|
+
}
|
|
141
|
+
interface DjotLinkNode extends DjotParentNode {
|
|
142
|
+
destination?: string;
|
|
143
|
+
reference?: string;
|
|
42
144
|
tag: "link";
|
|
43
145
|
}
|
|
44
146
|
interface DjotImageNode extends DjotParentNode {
|
|
45
|
-
destination
|
|
147
|
+
destination?: string;
|
|
148
|
+
reference?: string;
|
|
46
149
|
tag: "image";
|
|
47
150
|
}
|
|
48
151
|
interface DjotBulletListNode extends DjotParentNode {
|
|
152
|
+
tight?: boolean;
|
|
49
153
|
tag: "bullet_list";
|
|
50
154
|
}
|
|
155
|
+
type DjotOrderedListStyle = "1." | "1)" | "(1)" | "a." | "a)" | "(a)" | "A." | "A)" | "(A)" | "i." | "i)" | "(i)" | "I." | "I)" | "(I)" | (string & {});
|
|
51
156
|
interface DjotOrderedListNode extends DjotParentNode {
|
|
52
157
|
start?: number;
|
|
158
|
+
style?: DjotOrderedListStyle;
|
|
159
|
+
tight?: boolean;
|
|
53
160
|
tag: "ordered_list";
|
|
54
161
|
}
|
|
55
162
|
interface DjotListItemNode extends DjotParentNode {
|
|
56
163
|
tag: "list_item";
|
|
57
164
|
}
|
|
165
|
+
interface DjotDefinitionListNode extends DjotParentNode {
|
|
166
|
+
tag: "definition_list";
|
|
167
|
+
}
|
|
168
|
+
interface DjotDefinitionListItemNode extends DjotParentNode {
|
|
169
|
+
tag: "definition_list_item";
|
|
170
|
+
}
|
|
171
|
+
interface DjotTermNode extends DjotParentNode {
|
|
172
|
+
tag: "term";
|
|
173
|
+
}
|
|
174
|
+
interface DjotDefinitionNode extends DjotParentNode {
|
|
175
|
+
tag: "definition";
|
|
176
|
+
}
|
|
177
|
+
type DjotCheckboxStatus = "checked" | "unchecked";
|
|
178
|
+
interface DjotTaskListNode extends DjotParentNode {
|
|
179
|
+
tag: "task_list";
|
|
180
|
+
tight?: boolean;
|
|
181
|
+
}
|
|
182
|
+
interface DjotTaskListItemNode extends DjotParentNode {
|
|
183
|
+
checkbox: DjotCheckboxStatus;
|
|
184
|
+
tag: "task_list_item";
|
|
185
|
+
}
|
|
58
186
|
interface DjotBlockquoteNode extends DjotParentNode {
|
|
59
187
|
tag: "blockquote";
|
|
60
188
|
}
|
|
@@ -78,7 +206,10 @@ interface DjotSoftBreakNode extends DjotBaseNode {
|
|
|
78
206
|
interface DjotHardBreakNode extends DjotBaseNode {
|
|
79
207
|
tag: "hard_break" | "hardbreak";
|
|
80
208
|
}
|
|
81
|
-
|
|
209
|
+
interface DjotNonBreakingSpaceNode extends DjotBaseNode {
|
|
210
|
+
tag: "non_breaking_space";
|
|
211
|
+
}
|
|
212
|
+
type DjotNode = DjotDocNode | DjotSectionNode | DjotDivNode | DjotParaNode | DjotHeadingNode | DjotEmphNode | DjotStrongNode | DjotMarkNode | DjotHighlightedNode | DjotSuperscriptNode | DjotSupeNode | DjotSubscriptNode | DjotInsertNode | DjotDeleteNode | DjotSpanNode | DjotTableNode | DjotCaptionNode | DjotRowNode | DjotCellNode | DjotFootnoteReferenceNode | DjotFootnoteNode | DjotDoubleQuotedNode | DjotSingleQuotedNode | DjotSmartPunctuationNode | DjotInlineMathNode | DjotDisplayMathNode | DjotCodeNode | DjotCodeBlockNode | DjotRawBlockNode | DjotRawInlineNode | DjotSymbNode | DjotUrlNode | DjotEmailNode | DjotLinkNode | DjotImageNode | DjotBulletListNode | DjotOrderedListNode | DjotListItemNode | DjotDefinitionListNode | DjotDefinitionListItemNode | DjotTermNode | DjotDefinitionNode | DjotTaskListNode | DjotTaskListItemNode | DjotBlockquoteNode | DjotBlockQuoteNode | DjotThematicBreakNode | DjotStrNode | DjotVerbatimNode | DjotNonBreakingSpaceNode | DjotSoftBreakNode | DjotHardBreakNode;
|
|
82
213
|
type DjotNodeTag = DjotNode["tag"];
|
|
83
214
|
type DjotNodeByTag<Tag extends DjotNodeTag> = Extract<DjotNode, {
|
|
84
215
|
tag: Tag;
|
|
@@ -90,12 +221,65 @@ interface DjotNodePropsBase<Tag extends DjotNodeTag> {
|
|
|
90
221
|
interface DjotComponentPropsMap {
|
|
91
222
|
doc: DjotNodePropsBase<"doc">;
|
|
92
223
|
section: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"section">;
|
|
224
|
+
div: React.HTMLAttributes<HTMLDivElement> & DjotNodePropsBase<"div">;
|
|
93
225
|
para: React.HTMLAttributes<HTMLParagraphElement> & DjotNodePropsBase<"para">;
|
|
94
226
|
heading: React.HTMLAttributes<HTMLHeadingElement> & DjotNodePropsBase<"heading"> & {
|
|
95
227
|
level: number;
|
|
96
228
|
};
|
|
97
229
|
emph: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"emph">;
|
|
98
230
|
strong: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"strong">;
|
|
231
|
+
mark: React.HTMLAttributes<HTMLElement> & Omit<DjotNodePropsBase<"mark">, "node"> & {
|
|
232
|
+
node: DjotMarkNode | DjotHighlightedNode;
|
|
233
|
+
};
|
|
234
|
+
highlighted: React.HTMLAttributes<HTMLElement> & Omit<DjotNodePropsBase<"highlighted">, "node"> & {
|
|
235
|
+
node: DjotMarkNode | DjotHighlightedNode;
|
|
236
|
+
};
|
|
237
|
+
superscript: React.HTMLAttributes<HTMLElement> & Omit<DjotNodePropsBase<"superscript">, "node"> & {
|
|
238
|
+
node: DjotSuperscriptNode | DjotSupeNode;
|
|
239
|
+
};
|
|
240
|
+
supe: React.HTMLAttributes<HTMLElement> & Omit<DjotNodePropsBase<"supe">, "node"> & {
|
|
241
|
+
node: DjotSuperscriptNode | DjotSupeNode;
|
|
242
|
+
};
|
|
243
|
+
subscript: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"subscript">;
|
|
244
|
+
insert: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"insert">;
|
|
245
|
+
delete: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"delete">;
|
|
246
|
+
span: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"span">;
|
|
247
|
+
table: React.TableHTMLAttributes<HTMLTableElement> & DjotNodePropsBase<"table">;
|
|
248
|
+
caption: React.HTMLAttributes<HTMLTableCaptionElement> & DjotNodePropsBase<"caption">;
|
|
249
|
+
row: React.HTMLAttributes<HTMLTableRowElement> & DjotNodePropsBase<"row"> & {
|
|
250
|
+
head: boolean;
|
|
251
|
+
};
|
|
252
|
+
cell: React.TdHTMLAttributes<HTMLTableCellElement> & Omit<DjotNodePropsBase<"cell">, "node"> & {
|
|
253
|
+
align: DjotTableAlignment;
|
|
254
|
+
head: boolean;
|
|
255
|
+
node: DjotCellNode;
|
|
256
|
+
};
|
|
257
|
+
footnote_reference: React.AnchorHTMLAttributes<HTMLAnchorElement> & DjotNodePropsBase<"footnote_reference"> & {
|
|
258
|
+
index: number;
|
|
259
|
+
label: string;
|
|
260
|
+
};
|
|
261
|
+
footnote: React.LiHTMLAttributes<HTMLLIElement> & Omit<DjotNodePropsBase<"footnote">, "node"> & {
|
|
262
|
+
index: number;
|
|
263
|
+
label: string;
|
|
264
|
+
node: DjotFootnoteNode;
|
|
265
|
+
};
|
|
266
|
+
endnotes: React.HTMLAttributes<HTMLElement> & {
|
|
267
|
+
children?: React.ReactNode;
|
|
268
|
+
node: DjotDocNode;
|
|
269
|
+
order: string[];
|
|
270
|
+
};
|
|
271
|
+
double_quoted: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"double_quoted">;
|
|
272
|
+
single_quoted: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"single_quoted">;
|
|
273
|
+
smart_punctuation: DjotNodePropsBase<"smart_punctuation"> & {
|
|
274
|
+
kind: DjotSmartPunctuationType;
|
|
275
|
+
value: string;
|
|
276
|
+
};
|
|
277
|
+
inline_math: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"inline_math"> & {
|
|
278
|
+
value: string;
|
|
279
|
+
};
|
|
280
|
+
display_math: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"display_math"> & {
|
|
281
|
+
value: string;
|
|
282
|
+
};
|
|
99
283
|
code: React.HTMLAttributes<HTMLElement> & Omit<DjotNodePropsBase<"code">, "node"> & {
|
|
100
284
|
node: DjotCodeNode | DjotVerbatimNode;
|
|
101
285
|
value: string;
|
|
@@ -108,13 +292,50 @@ interface DjotComponentPropsMap {
|
|
|
108
292
|
language?: string;
|
|
109
293
|
value: string;
|
|
110
294
|
};
|
|
295
|
+
raw_block: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"raw_block"> & {
|
|
296
|
+
format: string;
|
|
297
|
+
value: string;
|
|
298
|
+
};
|
|
299
|
+
raw_inline: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"raw_inline"> & {
|
|
300
|
+
format: string;
|
|
301
|
+
value: string;
|
|
302
|
+
};
|
|
303
|
+
symb: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"symb"> & {
|
|
304
|
+
alias: string;
|
|
305
|
+
value: string;
|
|
306
|
+
};
|
|
307
|
+
url: React.AnchorHTMLAttributes<HTMLAnchorElement> & DjotNodePropsBase<"url"> & {
|
|
308
|
+
href: string;
|
|
309
|
+
value: string;
|
|
310
|
+
};
|
|
311
|
+
email: React.AnchorHTMLAttributes<HTMLAnchorElement> & DjotNodePropsBase<"email"> & {
|
|
312
|
+
href: string;
|
|
313
|
+
value: string;
|
|
314
|
+
};
|
|
111
315
|
link: React.AnchorHTMLAttributes<HTMLAnchorElement> & DjotNodePropsBase<"link">;
|
|
112
316
|
image: React.ImgHTMLAttributes<HTMLImageElement> & DjotNodePropsBase<"image"> & {
|
|
113
317
|
alt?: string;
|
|
114
318
|
};
|
|
115
|
-
bullet_list: React.HTMLAttributes<HTMLUListElement> & DjotNodePropsBase<"bullet_list"
|
|
116
|
-
|
|
117
|
-
|
|
319
|
+
bullet_list: React.HTMLAttributes<HTMLUListElement> & DjotNodePropsBase<"bullet_list"> & {
|
|
320
|
+
tight?: boolean;
|
|
321
|
+
};
|
|
322
|
+
ordered_list: React.OlHTMLAttributes<HTMLOListElement> & DjotNodePropsBase<"ordered_list"> & {
|
|
323
|
+
tight?: boolean;
|
|
324
|
+
};
|
|
325
|
+
list_item: React.LiHTMLAttributes<HTMLLIElement> & DjotNodePropsBase<"list_item"> & {
|
|
326
|
+
tight?: boolean;
|
|
327
|
+
};
|
|
328
|
+
definition_list: React.HTMLAttributes<HTMLDListElement> & DjotNodePropsBase<"definition_list">;
|
|
329
|
+
definition_list_item: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"definition_list_item">;
|
|
330
|
+
term: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"term">;
|
|
331
|
+
definition: React.HTMLAttributes<HTMLElement> & DjotNodePropsBase<"definition">;
|
|
332
|
+
task_list: React.HTMLAttributes<HTMLUListElement> & DjotNodePropsBase<"task_list"> & {
|
|
333
|
+
tight?: boolean;
|
|
334
|
+
};
|
|
335
|
+
task_list_item: React.LiHTMLAttributes<HTMLLIElement> & DjotNodePropsBase<"task_list_item"> & {
|
|
336
|
+
checkbox: DjotCheckboxStatus;
|
|
337
|
+
tight?: boolean;
|
|
338
|
+
};
|
|
118
339
|
blockquote: React.BlockquoteHTMLAttributes<HTMLQuoteElement> & Omit<DjotNodePropsBase<"blockquote">, "node"> & {
|
|
119
340
|
node: DjotBlockquoteNode | DjotBlockQuoteNode;
|
|
120
341
|
};
|
|
@@ -125,6 +346,9 @@ interface DjotComponentPropsMap {
|
|
|
125
346
|
str: DjotNodePropsBase<"str"> & {
|
|
126
347
|
value: string;
|
|
127
348
|
};
|
|
349
|
+
non_breaking_space: DjotNodePropsBase<"non_breaking_space"> & {
|
|
350
|
+
value: string;
|
|
351
|
+
};
|
|
128
352
|
soft_break: DjotNodePropsBase<"soft_break">;
|
|
129
353
|
softbreak: DjotNodePropsBase<"softbreak">;
|
|
130
354
|
hard_break: DjotNodePropsBase<"hard_break">;
|
|
@@ -133,17 +357,35 @@ interface DjotComponentPropsMap {
|
|
|
133
357
|
type DjotComponents = Partial<{
|
|
134
358
|
[K in keyof DjotComponentPropsMap]: React.ElementType<DjotComponentPropsMap[K]>;
|
|
135
359
|
}>;
|
|
136
|
-
interface
|
|
137
|
-
children?: string | null | undefined;
|
|
360
|
+
interface DjotSharedProps {
|
|
138
361
|
components?: DjotComponents | undefined;
|
|
139
362
|
}
|
|
363
|
+
type DjotProps = (DjotSharedProps & {
|
|
364
|
+
ast?: never;
|
|
365
|
+
children?: string | null | undefined;
|
|
366
|
+
}) | (DjotSharedProps & {
|
|
367
|
+
ast: DjotNode;
|
|
368
|
+
children?: never;
|
|
369
|
+
});
|
|
140
370
|
|
|
141
|
-
declare function
|
|
371
|
+
declare function compileDjot(source: string): DjotNode;
|
|
372
|
+
declare function Djot(props: DjotProps): React.ReactElement | null;
|
|
373
|
+
|
|
374
|
+
interface FootnoteState {
|
|
375
|
+
autoReferencesByLabel: Record<string, DjotReferenceNode>;
|
|
376
|
+
firstRefIdByLabel: Map<string, string>;
|
|
377
|
+
indexByLabel: Map<string, number>;
|
|
378
|
+
order: string[];
|
|
379
|
+
referencesByLabel: Record<string, DjotReferenceNode>;
|
|
380
|
+
refCountByLabel: Map<string, number>;
|
|
381
|
+
}
|
|
142
382
|
|
|
143
383
|
interface RenderNodeOptions {
|
|
144
384
|
components?: DjotComponents | undefined;
|
|
385
|
+
footnoteState?: FootnoteState | undefined;
|
|
145
386
|
key?: React.Key;
|
|
387
|
+
listTight?: boolean | undefined;
|
|
146
388
|
}
|
|
147
389
|
declare function renderNode(node: DjotNode, options?: RenderNodeOptions): React.ReactNode;
|
|
148
390
|
|
|
149
|
-
export { Djot, type DjotComponentPropsMap, type DjotComponents, type DjotNode, type DjotNodeByTag, type DjotNodeTag, type DjotProps, Djot as default, renderNode };
|
|
391
|
+
export { Djot, type DjotComponentPropsMap, type DjotComponents, type DjotNode, type DjotNodeByTag, type DjotNodeTag, type DjotProps, compileDjot, Djot as default, renderNode };
|