pantsdown 2.2.3 → 2.2.5

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/src/types.ts CHANGED
@@ -1,267 +1,285 @@
1
1
  export type HTMLAttrs = [name: string, value: string][];
2
2
 
3
3
  type BaseToken = {
4
- type: string;
5
- raw: string;
6
- text?: string;
7
- sourceMap?: SourceMap;
4
+ type: string;
5
+ raw: string;
6
+ text?: string;
7
+ sourceMap?: SourceMap;
8
8
  };
9
9
 
10
10
  export type SourceMap = [start: number, end: number] | undefined;
11
11
 
12
12
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
13
13
  export interface Tokens extends Record<string, BaseToken> {
14
- Space: {
15
- type: "space";
16
- raw: string;
17
- };
18
- Code: {
19
- type: "code";
20
- raw: string;
21
- text: string;
22
- codeBlockStyle?: "indented";
23
- lang?: string | undefined;
24
- sourceMap: SourceMap;
25
- };
26
- Alert: {
27
- type: "alert";
28
- raw: string;
29
- text: string;
30
- icon: string;
31
- tokens: Token[];
32
- variant: "Note" | "Important" | "Warning" | "Tip" | "Caution";
33
- };
34
- Heading: {
35
- type: "heading";
36
- raw: string;
37
- text: string;
38
- depth: number;
39
- tokens: Token[];
40
- sourceMap: SourceMap;
41
- };
42
- Table: {
43
- type: "table";
44
- raw: string;
45
- align: ("center" | "left" | "right" | null)[];
46
- header: Tokens["TableCell"][];
47
- rows: Tokens["TableCell"][][];
48
- sourceMap: SourceMap;
49
- };
50
- TableCell: {
51
- type: "tablecell";
52
- raw: string;
53
- text: string;
54
- tokens: Token[];
55
- };
56
- Hr: {
57
- type: "hr";
58
- raw: string;
59
- sourceMap: SourceMap;
60
- };
61
- Blockquote: {
62
- type: "blockquote";
63
- raw: string;
64
- text: string;
65
- tokens: Token[];
66
- };
67
- List: {
68
- type: "list";
69
- raw: string;
70
- ordered: boolean;
71
- start: number | "";
72
- loose: boolean;
73
- items: Tokens["ListItem"][];
74
- };
75
- ListItem: {
76
- type: "list_item";
77
- raw: string;
78
- text: string;
79
- task: boolean;
80
- checked?: boolean | undefined;
81
- loose: boolean;
82
- tokens: Token[];
83
- sourceMap: SourceMap;
84
- };
85
- Paragraph: {
86
- type: "paragraph";
87
- raw: string;
88
- text: string;
89
- pre?: boolean | undefined;
90
- tokens: Token[];
91
- sourceMap: SourceMap;
92
- };
93
- HTML: {
94
- type: "html";
95
- raw: string;
96
- text: string;
97
- pre: boolean;
98
- block: boolean;
99
- sourceMap: SourceMap;
100
- };
101
- Text: {
102
- type: "text";
103
- raw: string;
104
- text: string;
105
- tokens?: Token[];
106
- sourceMap?: SourceMap;
107
- };
108
- Def: {
109
- type: "def";
110
- raw: string;
111
- tag: string;
112
- href: string;
113
- title: string;
114
- sourceMap: SourceMap;
115
- };
116
- Escape: {
117
- type: "escape";
118
- raw: string;
119
- text: string;
120
- };
121
- Tag: {
122
- type: "text" | "html";
123
- raw: string;
124
- text: string;
125
- inLink: boolean;
126
- inRawBlock: boolean;
127
- block: boolean;
128
- };
129
- Link: {
130
- type: "link";
131
- raw: string;
132
- text: string;
133
- href: string;
134
- title: string | null;
135
- tokens: Token[];
136
- };
137
- Image: {
138
- type: "image";
139
- raw: string;
140
- text: string;
141
- href: string;
142
- title: string | null;
143
- };
144
- Strong: {
145
- type: "strong";
146
- raw: string;
147
- text: string;
148
- tokens: Token[];
149
- };
150
- Em: {
151
- type: "em";
152
- raw: string;
153
- text: string;
154
- tokens: Token[];
155
- };
156
- Codespan: {
157
- type: "codespan";
158
- raw: string;
159
- text: string;
160
- };
161
- Br: {
162
- type: "br";
163
- raw: string;
164
- };
165
- Del: {
166
- type: "del";
167
- raw: string;
168
- text: string;
169
- tokens: Token[];
170
- };
171
- Footnote: {
172
- type: "footnote";
173
- raw: string;
174
- text: string;
175
- label: string;
176
- content: Token[];
177
- sourceMap: SourceMap;
178
- };
179
- FootnoteRef: {
180
- type: "footnoteRef";
181
- raw: string;
182
- label: string;
183
- };
184
- Footnotes: {
185
- type: "footnotes";
186
- raw: string;
187
- items: Tokens["Footnote"][];
188
- };
189
- LatexBlock: {
190
- type: "latexBlock";
191
- raw: string;
192
- text: string;
193
- sourceMap: SourceMap;
194
- };
195
- LatexInline: {
196
- type: "latexInline";
197
- raw: string;
198
- text: string;
199
- };
14
+ Space: {
15
+ type: "space";
16
+ raw: string;
17
+ };
18
+ Code: {
19
+ type: "code";
20
+ raw: string;
21
+ text: string;
22
+ codeBlockStyle?: "indented";
23
+ lang?: string | undefined;
24
+ sourceMap: SourceMap;
25
+ };
26
+ Alert: {
27
+ type: "alert";
28
+ raw: string;
29
+ text: string;
30
+ icon: string;
31
+ tokens: Token[];
32
+ variant: "Note" | "Important" | "Warning" | "Tip" | "Caution";
33
+ };
34
+ Heading: {
35
+ type: "heading";
36
+ raw: string;
37
+ text: string;
38
+ depth: number;
39
+ tokens: Token[];
40
+ sourceMap: SourceMap;
41
+ };
42
+ Table: {
43
+ type: "table";
44
+ raw: string;
45
+ align: ("center" | "left" | "right" | null)[];
46
+ header: Tokens["TableCell"][];
47
+ rows: Tokens["TableCell"][][];
48
+ sourceMap: SourceMap;
49
+ };
50
+ TableCell: {
51
+ type: "tablecell";
52
+ raw: string;
53
+ text: string;
54
+ tokens: Token[];
55
+ };
56
+ Hr: {
57
+ type: "hr";
58
+ raw: string;
59
+ sourceMap: SourceMap;
60
+ };
61
+ Blockquote: {
62
+ type: "blockquote";
63
+ raw: string;
64
+ text: string;
65
+ tokens: Token[];
66
+ };
67
+ List: {
68
+ type: "list";
69
+ raw: string;
70
+ ordered: boolean;
71
+ start: number | "";
72
+ loose: boolean;
73
+ items: Tokens["ListItem"][];
74
+ };
75
+ ListItem: {
76
+ type: "list_item";
77
+ raw: string;
78
+ text: string;
79
+ task: boolean;
80
+ checked?: boolean | undefined;
81
+ loose: boolean;
82
+ tokens: Token[];
83
+ sourceMap: SourceMap;
84
+ };
85
+ Paragraph: {
86
+ type: "paragraph";
87
+ raw: string;
88
+ text: string;
89
+ pre?: boolean | undefined;
90
+ tokens: Token[];
91
+ sourceMap: SourceMap;
92
+ };
93
+ HTML: {
94
+ type: "html";
95
+ raw: string;
96
+ text: string;
97
+ pre: boolean;
98
+ block: boolean;
99
+ sourceMap: SourceMap;
100
+ };
101
+ Text: {
102
+ type: "text";
103
+ raw: string;
104
+ text: string;
105
+ tokens?: Token[];
106
+ sourceMap?: SourceMap;
107
+ };
108
+ Def: {
109
+ type: "def";
110
+ raw: string;
111
+ tag: string;
112
+ href: string;
113
+ title: string;
114
+ sourceMap: SourceMap;
115
+ };
116
+ Escape: {
117
+ type: "escape";
118
+ raw: string;
119
+ text: string;
120
+ };
121
+ Tag: {
122
+ type: "text" | "html";
123
+ raw: string;
124
+ text: string;
125
+ inLink: boolean;
126
+ inRawBlock: boolean;
127
+ block: boolean;
128
+ };
129
+ Link: {
130
+ type: "link";
131
+ raw: string;
132
+ text: string;
133
+ href: string;
134
+ title: string | null;
135
+ tokens: Token[];
136
+ };
137
+ Image: {
138
+ type: "image";
139
+ raw: string;
140
+ text: string;
141
+ href: string;
142
+ title: string | null;
143
+ };
144
+ Strong: {
145
+ type: "strong";
146
+ raw: string;
147
+ text: string;
148
+ tokens: Token[];
149
+ };
150
+ Em: {
151
+ type: "em";
152
+ raw: string;
153
+ text: string;
154
+ tokens: Token[];
155
+ };
156
+ Codespan: {
157
+ type: "codespan";
158
+ raw: string;
159
+ text: string;
160
+ };
161
+ Br: {
162
+ type: "br";
163
+ raw: string;
164
+ };
165
+ Del: {
166
+ type: "del";
167
+ raw: string;
168
+ text: string;
169
+ tokens: Token[];
170
+ };
171
+ Footnote: {
172
+ type: "footnote";
173
+ raw: string;
174
+ text: string;
175
+ label: string;
176
+ content: Token[];
177
+ sourceMap: SourceMap;
178
+ };
179
+ FootnoteRef: {
180
+ type: "footnoteRef";
181
+ raw: string;
182
+ label: string;
183
+ };
184
+ Footnotes: {
185
+ type: "footnotes";
186
+ raw: string;
187
+ items: Tokens["Footnote"][];
188
+ };
189
+ LatexBlock: {
190
+ type: "latexBlock";
191
+ raw: string;
192
+ text: string;
193
+ sourceMap: SourceMap;
194
+ };
195
+ LatexInline: {
196
+ type: "latexInline";
197
+ raw: string;
198
+ text: string;
199
+ };
200
200
  }
201
201
 
202
202
  export type Token =
203
- | Tokens["Space"]
204
- | Tokens["Code"]
205
- | Tokens["Heading"]
206
- | Tokens["Table"]
207
- | Tokens["TableCell"]
208
- | Tokens["Hr"]
209
- | Tokens["Blockquote"]
210
- | Tokens["List"]
211
- | Tokens["ListItem"]
212
- | Tokens["Paragraph"]
213
- | Tokens["HTML"]
214
- | Tokens["Text"]
215
- | Tokens["Def"]
216
- | Tokens["Escape"]
217
- | Tokens["Tag"]
218
- | Tokens["Link"]
219
- | Tokens["Image"]
220
- | Tokens["Strong"]
221
- | Tokens["Em"]
222
- | Tokens["Codespan"]
223
- | Tokens["Br"]
224
- | Tokens["Del"]
225
- | Tokens["Alert"]
226
- | Tokens["Footnote"]
227
- | Tokens["FootnoteRef"]
228
- | Tokens["Footnotes"]
229
- | Tokens["LatexBlock"]
230
- | Tokens["LatexInline"];
203
+ | Tokens["Space"]
204
+ | Tokens["Code"]
205
+ | Tokens["Heading"]
206
+ | Tokens["Table"]
207
+ | Tokens["TableCell"]
208
+ | Tokens["Hr"]
209
+ | Tokens["Blockquote"]
210
+ | Tokens["List"]
211
+ | Tokens["ListItem"]
212
+ | Tokens["Paragraph"]
213
+ | Tokens["HTML"]
214
+ | Tokens["Text"]
215
+ | Tokens["Def"]
216
+ | Tokens["Escape"]
217
+ | Tokens["Tag"]
218
+ | Tokens["Link"]
219
+ | Tokens["Image"]
220
+ | Tokens["Strong"]
221
+ | Tokens["Em"]
222
+ | Tokens["Codespan"]
223
+ | Tokens["Br"]
224
+ | Tokens["Del"]
225
+ | Tokens["Alert"]
226
+ | Tokens["Footnote"]
227
+ | Tokens["FootnoteRef"]
228
+ | Tokens["Footnotes"]
229
+ | Tokens["LatexBlock"]
230
+ | Tokens["LatexInline"];
231
231
 
232
232
  export type Links = Record<string, { href: string; title: string }>;
233
233
 
234
234
  export type PantsdownConfig = {
235
- renderer: {
236
- /**
237
- * Prefix to be added to relative image sources.
238
- * Must start and end with "/"
239
- *
240
- * @example
241
- * relativeImageUrlPrefix: "/__localimage__/"
242
- *
243
- * ![image](./wallpants-512.png)
244
- * relative src is updated and results in:
245
- * <img src="/__localimage__/wallpants-512.png" />
246
- *
247
- * ![image](https://avatars.githubusercontent.com/wallpants)
248
- * absolute src remains unchanged:
249
- * <img src="https://avatars.githubusercontent.com/wallpants" />
250
- */
251
- relativeImageUrlPrefix: string;
235
+ renderer: {
236
+ /**
237
+ * Prefix to be added to relative image sources.
238
+ * Must start and end with "/"
239
+ *
240
+ * @example
241
+ * relativeImageUrlPrefix: "/__localimage__/nested/directory/"
242
+ *
243
+ * ![image](./wallpants-512.png)
244
+ * relative src is updated and results in:
245
+ * <img src="/__localimage__/nested/directory/wallpants-512.png" />
246
+ *
247
+ * ![image](https://avatars.githubusercontent.com/wallpants)
248
+ * absolute src remains unchanged:
249
+ * <img src="https://avatars.githubusercontent.com/wallpants" />
250
+ */
251
+ relativeImageUrlPrefix: string;
252
252
 
253
- /**
254
- * Whether to render <details> html tags with attribute `open=""`
255
- *
256
- * @default
257
- * false
258
- */
259
- detailsTagDefaultOpen: boolean;
260
- };
253
+ /**
254
+ * Prefix to be added to absolute image sources.
255
+ * Must start and end with "/"
256
+ * Falls back to `relativeImageUrlPrefix` if not provided
257
+ *
258
+ * @example
259
+ * absoluteImageUrlPrefix: "/__localimage__/"
260
+ *
261
+ * ![image](./wallpants-512.png)
262
+ * relative src is updated and results in:
263
+ * <img src="/__localimage__/wallpants-512.png" />
264
+ *
265
+ * ![image](https://avatars.githubusercontent.com/wallpants)
266
+ * external src remains unchanged:
267
+ * <img src="https://avatars.githubusercontent.com/wallpants" />
268
+ */
269
+ absoluteImageUrlPrefix?: string | undefined;
270
+
271
+ /**
272
+ * Whether to render <details> html tags with attribute `open=""`
273
+ *
274
+ * @default
275
+ * false
276
+ */
277
+ detailsTagDefaultOpen: boolean;
278
+ };
261
279
  };
262
280
 
263
281
  type DeepPartial<T> = {
264
- [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
282
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
265
283
  };
266
284
 
267
285
  export type PartialPantsdownConfig = DeepPartial<PantsdownConfig>;