@wdprlib/ast 0.1.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.
@@ -0,0 +1,583 @@
1
+ /**
2
+ * Source code position
3
+ */
4
+ interface Point {
5
+ /** Line number (1-based) */
6
+ line: number;
7
+ /** Column number (1-based) */
8
+ column: number;
9
+ /** Offset (0-based) */
10
+ offset: number;
11
+ }
12
+ /**
13
+ * Source code range
14
+ */
15
+ interface Position {
16
+ start: Point;
17
+ end: Point;
18
+ }
19
+ /**
20
+ * Helper to create a Point
21
+ */
22
+ declare function createPoint(line: number, column: number, offset: number): Point;
23
+ /**
24
+ * Helper to create a Position
25
+ */
26
+ declare function createPosition(start: Point, end: Point): Position;
27
+ /**
28
+ * Element types for AST
29
+ */
30
+ /**
31
+ * Attributes map
32
+ */
33
+ type AttributeMap = Record<string, string>;
34
+ /**
35
+ * Variable map for includes
36
+ */
37
+ type VariableMap = Record<string, string>;
38
+ /**
39
+ * Alignment
40
+ */
41
+ type Alignment = "left" | "right" | "center" | "justify";
42
+ /**
43
+ * Float alignment
44
+ */
45
+ interface FloatAlignment {
46
+ align: Alignment;
47
+ float: boolean;
48
+ }
49
+ /**
50
+ * Heading level
51
+ */
52
+ type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
53
+ /**
54
+ * Heading structure
55
+ */
56
+ interface Heading {
57
+ level: HeadingLevel;
58
+ "has-toc": boolean;
59
+ }
60
+ /**
61
+ * Header container type
62
+ */
63
+ interface HeaderType {
64
+ header: Heading;
65
+ }
66
+ /**
67
+ * Align container type
68
+ */
69
+ interface AlignType {
70
+ align: Alignment;
71
+ }
72
+ /**
73
+ * String-only container types (formatting, structural, etc.)
74
+ */
75
+ type StringContainerType = "bold" | "italics" | "underline" | "superscript" | "subscript" | "strikethrough" | "monospace" | "span" | "div" | "blockquote" | "size" | "paragraph" | "heading" | "collapsible" | "definition-list" | "definition-list-item" | "definition-list-key" | "definition-list-value" | "table-row" | "table-cell";
76
+ /**
77
+ * Container types
78
+ */
79
+ type ContainerType = StringContainerType | HeaderType | AlignType;
80
+ /**
81
+ * Type guard: ContainerType is a string literal
82
+ */
83
+ declare function isStringContainerType(type: ContainerType): type is StringContainerType;
84
+ /**
85
+ * Type guard: ContainerType is a HeaderType
86
+ */
87
+ declare function isHeaderType(type: ContainerType): type is HeaderType;
88
+ /**
89
+ * Type guard: ContainerType is an AlignType
90
+ */
91
+ declare function isAlignType(type: ContainerType): type is AlignType;
92
+ /**
93
+ * Container data
94
+ */
95
+ interface ContainerData {
96
+ type: ContainerType;
97
+ attributes: AttributeMap;
98
+ elements: Element[];
99
+ _paragraphStrip?: boolean;
100
+ _emptyParagraphStrip?: boolean;
101
+ _escapedFromParagraph?: boolean;
102
+ _closeSpan?: boolean;
103
+ _splitByBlankLine?: boolean;
104
+ }
105
+ /**
106
+ * Anchor target
107
+ */
108
+ type AnchorTarget = "new-tab" | "parent" | "top" | "same";
109
+ /**
110
+ * Page reference (for internal links)
111
+ */
112
+ interface PageRef {
113
+ site: string | null;
114
+ page: string;
115
+ }
116
+ /**
117
+ * Link location - either a page reference or a URL string
118
+ */
119
+ type LinkLocation = PageRef | string;
120
+ /**
121
+ * Link label types
122
+ */
123
+ type LinkLabel = {
124
+ text: string;
125
+ } | {
126
+ url: string | null;
127
+ } | "page";
128
+ /**
129
+ * Link type
130
+ */
131
+ type LinkType = "direct" | "page" | "interwiki" | "anchor" | "table-of-contents";
132
+ /**
133
+ * Image source
134
+ */
135
+ type ImageSource = {
136
+ type: "url";
137
+ data: string;
138
+ } | {
139
+ type: "file1";
140
+ data: {
141
+ file: string;
142
+ };
143
+ } | {
144
+ type: "file2";
145
+ data: {
146
+ page: string;
147
+ file: string;
148
+ };
149
+ } | {
150
+ type: "file3";
151
+ data: {
152
+ site: string;
153
+ page: string;
154
+ file: string;
155
+ };
156
+ };
157
+ /**
158
+ * List type
159
+ */
160
+ type ListType = "bullet" | "numbered" | "generic";
161
+ /**
162
+ * List item - discriminated union
163
+ */
164
+ type ListItem = {
165
+ "item-type": "elements";
166
+ attributes: AttributeMap;
167
+ elements: Element[];
168
+ } | {
169
+ "item-type": "sub-list";
170
+ element: "list";
171
+ data: ListData;
172
+ };
173
+ /**
174
+ * List data
175
+ */
176
+ interface ListData {
177
+ type: ListType;
178
+ attributes: AttributeMap;
179
+ items: ListItem[];
180
+ }
181
+ /**
182
+ * Definition list item
183
+ */
184
+ interface DefinitionListItem {
185
+ key_string: string;
186
+ key: Element[];
187
+ value: Element[];
188
+ }
189
+ /**
190
+ * Table cell
191
+ */
192
+ interface TableCell {
193
+ header: boolean;
194
+ "column-span": number;
195
+ align: Alignment | null;
196
+ attributes: AttributeMap;
197
+ elements: Element[];
198
+ }
199
+ /**
200
+ * Table row
201
+ */
202
+ interface TableRow {
203
+ attributes: AttributeMap;
204
+ cells: TableCell[];
205
+ }
206
+ /**
207
+ * Table data
208
+ */
209
+ interface TableData {
210
+ attributes: AttributeMap;
211
+ rows: TableRow[];
212
+ }
213
+ /**
214
+ * Tab data
215
+ */
216
+ interface TabData {
217
+ label: string;
218
+ elements: Element[];
219
+ }
220
+ /**
221
+ * Code block data
222
+ */
223
+ interface CodeBlockData {
224
+ contents: string;
225
+ language: string | null;
226
+ name: string | null;
227
+ }
228
+ /**
229
+ * Collapsible data
230
+ */
231
+ interface CollapsibleData {
232
+ elements: Element[];
233
+ attributes: AttributeMap;
234
+ "start-open": boolean;
235
+ "show-text": string | null;
236
+ "hide-text": string | null;
237
+ "show-top": boolean;
238
+ "show-bottom": boolean;
239
+ }
240
+ /**
241
+ * Module types
242
+ */
243
+ type Module = {
244
+ module: "unknown";
245
+ name: string;
246
+ arguments: AttributeMap;
247
+ body?: string;
248
+ } | {
249
+ module: "backlinks";
250
+ page: string | null;
251
+ } | {
252
+ module: "categories";
253
+ "include-hidden": boolean;
254
+ } | {
255
+ module: "join";
256
+ "button-text": string | null;
257
+ attributes: AttributeMap;
258
+ } | {
259
+ module: "page-tree";
260
+ root: string | null;
261
+ "show-root": boolean;
262
+ depth: number | null;
263
+ } | {
264
+ module: "rate";
265
+ } | {
266
+ module: "list-users";
267
+ users: string;
268
+ body?: string;
269
+ attributes: AttributeMap;
270
+ } | {
271
+ module: "list-pages";
272
+ category?: string;
273
+ tags?: string;
274
+ parent?: string;
275
+ "link-to"?: string;
276
+ "created-by"?: string;
277
+ "created-at"?: string;
278
+ "updated-at"?: string;
279
+ rating?: string;
280
+ votes?: string;
281
+ name?: string;
282
+ fullname?: string;
283
+ range?: string;
284
+ pagetype?: string;
285
+ offset?: number;
286
+ limit?: number;
287
+ "per-page"?: number;
288
+ order?: string;
289
+ reverse: boolean;
290
+ separate: boolean;
291
+ wrapper: boolean;
292
+ "prepend-line"?: string;
293
+ "append-line"?: string;
294
+ rss?: string;
295
+ "rss-description"?: string;
296
+ "rss-home"?: string;
297
+ "rss-limit"?: number;
298
+ "rss-only": boolean;
299
+ "url-attr-prefix"?: string;
300
+ body?: string;
301
+ attributes: AttributeMap;
302
+ };
303
+ /**
304
+ * Embed types
305
+ */
306
+ type Embed = {
307
+ embed: "youtube";
308
+ data: {
309
+ "video-id": string;
310
+ };
311
+ } | {
312
+ embed: "vimeo";
313
+ data: {
314
+ "video-id": string;
315
+ };
316
+ } | {
317
+ embed: "github-gist";
318
+ data: {
319
+ username: string;
320
+ hash: string;
321
+ };
322
+ } | {
323
+ embed: "gitlab-snippet";
324
+ data: {
325
+ "snippet-id": string;
326
+ };
327
+ };
328
+ /**
329
+ * Date item value
330
+ */
331
+ interface DateItem {
332
+ timestamp: number;
333
+ timezone: string;
334
+ }
335
+ /**
336
+ * Clear float direction
337
+ */
338
+ type ClearFloat = "left" | "right" | "both";
339
+ interface AnchorData {
340
+ target: AnchorTarget | null;
341
+ attributes: AttributeMap;
342
+ elements: Element[];
343
+ }
344
+ interface LinkData {
345
+ type: LinkType;
346
+ link: LinkLocation;
347
+ extra: string | null;
348
+ label: LinkLabel;
349
+ target: AnchorTarget | null;
350
+ }
351
+ interface ImageData {
352
+ source: ImageSource;
353
+ link: LinkLocation | null;
354
+ alignment: FloatAlignment | null;
355
+ attributes: AttributeMap;
356
+ }
357
+ interface TableOfContentsData {
358
+ attributes: AttributeMap;
359
+ align: Alignment | null;
360
+ }
361
+ interface FootnoteBlockData {
362
+ title: string | null;
363
+ hide?: boolean;
364
+ }
365
+ interface BibliographyCiteData {
366
+ label: string;
367
+ brackets: boolean;
368
+ }
369
+ interface BibliographyBlockData {
370
+ index: number;
371
+ title: string | null;
372
+ hide: boolean;
373
+ }
374
+ interface UserData {
375
+ name: string;
376
+ "show-avatar": boolean;
377
+ }
378
+ interface DateData {
379
+ value: DateItem;
380
+ format: string | null;
381
+ hover: boolean;
382
+ }
383
+ interface ColorData {
384
+ color: string;
385
+ elements: Element[];
386
+ }
387
+ interface MathData {
388
+ name: string | null;
389
+ "latex-source": string;
390
+ }
391
+ interface MathInlineData {
392
+ "latex-source": string;
393
+ }
394
+ interface HtmlData {
395
+ contents: string;
396
+ }
397
+ interface IframeData {
398
+ url: string;
399
+ attributes: AttributeMap;
400
+ }
401
+ interface IncludeData {
402
+ "paragraph-safe": boolean;
403
+ variables: VariableMap;
404
+ location: PageRef;
405
+ elements: Element[];
406
+ }
407
+ interface IfTagsData {
408
+ condition: string;
409
+ elements: Element[];
410
+ }
411
+ /**
412
+ * Expression data: [[#expr expression]]
413
+ * The expression is stored as a string and evaluated at render time.
414
+ */
415
+ interface ExprData {
416
+ expression: string;
417
+ }
418
+ /**
419
+ * If data: [[#if value | then | else]]
420
+ * Simple true/false checker that treats the value as a string.
421
+ * False values: "false", "null", "", "0"
422
+ */
423
+ interface IfCondData {
424
+ condition: string;
425
+ then: Element[];
426
+ else: Element[];
427
+ }
428
+ /**
429
+ * IfExpr data: [[#ifexpr expression | then | else]]
430
+ * Evaluates the expression and branches based on the result.
431
+ */
432
+ interface IfExprData {
433
+ expression: string;
434
+ then: Element[];
435
+ else: Element[];
436
+ }
437
+ type ElementDataMap = {
438
+ container: ContainerData;
439
+ module: Module;
440
+ text: string;
441
+ raw: string;
442
+ variable: string;
443
+ email: string;
444
+ table: TableData;
445
+ "tab-view": TabData[];
446
+ anchor: AnchorData;
447
+ "anchor-name": string;
448
+ link: LinkData;
449
+ image: ImageData;
450
+ list: ListData;
451
+ "definition-list": DefinitionListItem[];
452
+ collapsible: CollapsibleData;
453
+ "table-of-contents": TableOfContentsData;
454
+ footnote: void;
455
+ "footnote-ref": number;
456
+ "footnote-block": FootnoteBlockData;
457
+ "bibliography-cite": BibliographyCiteData;
458
+ "bibliography-block": BibliographyBlockData;
459
+ user: UserData;
460
+ date: DateData;
461
+ color: ColorData;
462
+ code: CodeBlockData;
463
+ math: MathData;
464
+ "math-inline": MathInlineData;
465
+ "equation-reference": string;
466
+ embed: Embed;
467
+ html: HtmlData;
468
+ iframe: IframeData;
469
+ include: IncludeData;
470
+ style: string;
471
+ "line-break": void;
472
+ "line-breaks": number;
473
+ "clear-float": ClearFloat;
474
+ "horizontal-rule": void;
475
+ "content-separator": void;
476
+ "if-tags": IfTagsData;
477
+ expr: ExprData;
478
+ if: IfCondData;
479
+ ifexpr: IfExprData;
480
+ };
481
+ /**
482
+ * All element tag names
483
+ */
484
+ type ElementName = keyof ElementDataMap;
485
+ /**
486
+ * Get the data type for a given element name
487
+ */
488
+ type ElementData<K extends ElementName> = ElementDataMap[K];
489
+ /**
490
+ * Get the Element variant for a given element name
491
+ */
492
+ type ElementOf<K extends ElementName> = ElementDataMap[K] extends void ? {
493
+ element: K;
494
+ } : {
495
+ element: K;
496
+ data: ElementDataMap[K];
497
+ };
498
+ /**
499
+ * Element - tagged union generated from ElementDataMap
500
+ */
501
+ type Element = { [K in ElementName] : ElementOf<K> }[ElementName];
502
+ /**
503
+ * TOC entry collected during parsing (internal format)
504
+ */
505
+ interface TocEntry {
506
+ level: number;
507
+ text: string;
508
+ }
509
+ /**
510
+ * Syntax tree - root of the AST
511
+ */
512
+ interface SyntaxTree {
513
+ elements: Element[];
514
+ "table-of-contents"?: Element[];
515
+ styles?: string[];
516
+ "html-blocks"?: string[];
517
+ "code-blocks"?: CodeBlockData[];
518
+ footnotes?: Element[][];
519
+ }
520
+ /**
521
+ * Create a text element
522
+ */
523
+ declare function text(value: string): Element;
524
+ /**
525
+ * Create a container element
526
+ */
527
+ declare function container(type: ContainerType, elements: Element[], attributes?: AttributeMap): Element;
528
+ /**
529
+ * Create a paragraph element
530
+ */
531
+ declare function paragraph(elements: Element[], attributes?: AttributeMap): Element;
532
+ /**
533
+ * Create a bold element
534
+ */
535
+ declare function bold(elements: Element[], attributes?: AttributeMap): Element;
536
+ /**
537
+ * Create an italics element
538
+ */
539
+ declare function italics(elements: Element[], attributes?: AttributeMap): Element;
540
+ /**
541
+ * Create a heading element
542
+ */
543
+ declare function heading(level: HeadingLevel, elements: Element[], hasToc?: boolean, attributes?: AttributeMap): Element;
544
+ /**
545
+ * Create a line break element
546
+ */
547
+ declare function lineBreak(): Element;
548
+ /**
549
+ * Create a horizontal rule element
550
+ */
551
+ declare function horizontalRule(): Element;
552
+ /**
553
+ * Create a link element
554
+ */
555
+ declare function link(linkLocation: LinkLocation, label: LinkLabel, options?: {
556
+ type?: LinkType;
557
+ extra?: string | null;
558
+ target?: AnchorTarget | null;
559
+ }): Element;
560
+ /**
561
+ * Create a list element
562
+ */
563
+ declare function list(type: ListType, items: ListItem[], attributes?: AttributeMap): Element;
564
+ /**
565
+ * Create a list item (elements type)
566
+ */
567
+ declare function listItemElements(elements: Element[], attributes?: AttributeMap): ListItem;
568
+ /**
569
+ * Create a list item (sub-list type)
570
+ */
571
+ declare function listItemSubList(data: ListData): ListItem;
572
+ /**
573
+ * Check if a container type is paragraph-safe.
574
+ */
575
+ declare function isContainerTypeParagraphSafe(type: ContainerType): boolean;
576
+ /**
577
+ * Check if an element is paragraph-safe (can be contained within a paragraph).
578
+ *
579
+ * This does a surface-level check and does not look into element interiors.
580
+ */
581
+ declare function isParagraphSafe(element: Element): boolean;
582
+ type Version = "wikidot";
583
+ export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, createPosition, createPoint, container, bold, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, Position, Point, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, FootnoteBlockData, FloatAlignment, ExprData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DefinitionListItem, DateItem, DateData, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };