@f-o-t/markdown 1.0.2 → 1.0.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/dist/index.d.ts CHANGED
@@ -1,780 +1,12 @@
1
- import { z } from "zod";
2
- /**
3
- * Default maximum buffer size (10MB) to prevent memory exhaustion attacks.
4
- */
5
- declare const DEFAULT_MAX_BUFFER_SIZE: number;
6
- /**
7
- * Source position for a node in the original markdown.
8
- */
9
- declare const positionSchema: any;
10
- type Position = z.infer<typeof positionSchema>;
11
- interface TextNode {
12
- type: "text";
13
- value: string;
14
- position?: Position;
15
- }
16
- interface CodeSpanNode {
17
- type: "codeSpan";
18
- value: string;
19
- position?: Position;
20
- }
21
- interface HardBreakNode {
22
- type: "hardBreak";
23
- position?: Position;
24
- }
25
- interface SoftBreakNode {
26
- type: "softBreak";
27
- position?: Position;
28
- }
29
- interface HtmlInlineNode {
30
- type: "htmlInline";
31
- value: string;
32
- position?: Position;
33
- }
34
- interface EmphasisNode {
35
- type: "emphasis";
36
- children: InlineNode[];
37
- marker: "*" | "_";
38
- position?: Position;
39
- }
40
- interface StrongNode {
41
- type: "strong";
42
- children: InlineNode[];
43
- marker: "**" | "__";
44
- position?: Position;
45
- }
46
- interface LinkNode {
47
- type: "link";
48
- url: string;
49
- children: InlineNode[];
50
- title?: string;
51
- reference?: string;
52
- position?: Position;
53
- }
54
- interface ImageNode {
55
- type: "image";
56
- alt: string;
57
- url: string;
58
- title?: string;
59
- reference?: string;
60
- position?: Position;
61
- }
62
- type InlineNode = TextNode | CodeSpanNode | HardBreakNode | SoftBreakNode | HtmlInlineNode | EmphasisNode | StrongNode | LinkNode | ImageNode;
63
- interface ThematicBreakNode {
64
- type: "thematicBreak";
65
- marker: "-" | "*" | "_";
66
- position?: Position;
67
- }
68
- interface HeadingNode {
69
- type: "heading";
70
- level: 1 | 2 | 3 | 4 | 5 | 6;
71
- children: InlineNode[];
72
- style: "atx" | "setext";
73
- position?: Position;
74
- }
75
- interface CodeBlockNode {
76
- type: "codeBlock";
77
- value: string;
78
- style: "fenced" | "indented";
79
- lang?: string;
80
- meta?: string;
81
- fence?: "`" | "~";
82
- fenceLength?: number;
83
- position?: Position;
84
- }
85
- interface HtmlBlockNode {
86
- type: "htmlBlock";
87
- value: string;
88
- htmlType: number;
89
- position?: Position;
90
- }
91
- interface ParagraphNode {
92
- type: "paragraph";
93
- children: InlineNode[];
94
- position?: Position;
95
- }
96
- interface LinkReferenceDefinitionNode {
97
- type: "linkReferenceDefinition";
98
- label: string;
99
- url: string;
100
- title?: string;
101
- position?: Position;
102
- }
103
- interface BlockquoteNode {
104
- type: "blockquote";
105
- children: BlockNode[];
106
- position?: Position;
107
- }
108
- interface ListItemNode {
109
- type: "listItem";
110
- children: BlockNode[];
111
- marker: "-" | "*" | "+" | ")" | ".";
112
- spread: boolean;
113
- checked?: boolean;
114
- position?: Position;
115
- }
116
- interface ListNode {
117
- type: "list";
118
- ordered: boolean;
119
- start?: number;
120
- spread: boolean;
121
- marker: "-" | "*" | "+" | ")" | ".";
122
- children: ListItemNode[];
123
- position?: Position;
124
- }
125
- interface TableCellNode {
126
- type: "tableCell";
127
- children: InlineNode[];
128
- align?: "left" | "center" | "right";
129
- isHeader: boolean;
130
- position?: Position;
131
- }
132
- interface TableRowNode {
133
- type: "tableRow";
134
- children: TableCellNode[];
135
- isHeader: boolean;
136
- position?: Position;
137
- }
138
- interface TableNode {
139
- type: "table";
140
- children: TableRowNode[];
141
- align: Array<"left" | "center" | "right" | null>;
142
- position?: Position;
143
- }
144
- type BlockNode = ThematicBreakNode | HeadingNode | CodeBlockNode | HtmlBlockNode | ParagraphNode | LinkReferenceDefinitionNode | BlockquoteNode | ListItemNode | ListNode | TableNode;
145
- interface DocumentNode {
146
- type: "document";
147
- children: BlockNode[];
148
- references?: Record<string, {
149
- type: "linkReferenceDefinition";
150
- label: string;
151
- url: string;
152
- title?: string;
153
- position?: Position;
154
- }>;
155
- position?: Position;
156
- }
157
- interface MarkdownDocument {
158
- root: DocumentNode;
159
- lineEnding: "\n" | "\r\n";
160
- source?: string;
161
- }
162
- declare const textNodeSchema: any;
163
- declare const codeSpanNodeSchema: any;
164
- declare const hardBreakNodeSchema: any;
165
- declare const softBreakNodeSchema: any;
166
- declare const htmlInlineNodeSchema: any;
167
- declare const emphasisNodeSchema: any;
168
- declare const strongNodeSchema: any;
169
- declare const linkNodeSchema: any;
170
- declare const imageNodeSchema: any;
171
- declare const inlineNodeSchema: any;
172
- declare const thematicBreakNodeSchema: any;
173
- declare const headingNodeSchema: any;
174
- declare const codeBlockNodeSchema: any;
175
- declare const htmlBlockNodeSchema: any;
176
- declare const paragraphNodeSchema: any;
177
- declare const linkReferenceDefinitionSchema: any;
178
- declare const blockquoteNodeSchema: any;
179
- declare const listItemNodeSchema: any;
180
- declare const listNodeSchema: any;
181
- declare const tableCellNodeSchema: any;
182
- declare const tableRowNodeSchema: any;
183
- declare const tableNodeSchema: any;
184
- declare const blockNodeSchema: any;
185
- declare const documentNodeSchema: any;
186
- declare const markdownDocumentSchema: any;
187
- /**
188
- * Parse options.
189
- */
190
- declare const parseOptionsSchema: any;
191
- type ParseOptions = z.input<typeof parseOptionsSchema>;
192
- /**
193
- * Generate options.
194
- */
195
- declare const generateOptionsSchema: any;
196
- type GenerateOptions = z.input<typeof generateOptionsSchema>;
197
- /**
198
- * Stream options.
199
- */
200
- declare const streamOptionsSchema: any;
201
- type StreamOptions = z.input<typeof streamOptionsSchema>;
202
- interface BlockStreamEvent {
203
- type: "block";
204
- data: BlockNode;
205
- }
206
- interface CompleteStreamEvent {
207
- type: "complete";
208
- document: MarkdownDocument;
209
- }
210
- interface ErrorStreamEvent {
211
- type: "error";
212
- error: string;
213
- }
214
- type StreamEvent = BlockStreamEvent | CompleteStreamEvent | ErrorStreamEvent;
215
- interface BatchMarkdownFileInput {
216
- filename: string;
217
- content: string;
218
- }
219
- interface FileStartEvent {
220
- type: "file_start";
221
- fileIndex: number;
222
- filename: string;
223
- }
224
- interface FileCompleteEvent {
225
- type: "file_complete";
226
- fileIndex: number;
227
- filename: string;
228
- document: MarkdownDocument;
229
- }
230
- interface FileErrorEvent {
231
- type: "file_error";
232
- fileIndex: number;
233
- filename: string;
234
- error: string;
235
- }
236
- interface BatchBlockEvent {
237
- type: "block";
238
- fileIndex: number;
239
- data: BlockNode;
240
- }
241
- interface BatchCompleteEvent {
242
- type: "batch_complete";
243
- totalFiles: number;
244
- errorCount: number;
245
- }
246
- type BatchMarkdownStreamEvent = FileStartEvent | FileCompleteEvent | FileErrorEvent | BatchBlockEvent | BatchCompleteEvent;
247
- interface BatchMarkdownFileResult {
248
- filename: string;
249
- document?: MarkdownDocument;
250
- error?: string;
251
- }
252
- /** Alias for LinkReferenceDefinitionNode */
253
- type LinkReferenceDefinition = LinkReferenceDefinitionNode;
254
- /** Alias for BatchMarkdownFileResult */
255
- type BatchParsedMarkdownFile = BatchMarkdownFileResult;
256
- /** Union type for any node */
257
- type Node = InlineNode | BlockNode | DocumentNode;
258
- /** Nodes that contain a value property */
259
- type LiteralNode = TextNode | CodeSpanNode | HtmlInlineNode | CodeBlockNode | HtmlBlockNode;
260
- /** Nodes that contain children */
261
- type ParentNode = EmphasisNode | StrongNode | LinkNode | HeadingNode | ParagraphNode | BlockquoteNode | ListItemNode | ListNode | TableNode | TableRowNode | TableCellNode | DocumentNode;
262
- /**
263
- * Result type for parse operations that may fail.
264
- */
265
- type ParseResult<T> = {
266
- success: true;
267
- data: T;
268
- } | {
269
- success: false;
270
- error: Error;
271
- };
272
- /**
273
- * Parses markdown content and returns a result object.
274
- *
275
- * @param content - The markdown string to parse
276
- * @param options - Parsing options
277
- * @returns A ParseResult containing either the parsed document or an error
278
- *
279
- * @example
280
- * ```typescript
281
- * const result = parse("# Hello World");
282
- * if (result.success) {
283
- * console.log(result.data.root.children);
284
- * }
285
- * ```
286
- */
287
- declare function parse(content: string, options?: ParseOptions): ParseResult<MarkdownDocument>;
288
- /**
289
- * Parses markdown content and throws on error.
290
- *
291
- * @param content - The markdown string to parse
292
- * @param options - Parsing options
293
- * @returns The parsed markdown document
294
- * @throws Error if parsing fails or options are invalid
295
- *
296
- * @example
297
- * ```typescript
298
- * const doc = parseOrThrow("# Hello World");
299
- * console.log(doc.root.children);
300
- * ```
301
- */
302
- declare function parseOrThrow(content: string, options?: ParseOptions): MarkdownDocument;
303
- /**
304
- * Parses markdown from a buffer with automatic encoding detection.
305
- *
306
- * @param buffer - The buffer containing markdown data
307
- * @param options - Parsing options
308
- * @returns A ParseResult containing either the parsed document or an error
309
- *
310
- * @example
311
- * ```typescript
312
- * const buffer = new Uint8Array([...]);
313
- * const result = parseBuffer(buffer);
314
- * if (result.success) {
315
- * console.log(result.data.root.children);
316
- * }
317
- * ```
318
- */
319
- declare function parseBuffer(buffer: Uint8Array, options?: ParseOptions): ParseResult<MarkdownDocument>;
320
- /**
321
- * Parses markdown from a buffer with automatic encoding detection.
322
- * Throws on error.
323
- *
324
- * @param buffer - The buffer containing markdown data
325
- * @param options - Parsing options
326
- * @returns The parsed markdown document
327
- * @throws Error if parsing fails
328
- *
329
- * @example
330
- * ```typescript
331
- * const buffer = new Uint8Array([...]);
332
- * const doc = parseBufferOrThrow(buffer);
333
- * console.log(doc.root.children);
334
- * ```
335
- */
336
- declare function parseBufferOrThrow(buffer: Uint8Array, options?: ParseOptions): MarkdownDocument;
337
- /**
338
- * Parses markdown and returns just the AST root node.
339
- *
340
- * @param content - The markdown string to parse
341
- * @param options - Parsing options
342
- * @returns The root document node
343
- *
344
- * @example
345
- * ```typescript
346
- * const root = parseToAst("# Hello");
347
- * console.log(root.type); // "document"
348
- * ```
349
- */
350
- declare function parseToAst(content: string, options?: ParseOptions): MarkdownDocument["root"];
351
- /**
352
- * Checks if the given content is valid markdown (doesn't throw during parsing).
353
- *
354
- * @param content - The content to check
355
- * @returns True if the content can be parsed as markdown
356
- *
357
- * @example
358
- * ```typescript
359
- * isValidMarkdown("# Hello"); // true
360
- * isValidMarkdown("anything"); // true (markdown is very permissive)
361
- * ```
362
- */
363
- declare function isValidMarkdown(content: string): boolean;
364
- /**
365
- * Generates markdown string from a document AST.
366
- *
367
- * @param document - The markdown document or root node to convert
368
- * @param options - Generation options
369
- * @returns The generated markdown string
370
- *
371
- * @example
372
- * ```typescript
373
- * const doc = parse("# Hello");
374
- * const markdown = generate(doc);
375
- * console.log(markdown); // "# Hello"
376
- * ```
377
- */
378
- declare function generate(document: MarkdownDocument | DocumentNode, options?: GenerateOptions): string;
379
- /**
380
- * Generates markdown string from any AST node.
381
- *
382
- * @param node - The node to convert
383
- * @param options - Generation options
384
- * @returns The generated markdown string
385
- *
386
- * @example
387
- * ```typescript
388
- * const node: HeadingNode = { type: "heading", level: 1, children: [...], style: "atx" };
389
- * const markdown = generateNode(node);
390
- * ```
391
- */
392
- declare function generateNode(node: Node, options?: GenerateOptions): string;
393
- /**
394
- * Creates an incremental markdown generator.
395
- *
396
- * @param options - Generation options
397
- * @returns A generator object with methods to add nodes
398
- *
399
- * @example
400
- * ```typescript
401
- * const gen = createGenerator();
402
- * gen.addNode({ type: "heading", level: 1, children: [...], style: "atx" });
403
- * gen.addNode({ type: "paragraph", children: [...] });
404
- * console.log(gen.toString());
405
- * ```
406
- */
407
- declare function createGenerator(options?: GenerateOptions): {
408
- addNode: (node: Node) => void;
409
- toString: () => string;
410
- toStream: () => ReadableStream<string>;
411
- };
412
- /**
413
- * Generates a heading string.
414
- *
415
- * @param level - Heading level (1-6)
416
- * @param text - Heading text
417
- * @param style - Heading style (atx or setext)
418
- * @returns The generated heading
419
- *
420
- * @example
421
- * ```typescript
422
- * generateHeadingString(1, "Hello"); // "# Hello"
423
- * generateHeadingString(2, "World", "setext"); // "World\n------"
424
- * ```
425
- */
426
- declare function generateHeadingString(level: 1 | 2 | 3 | 4 | 5 | 6, text: string, style?: "atx" | "setext"): string;
427
- /**
428
- * Generates a link string.
429
- *
430
- * @param text - Link text
431
- * @param url - Link URL
432
- * @param title - Optional link title
433
- * @returns The generated link
434
- *
435
- * @example
436
- * ```typescript
437
- * generateLinkString("Example", "https://example.com"); // "[Example](https://example.com)"
438
- * ```
439
- */
440
- declare function generateLinkString(text: string, url: string, title?: string): string;
441
- /**
442
- * Generates an image string.
443
- *
444
- * @param alt - Alt text
445
- * @param url - Image URL
446
- * @param title - Optional image title
447
- * @returns The generated image
448
- *
449
- * @example
450
- * ```typescript
451
- * generateImageString("Logo", "logo.png"); // "![Logo](logo.png)"
452
- * ```
453
- */
454
- declare function generateImageString(alt: string, url: string, title?: string): string;
455
- /**
456
- * Generates a code block string.
457
- *
458
- * @param code - The code content
459
- * @param lang - Optional language identifier
460
- * @param style - Code block style (fenced or indented)
461
- * @returns The generated code block
462
- *
463
- * @example
464
- * ```typescript
465
- * generateCodeBlockString("console.log('hi');", "js");
466
- * // "```js\nconsole.log('hi');\n```"
467
- * ```
468
- */
469
- declare function generateCodeBlockString(code: string, lang?: string, style?: "fenced" | "indented"): string;
470
- /**
471
- * Generates a list string from items.
472
- *
473
- * @param items - List items (strings or nested lists)
474
- * @param ordered - Whether the list is ordered
475
- * @param start - Starting number for ordered lists
476
- * @returns The generated list
477
- *
478
- * @example
479
- * ```typescript
480
- * generateListString(["First", "Second"]); // "- First\n- Second"
481
- * generateListString(["First", "Second"], true); // "1. First\n2. Second"
482
- * ```
483
- */
484
- declare function generateListString(items: string[], ordered?: boolean, start?: number): string;
485
- /**
486
- * Generates a blockquote string.
487
- *
488
- * @param content - The content to quote
489
- * @returns The generated blockquote
490
- *
491
- * @example
492
- * ```typescript
493
- * generateBlockquoteString("Hello world"); // "> Hello world"
494
- * ```
495
- */
496
- declare function generateBlockquoteString(content: string): string;
497
- /**
498
- * Wraps text with emphasis markers.
499
- *
500
- * @param text - The text to emphasize
501
- * @param marker - The emphasis marker (* or _)
502
- * @returns The emphasized text
503
- *
504
- * @example
505
- * ```typescript
506
- * generateEmphasisString("hello"); // "*hello*"
507
- * ```
508
- */
509
- declare function generateEmphasisString(text: string, marker?: "*" | "_"): string;
510
- /**
511
- * Wraps text with strong emphasis markers.
512
- *
513
- * @param text - The text to emphasize
514
- * @param marker - The strong marker (** or __)
515
- * @returns The strongly emphasized text
516
- *
517
- * @example
518
- * ```typescript
519
- * generateStrongString("hello"); // "**hello**"
520
- * ```
521
- */
522
- declare function generateStrongString(text: string, marker?: "**" | "__"): string;
523
- /**
524
- * Wraps text in inline code.
525
- *
526
- * @param text - The text to wrap
527
- * @returns The inline code
528
- *
529
- * @example
530
- * ```typescript
531
- * generateInlineCodeString("foo"); // "`foo`"
532
- * ```
533
- */
534
- declare function generateInlineCodeString(text: string): string;
535
- /**
536
- * Generates a GFM table string from headers, rows, and optional alignment.
537
- *
538
- * @param headers - Array of column header strings
539
- * @param rows - 2D array of cell values
540
- * @param alignments - Optional array of alignment values ('left' | 'center' | 'right')
541
- * @returns The generated table markdown
542
- *
543
- * @example
544
- * ```typescript
545
- * generateTableString(
546
- * ["Name", "Age"],
547
- * [["Alice", "30"], ["Bob", "25"]]
548
- * );
549
- * // "| Name | Age |\n| --- | --- |\n| Alice | 30 |\n| Bob | 25 |"
550
- * ```
551
- */
552
- declare function generateTableString(headers: string[], rows: string[][], alignments?: ("left" | "center" | "right" | null)[]): string;
553
- /**
554
- * Generates a task list (checklist) string.
555
- *
556
- * @param items - Array of items with text and optional checked state
557
- * @returns The generated task list markdown
558
- *
559
- * @example
560
- * ```typescript
561
- * generateTaskListString([
562
- * { text: "Buy groceries", checked: true },
563
- * { text: "Walk the dog", checked: false },
564
- * ]);
565
- * // "- [x] Buy groceries\n- [ ] Walk the dog"
566
- * ```
567
- */
568
- declare function generateTaskListString(items: Array<{
569
- text: string;
570
- checked?: boolean;
571
- }>): string;
572
- /**
573
- * Wraps text with strikethrough markers (GFM extension).
574
- *
575
- * @param text - The text to strike through
576
- * @returns The strikethrough text
577
- *
578
- * @example
579
- * ```typescript
580
- * generateStrikethroughString("deleted"); // "~~deleted~~"
581
- * ```
582
- */
583
- declare function generateStrikethroughString(text: string): string;
584
- /**
585
- * Options for HTML rendering.
586
- */
587
- interface HtmlRenderOptions {
588
- /** Whether to sanitize raw HTML blocks/inline (default: true) */
589
- sanitizeHtml?: boolean;
590
- /** Whether to add target="_blank" to external links (default: false) */
591
- externalLinksNewTab?: boolean;
592
- /** Custom class prefix for elements (default: none) */
593
- classPrefix?: string;
594
- /** Whether to render soft breaks as <br> (default: false) */
595
- softBreakAsBr?: boolean;
596
- /** Custom URL transformer for links and images */
597
- transformUrl?: (url: string, type: "link" | "image") => string;
598
- /** Custom attributes to add to specific elements */
599
- elementAttributes?: {
600
- link?: Record<string, string>;
601
- image?: Record<string, string>;
602
- codeBlock?: Record<string, string>;
603
- heading?: Record<string, string>;
604
- };
605
- }
606
- /**
607
- * Renders a markdown document to HTML string.
608
- *
609
- * @param document - The markdown document or root node
610
- * @param options - Rendering options
611
- * @returns The generated HTML string
612
- *
613
- * @example
614
- * ```typescript
615
- * const doc = parse("# Hello **World**");
616
- * const html = renderToHtml(doc);
617
- * // => "<h1>Hello <strong>World</strong></h1>"
618
- * ```
619
- */
620
- declare function renderToHtml(document: MarkdownDocument | DocumentNode, options?: HtmlRenderOptions): string;
621
- /**
622
- * Renders any AST node to HTML string.
623
- *
624
- * @param node - The node to render
625
- * @param options - Rendering options
626
- * @returns The generated HTML string
627
- */
628
- declare function renderNodeToHtml(node: Node, options?: HtmlRenderOptions): string;
629
- /**
630
- * Options for HTML to Markdown conversion
631
- */
632
- interface HtmlToMarkdownOptions {
633
- /** Keep original whitespace (default: false) */
634
- preserveWhitespace?: boolean;
635
- /** Heading style: "atx" (#) or "setext" (===) (default: "atx") */
636
- headingStyle?: "atx" | "setext";
637
- /** Unordered list marker (default: "-") */
638
- bulletMarker?: "-" | "*" | "+";
639
- /** Code block style (default: "fenced") */
640
- codeBlockStyle?: "fenced" | "indented";
641
- /** Fence character (default: "`") */
642
- fence?: "`" | "~";
643
- /** Strong marker (default: "**") */
644
- strongMarker?: "**" | "__";
645
- /** Emphasis marker (default: "*") */
646
- emphasisMarker?: "*" | "_";
647
- /** Link style (default: "inline") */
648
- linkStyle?: "inline" | "reference";
649
- }
650
- /** Intermediate HTML node representation */
651
- interface HtmlNode {
652
- type: "element" | "text" | "comment";
653
- tag?: string;
654
- attributes?: Record<string, string>;
655
- children?: HtmlNode[];
656
- content?: string;
657
- }
658
- /**
659
- * Parse HTML string into an intermediate AST
660
- */
661
- declare function parseHtml(html: string): HtmlNode[];
662
- /**
663
- * Convert HTML AST to Markdown AST
664
- */
665
- declare function htmlAstToMarkdownAst(nodes: HtmlNode[], options?: HtmlToMarkdownOptions): DocumentNode;
666
- /**
667
- * Convert HTML string to Markdown string
668
- *
669
- * @param html - The HTML content to convert
670
- * @param options - Conversion options
671
- * @returns Markdown string
672
- *
673
- * @example
674
- * ```typescript
675
- * const html = '<h1>Hello</h1><p>This is <strong>bold</strong> text.</p>';
676
- * const markdown = htmlToMarkdown(html);
677
- * // Result: "# Hello\n\nThis is **bold** text."
678
- * ```
679
- */
680
- declare function htmlToMarkdown(html: string, options?: HtmlToMarkdownOptions): string;
681
- /**
682
- * Parses markdown content from a stream, yielding events for each block.
683
- *
684
- * @param input - A ReadableStream of Uint8Array or AsyncIterable of strings
685
- * @param options - Parsing options
686
- * @yields StreamEvent for each block and completion
687
- *
688
- * @example
689
- * ```typescript
690
- * const response = await fetch("doc.md");
691
- * for await (const event of parseStream(response.body)) {
692
- * if (event.type === "block") {
693
- * console.log(event.data.type);
694
- * }
695
- * }
696
- * ```
697
- */
698
- declare function parseStream(input: ReadableStream<Uint8Array> | AsyncIterable<string>, options?: StreamOptions): AsyncGenerator<StreamEvent>;
699
- /**
700
- * Parses markdown content from a stream and collects all blocks into a document.
701
- *
702
- * @param input - A ReadableStream of Uint8Array or AsyncIterable of strings
703
- * @param options - Parsing options
704
- * @returns A promise that resolves to the complete MarkdownDocument
705
- *
706
- * @example
707
- * ```typescript
708
- * const response = await fetch("doc.md");
709
- * const doc = await parseStreamToDocument(response.body);
710
- * console.log(doc.root.children.length);
711
- * ```
712
- */
713
- declare function parseStreamToDocument(input: ReadableStream<Uint8Array> | AsyncIterable<string>, options?: StreamOptions): Promise<MarkdownDocument>;
714
- /**
715
- * Creates a streaming parser from a buffer.
716
- * Useful when you have a buffer but want to use the streaming API.
717
- *
718
- * @param buffer - The buffer containing markdown data
719
- * @param options - Parsing options
720
- * @yields StreamEvent for each block and completion
721
- */
722
- declare function parseBufferStream(buffer: Uint8Array, options?: StreamOptions): AsyncGenerator<StreamEvent>;
723
- /**
724
- * Streaming batch parser - processes files sequentially, yielding events.
725
- *
726
- * @param files - Array of files with filename and content
727
- * @param options - Stream options
728
- * @yields BatchMarkdownStreamEvent for each file start, block, completion, or error
729
- *
730
- * @example
731
- * ```typescript
732
- * const files = [
733
- * { filename: "readme.md", content: "# Hello" },
734
- * { filename: "docs.md", content: "## World" }
735
- * ];
736
- * for await (const event of parseBatchStream(files)) {
737
- * console.log(event.type, event.filename);
738
- * }
739
- * ```
740
- */
741
- declare function parseBatchStream(files: BatchMarkdownFileInput[], options?: StreamOptions): AsyncGenerator<BatchMarkdownStreamEvent>;
742
- /**
743
- * Convenience function that collects streaming batch results into arrays.
744
- *
745
- * @param files - Array of files with filename and content
746
- * @param options - Stream options
747
- * @returns Array of parsed file results
748
- */
749
- declare function parseBatchStreamToArray(files: BatchMarkdownFileInput[], options?: StreamOptions): Promise<BatchParsedMarkdownFile[]>;
750
- /**
751
- * Normalizes line endings to LF.
752
- *
753
- * @param content - The content to normalize
754
- * @returns The content with normalized line endings
755
- */
756
- declare function normalizeLineEndings(content: string): string;
757
- /**
758
- * Normalizes escaped newline sequences to actual newlines.
759
- * Handles AI-generated content that may contain literal \n strings
760
- * instead of actual newline characters.
761
- *
762
- * @param content - The content to normalize
763
- * @returns The content with escaped newlines converted to actual newlines
764
- */
765
- declare function normalizeEscapedNewlines(content: string): string;
766
- /**
767
- * Normalizes markdown by unescaping incorrectly escaped emphasis markers.
768
- * LLMs sometimes escape ** or * markers that shouldn't be escaped.
769
- *
770
- * @param text - The markdown text to normalize
771
- * @returns The normalized text with unescaped emphasis markers
772
- *
773
- * @example
774
- * ```typescript
775
- * normalizeMarkdownEmphasis("\\*\\*bold\\*\\*"); // "**bold**"
776
- * normalizeMarkdownEmphasis("\\*italic\\*"); // "*italic*"
777
- * ```
778
- */
779
- declare function normalizeMarkdownEmphasis(text: string): string;
780
- export { thematicBreakNodeSchema, textNodeSchema, tableRowNodeSchema, tableNodeSchema, tableCellNodeSchema, strongNodeSchema, streamOptionsSchema, softBreakNodeSchema, renderToHtml, renderNodeToHtml, positionSchema, parseToAst, parseStreamToDocument, parseStream, parseOrThrow, parseOptionsSchema, parseHtml, parseBufferStream, parseBufferOrThrow, parseBuffer, parseBatchStreamToArray, parseBatchStream, parse, paragraphNodeSchema, normalizeMarkdownEmphasis, normalizeLineEndings, normalizeEscapedNewlines, markdownDocumentSchema, listNodeSchema, listItemNodeSchema, linkReferenceDefinitionSchema, linkNodeSchema, isValidMarkdown, inlineNodeSchema, imageNodeSchema, htmlToMarkdown, htmlInlineNodeSchema, htmlBlockNodeSchema, htmlAstToMarkdownAst, headingNodeSchema, hardBreakNodeSchema, generateTaskListString, generateTableString, generateStrongString, generateStrikethroughString, generateOptionsSchema, generateNode, generateListString, generateLinkString, generateInlineCodeString, generateImageString, generateHeadingString, generateEmphasisString, generateCodeBlockString, generateBlockquoteString, generate, emphasisNodeSchema, documentNodeSchema, createGenerator, codeSpanNodeSchema, codeBlockNodeSchema, blockquoteNodeSchema, blockNodeSchema, ThematicBreakNode, TextNode, TableRowNode, TableNode, TableCellNode, StrongNode, StreamOptions, StreamEvent, SoftBreakNode, Position, ParseResult, ParseOptions, ParentNode, ParagraphNode, Node, MarkdownDocument, LiteralNode, ListNode, ListItemNode, LinkReferenceDefinition, LinkNode, InlineNode, ImageNode, HtmlToMarkdownOptions, HtmlRenderOptions, HtmlInlineNode, HtmlBlockNode, HeadingNode, HardBreakNode, GenerateOptions, EmphasisNode, DocumentNode, DEFAULT_MAX_BUFFER_SIZE, CodeSpanNode, CodeBlockNode, BlockquoteNode, BlockNode, BatchParsedMarkdownFile, BatchMarkdownStreamEvent, BatchMarkdownFileInput };
1
+ export { isValidMarkdown, parse, parseBuffer, parseBufferOrThrow, parseOrThrow, parseToAst, } from "./parser";
2
+ export { createGenerator, generate, generateBlockquoteString, generateCodeBlockString, generateEmphasisString, generateHeadingString, generateImageString, generateInlineCodeString, generateLinkString, generateListString, generateNode, generateStrikethroughString, generateStrongString, generateTableString, generateTaskListString, } from "./generator";
3
+ export type { HtmlRenderOptions } from "./html-renderer";
4
+ export { renderNodeToHtml, renderToHtml } from "./html-renderer";
5
+ export type { HtmlToMarkdownOptions } from "./html-parser";
6
+ export { htmlAstToMarkdownAst, htmlToMarkdown, parseHtml, } from "./html-parser";
7
+ export { parseBatchStream, parseBatchStreamToArray, parseBufferStream, parseStream, parseStreamToDocument, } from "./stream";
8
+ export { blockNodeSchema, blockquoteNodeSchema, codeBlockNodeSchema, codeSpanNodeSchema, DEFAULT_MAX_BUFFER_SIZE, documentNodeSchema, emphasisNodeSchema, generateOptionsSchema, hardBreakNodeSchema, headingNodeSchema, htmlBlockNodeSchema, htmlInlineNodeSchema, imageNodeSchema, inlineNodeSchema, linkNodeSchema, linkReferenceDefinitionSchema, listItemNodeSchema, listNodeSchema, markdownDocumentSchema, paragraphNodeSchema, parseOptionsSchema, positionSchema, softBreakNodeSchema, streamOptionsSchema, strongNodeSchema, tableCellNodeSchema, tableNodeSchema, tableRowNodeSchema, textNodeSchema, thematicBreakNodeSchema, } from "./schemas";
9
+ export type { BatchMarkdownFileInput, BatchMarkdownStreamEvent, BatchParsedMarkdownFile, BlockNode, BlockquoteNode, CodeBlockNode, CodeSpanNode, DocumentNode, EmphasisNode, GenerateOptions, HardBreakNode, HeadingNode, HtmlBlockNode, HtmlInlineNode, ImageNode, InlineNode, LinkNode, LinkReferenceDefinition, ListItemNode, ListNode, LiteralNode, MarkdownDocument, Node, ParagraphNode, ParentNode, ParseOptions, Position, SoftBreakNode, StreamEvent, StreamOptions, StrongNode, TableCellNode, TableNode, TableRowNode, TextNode, ThematicBreakNode, } from "./schemas";
10
+ export type { ParseResult } from "./types";
11
+ export { normalizeEscapedNewlines, normalizeLineEndings, normalizeMarkdownEmphasis, } from "./utils";
12
+ //# sourceMappingURL=index.d.ts.map