@thi.ng/hiccup-markdown 2.1.48 → 3.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/api.d.ts CHANGED
@@ -1,19 +1,350 @@
1
- export interface TagFactories {
2
- blockquote(children: any[]): any[];
3
- code(body: string): any[];
4
- codeblock(lang: string, body: string): any[];
5
- em(body: string): any[];
6
- heading(level: number, children: any[]): any[];
7
- hr(): any[];
8
- img(src: string, alt: string): any[];
9
- li(children: any[]): any[];
10
- link(href: string, body: string): any[];
11
- list(type: string, items: any[]): any[];
12
- paragraph(children: any[]): any[];
13
- strike(body: string): any[];
14
- strong(body: string): any[];
15
- table(rows: any[]): any[];
16
- td(i: number, children: any[]): any[];
17
- tr(i: number, cells: any[]): any[];
1
+ import type { IObjectOf } from "@thi.ng/api";
2
+ import type { ILogger } from "@thi.ng/logger";
3
+ import type { ParseState } from "@thi.ng/parse";
4
+ /**
5
+ * The functions in this interface are being called by the parser to allow the
6
+ * user to transform the raw elements into arbitrary results. The package
7
+ * provides default implementations for all to generate minimal hiccup output.
8
+ *
9
+ * See the [markdown example
10
+ * project](https://github.com/thi-ng/umbrella/tree/develop/examples/markdown)
11
+ * for how these can be customized.
12
+ *
13
+ * @remarks
14
+ * For consistency, all handlers are receiving the {@link TransformCtx} as
15
+ * 1st arg. The remaining args are specific to each element type though and
16
+ * vary. Any child elements (`body` args) will already be transformed by the
17
+ * time a handler receives them.
18
+ *
19
+ * ### Optional metadata
20
+ *
21
+ * Block-level elements will also receive optional metadata associated with that
22
+ * element (and defined in the markdown source). The default implementations all
23
+ * assign such metadata (if present) to a `__meta` attribute (via
24
+ * {@link withMeta}). Also by default, the metadata itself is taken verbatim (as
25
+ * string) and NOT transformed in any way. Any form of metadata parsing (e.g.
26
+ * JSON) must be implemented by the {@link TagTransforms.meta} handler.
27
+ */
28
+ export interface TagTransforms {
29
+ /**
30
+ * Handler for `**` delimited body.
31
+ *
32
+ * @param ctx
33
+ * @param body
34
+ */
35
+ bold(ctx: TransformCtx, body: any[]): any;
36
+ /**
37
+ * Handler for `>` quoted body (aka blockquotes).
38
+ *
39
+ * @param ctx
40
+ * @param body
41
+ * @param meta
42
+ */
43
+ blockquote(ctx: TransformCtx, body: any[], meta?: any): any;
44
+ /**
45
+ * Handler for forced line breaks (aka lines ending with `\`).
46
+ *
47
+ * @param ctx
48
+ */
49
+ br(ctx: TransformCtx): any;
50
+ /**
51
+ * Handler for inline `code`.
52
+ *
53
+ * @param ctx
54
+ * @param body
55
+ */
56
+ code(ctx: TransformCtx, body: string): any;
57
+ /**
58
+ * Handler for GFM-style fenced code blocks.
59
+ *
60
+ * @param ctx
61
+ * @param lang
62
+ * @param head
63
+ * @param body
64
+ * @param meta
65
+ */
66
+ codeblock(ctx: TransformCtx, lang: string, head: string[], body: string, meta?: any): any;
67
+ /**
68
+ * Handler for `:::`-fenced custom blocks. `body` is unparsed raw string.
69
+ *
70
+ * @param ctx
71
+ * @param type
72
+ * @param head
73
+ * @param body
74
+ * @param meta
75
+ */
76
+ custom(ctx: TransformCtx, type: string, head: string[], body: string, meta?: any): any;
77
+ /**
78
+ * Handler for `:emoji_id:` replacements.
79
+ *
80
+ * @param ctx
81
+ * @param id
82
+ */
83
+ emoji(ctx: TransformCtx, id: string): any;
84
+ /**
85
+ * Handler for a single footnote definition (NOT its reference!).
86
+ *
87
+ * @param ctx
88
+ * @param id
89
+ * @param body
90
+ * @param meta
91
+ */
92
+ footnote(ctx: TransformCtx, id: string, body: any[], meta?: any): any;
93
+ /**
94
+ * Handler for a footnote reference.
95
+ *
96
+ * @param ctx
97
+ * @param id
98
+ */
99
+ footnoteRef(ctx: TransformCtx, id: string): any;
100
+ /**
101
+ * Handler for the container element holding all footnootes (only used if
102
+ * there actually are footnotes).
103
+ *
104
+ * @param ctx
105
+ * @param notes
106
+ */
107
+ footnoteWrapper(ctx: TransformCtx, notes: IObjectOf<any>): any;
108
+ /**
109
+ * Handler for a single heading element.
110
+ *
111
+ * @param ctx
112
+ * @param level
113
+ * @param id
114
+ * @param body
115
+ * @param meta
116
+ */
117
+ heading(ctx: TransformCtx, level: number, id: string, body: any[], meta?: any): any;
118
+ /**
119
+ * Horizontal rule handler. Also receives number of dashes used (e.g. to
120
+ * create different representations/styling)
121
+ *
122
+ * @param ctx
123
+ * @param length
124
+ * @param meta
125
+ */
126
+ hr(ctx: TransformCtx, length: number, meta?: any): any;
127
+ /**
128
+ * Handler for an image element.
129
+ *
130
+ * @param ctx
131
+ * @param label
132
+ * @param src
133
+ * @param title
134
+ */
135
+ img(ctx: TransformCtx, label: string, src: string, title?: string): any;
136
+ /**
137
+ * Handler for `_`-delimited italic body content
138
+ *
139
+ * @param ctx
140
+ * @param body
141
+ */
142
+ italic(ctx: TransformCtx, body: any[]): any;
143
+ /**
144
+ * Handler for `<kbd>`-wrapped keyboard shortcuts content
145
+ * @param ctx
146
+ * @param key
147
+ */
148
+ kbd(ctx: TransformCtx, key: string): any;
149
+ /**
150
+ * Handler for `[label](target)`-style links.
151
+ *
152
+ * @param ctx
153
+ * @param target
154
+ * @param title
155
+ * @param body
156
+ */
157
+ link(ctx: TransformCtx, target: string, title: string | undefined, body: any[]): any;
158
+ /**
159
+ * Handler for `[label][id]`-style links.
160
+ *
161
+ * @remarks
162
+ * Important: The actual link target might not yet be defined/known when
163
+ * this handler is called. Therefore some form of late-binding /
164
+ * lazy-resolution mechanism needs to be employed. Handlers can check the
165
+ * {@link TransformCtx.linkRefs} object if an entry for the given link
166
+ * ID is already defined. The assumption is that once the entire document
167
+ * has been parsed, all link refs will be known too.
168
+ *
169
+ * @param ctx
170
+ * @param refID
171
+ * @param body
172
+ */
173
+ linkRef(ctx: TransformCtx, refID: string, body: any[]): any;
174
+ /**
175
+ * Handler to transform/parse raw metadata into possibly more structured
176
+ * form.
177
+ *
178
+ * @param ctx
179
+ * @param body
180
+ */
181
+ meta(ctx: TransformCtx, body: string): any;
182
+ /**
183
+ * Handler for an ordered list wrapper.
184
+ *
185
+ * @param ctx
186
+ * @param items
187
+ * @param meta
188
+ */
189
+ ol(ctx: TransformCtx, items: any[], meta?: any): any;
190
+ /**
191
+ * Handler for a single list item in an ordered list. The `index` arg is the
192
+ * parsed integer index specified in the MD source code for that item.
193
+ *
194
+ * @remarks
195
+ * If the `attribs` object has a `__todo` attrib, the item is a task list
196
+ * item and `__done` indicates its state.
197
+ *
198
+ * @param ctx
199
+ * @param attribs
200
+ * @param index
201
+ * @param body
202
+ */
203
+ olitem(ctx: TransformCtx, attribs: TodoAttribs, index: number, ...body: any[]): any;
204
+ /**
205
+ * Handler for a paragraph of body content.
206
+ *
207
+ * @param ctx
208
+ * @param body
209
+ * @param meta
210
+ */
211
+ para(ctx: TransformCtx, body: any[], meta?: any): any;
212
+ /**
213
+ * Handler for `~~`-wrapped body content.
214
+ *
215
+ * @param ctx
216
+ * @param body
217
+ */
218
+ strike(ctx: TransformCtx, body: any[]): any;
219
+ /**
220
+ * Handler for a table container.
221
+ *
222
+ * @param ctx
223
+ * @param align
224
+ * @param head
225
+ * @param rows
226
+ * @param meta
227
+ */
228
+ table(ctx: TransformCtx, align: ColumnAlign[], head: any[], rows: any[], meta?: any): any;
229
+ /**
230
+ * Handler for a single table cell in a non-header row.
231
+ *
232
+ * @param ctx
233
+ * @param body
234
+ */
235
+ tableCell(ctx: TransformCtx, body: any[]): any;
236
+ /**
237
+ * Handler for a single table cell in the header row.
238
+ *
239
+ * @param ctx
240
+ * @param body
241
+ */
242
+ tableHead(ctx: TransformCtx, body: any[]): any;
243
+ /**
244
+ * Handler for a single table row. The header row will have `index=0`.
245
+ *
246
+ * @param ctx
247
+ * @param body
248
+ */
249
+ tableRow(ctx: TransformCtx, index: number, cells: any[]): any;
250
+ /**
251
+ * Handler for an unordered list wrapper.
252
+ *
253
+ * @param ctx
254
+ * @param items
255
+ * @param meta
256
+ */
257
+ ul(ctx: TransformCtx, items: any[], meta?: any): any;
258
+ /**
259
+ * Handler for a single list item in an unordered list.
260
+ *
261
+ * @remarks
262
+ * If the `attribs` object has a `__todo` attrib, the item is a task list
263
+ * item and `__done` indicates its state.
264
+ *
265
+ * @param ctx
266
+ * @param attribs
267
+ * @param body
268
+ */
269
+ ulitem(ctx: TransformCtx, attribs: TodoAttribs, ...body: any[]): any;
270
+ /**
271
+ * Handler for `[[page name]]` or `[[page name|label]]-style links.
272
+ *
273
+ * @param ctx
274
+ * @param id
275
+ * @param label
276
+ */
277
+ wikiref(ctx: TransformCtx, id: string, label?: string): any;
18
278
  }
279
+ /**
280
+ * State object used to manage & customize the transformation of raw parser
281
+ * results.
282
+ */
283
+ export interface TransformCtx {
284
+ logger?: ILogger;
285
+ tags: TagTransforms;
286
+ linkRefs: IObjectOf<[string, string?]>;
287
+ footnotes: IObjectOf<any>;
288
+ headings: {
289
+ level: number;
290
+ body: any[];
291
+ }[];
292
+ hasFootnotes: boolean;
293
+ meta?: any;
294
+ row: number;
295
+ opts: ParseOpts;
296
+ }
297
+ export interface ParseOpts {
298
+ /**
299
+ * If true, automatically escapes some characters using HTML entities.
300
+ *
301
+ * @remarks
302
+ * Reference:
303
+ * - https://github.com/thi-ng/umbrella/blob/develop/packages/strings/src/entities.ts
304
+ *
305
+ * @defaultValue false
306
+ */
307
+ escape: boolean;
308
+ /**
309
+ * If true (default: false), retains the
310
+ * [`ParseState`](https://docs.thi.ng/umbrella/parse/interfaces/ParseState.html)
311
+ * for each tree node (useful for error messages/debugging).
312
+ *
313
+ * @remarks
314
+ * Regardless of this option being enabled, the final state of the parser
315
+ * can be obtained via the {@link ParseResult.state} property.
316
+ *
317
+ * @defaultValue false
318
+ */
319
+ retain: boolean;
320
+ }
321
+ /**
322
+ * Result type of {@link parse}.
323
+ */
324
+ export interface ParseResult {
325
+ /**
326
+ * Result array of parsed & transformed elements
327
+ */
328
+ result: any[];
329
+ /**
330
+ * The transform context used to transform the Markdown document (e.g. to
331
+ * obtain footnotes, headings, link references etc.)
332
+ */
333
+ ctx: TransformCtx;
334
+ /**
335
+ * True, if the entire document was transformed. False, if only parsing only
336
+ * succeeded partially.
337
+ */
338
+ complete: boolean;
339
+ /**
340
+ * Last location information (line, column, index position) of the parser.
341
+ * For partial results, this will be where further parsing failed.
342
+ */
343
+ state: ParseState<string>;
344
+ }
345
+ export type TodoAttribs = Partial<{
346
+ __todo: true;
347
+ __done: boolean;
348
+ }>;
349
+ export type ColumnAlign = "center" | "default" | "left" | "right";
19
350
  //# sourceMappingURL=api.d.ts.map
package/emoji.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { IObjectOf } from "@thi.ng/api";
2
+ /**
3
+ * @remarks
4
+ * Source: https://raw.githubusercontent.com/omnidan/node_emoji/master/lib/emoji.json
5
+ *
6
+ * Changes:
7
+ * - sorted alphabetically
8
+ * - replaced all hyphens with underscores
9
+ */
10
+ export declare const EMOJIS: IObjectOf<string>;
11
+ //# sourceMappingURL=emoji.d.ts.map