@forge-ts/gen 0.7.1 → 0.8.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/dist/index.d.ts +264 -1
- package/dist/index.js +912 -536
- package/dist/index.js.map +1 -1
- package/package.json +10 -2
package/dist/index.d.ts
CHANGED
|
@@ -395,6 +395,269 @@ interface MarkdownOptions {
|
|
|
395
395
|
*/
|
|
396
396
|
declare function generateMarkdown(symbols: ForgeSymbol[], config: ForgeConfig, options?: MarkdownOptions): string;
|
|
397
397
|
|
|
398
|
+
/**
|
|
399
|
+
* Mdast AST node builders and markdown serialization.
|
|
400
|
+
*
|
|
401
|
+
* Provides concise factory functions for constructing mdast trees
|
|
402
|
+
* and a serializer that produces well-formed markdown via remark-stringify.
|
|
403
|
+
*
|
|
404
|
+
* @internal
|
|
405
|
+
*/
|
|
406
|
+
/** Inline leaf node: literal text. */
|
|
407
|
+
interface MdText {
|
|
408
|
+
type: "text";
|
|
409
|
+
value: string;
|
|
410
|
+
}
|
|
411
|
+
/** Inline leaf node: code span. */
|
|
412
|
+
interface MdInlineCode {
|
|
413
|
+
type: "inlineCode";
|
|
414
|
+
value: string;
|
|
415
|
+
}
|
|
416
|
+
/** Inline container: strong emphasis (bold). */
|
|
417
|
+
interface MdStrong {
|
|
418
|
+
type: "strong";
|
|
419
|
+
children: MdPhrasing[];
|
|
420
|
+
}
|
|
421
|
+
/** Inline container: emphasis (italic). */
|
|
422
|
+
interface MdEmphasis {
|
|
423
|
+
type: "emphasis";
|
|
424
|
+
children: MdPhrasing[];
|
|
425
|
+
}
|
|
426
|
+
/** Inline container: hyperlink. */
|
|
427
|
+
interface MdLink {
|
|
428
|
+
type: "link";
|
|
429
|
+
url: string;
|
|
430
|
+
children: MdPhrasing[];
|
|
431
|
+
}
|
|
432
|
+
/** Union of all inline (phrasing) content types. */
|
|
433
|
+
type MdPhrasing = MdText | MdInlineCode | MdStrong | MdEmphasis | MdLink;
|
|
434
|
+
/** Block node: heading (depth 1-6). */
|
|
435
|
+
interface MdHeading {
|
|
436
|
+
type: "heading";
|
|
437
|
+
depth: 1 | 2 | 3 | 4 | 5 | 6;
|
|
438
|
+
children: MdPhrasing[];
|
|
439
|
+
}
|
|
440
|
+
/** Block node: paragraph. */
|
|
441
|
+
interface MdParagraph {
|
|
442
|
+
type: "paragraph";
|
|
443
|
+
children: MdPhrasing[];
|
|
444
|
+
}
|
|
445
|
+
/** Block node: fenced code block. */
|
|
446
|
+
interface MdCode {
|
|
447
|
+
type: "code";
|
|
448
|
+
lang?: string | null;
|
|
449
|
+
value: string;
|
|
450
|
+
}
|
|
451
|
+
/** Block node: blockquote. */
|
|
452
|
+
interface MdBlockquote {
|
|
453
|
+
type: "blockquote";
|
|
454
|
+
children: MdBlock[];
|
|
455
|
+
}
|
|
456
|
+
/** Block node: raw HTML (including comments). */
|
|
457
|
+
interface MdHtml {
|
|
458
|
+
type: "html";
|
|
459
|
+
value: string;
|
|
460
|
+
}
|
|
461
|
+
/** Block node: horizontal rule. */
|
|
462
|
+
interface MdThematicBreak {
|
|
463
|
+
type: "thematicBreak";
|
|
464
|
+
}
|
|
465
|
+
/** List item container. */
|
|
466
|
+
interface MdListItem {
|
|
467
|
+
type: "listItem";
|
|
468
|
+
spread?: boolean;
|
|
469
|
+
children: MdBlock[];
|
|
470
|
+
}
|
|
471
|
+
/** Block node: ordered or unordered list. */
|
|
472
|
+
interface MdList {
|
|
473
|
+
type: "list";
|
|
474
|
+
ordered?: boolean;
|
|
475
|
+
spread?: boolean;
|
|
476
|
+
children: MdListItem[];
|
|
477
|
+
}
|
|
478
|
+
/** GFM table cell. */
|
|
479
|
+
interface MdTableCell {
|
|
480
|
+
type: "tableCell";
|
|
481
|
+
children: MdPhrasing[];
|
|
482
|
+
}
|
|
483
|
+
/** GFM table row. */
|
|
484
|
+
interface MdTableRow {
|
|
485
|
+
type: "tableRow";
|
|
486
|
+
children: MdTableCell[];
|
|
487
|
+
}
|
|
488
|
+
/** GFM table. */
|
|
489
|
+
interface MdTable {
|
|
490
|
+
type: "table";
|
|
491
|
+
align?: ("left" | "center" | "right" | null)[];
|
|
492
|
+
children: MdTableRow[];
|
|
493
|
+
}
|
|
494
|
+
/** Union of all block content types. */
|
|
495
|
+
type MdBlock = MdHeading | MdParagraph | MdCode | MdBlockquote | MdHtml | MdThematicBreak | MdList | MdTable;
|
|
496
|
+
/** Document root. */
|
|
497
|
+
interface MdRoot {
|
|
498
|
+
type: "root";
|
|
499
|
+
children: MdBlock[];
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Concise factory functions for building mdast nodes.
|
|
503
|
+
*
|
|
504
|
+
* Usage:
|
|
505
|
+
* ```typescript
|
|
506
|
+
* const tree = md.root(
|
|
507
|
+
* md.heading(2, md.text("API")),
|
|
508
|
+
* md.table(null,
|
|
509
|
+
* md.tableRow(md.tableCell(md.text("Name")), md.tableCell(md.text("Type"))),
|
|
510
|
+
* md.tableRow(md.tableCell(md.inlineCode("id")), md.tableCell(md.text("string"))),
|
|
511
|
+
* ),
|
|
512
|
+
* );
|
|
513
|
+
* ```
|
|
514
|
+
*/
|
|
515
|
+
declare const md: {
|
|
516
|
+
text: (value: string) => MdText;
|
|
517
|
+
inlineCode: (value: string) => MdInlineCode;
|
|
518
|
+
strong: (...children: MdPhrasing[]) => MdStrong;
|
|
519
|
+
emphasis: (...children: MdPhrasing[]) => MdEmphasis;
|
|
520
|
+
link: (url: string, ...children: MdPhrasing[]) => MdLink;
|
|
521
|
+
heading: (depth: 1 | 2 | 3 | 4 | 5 | 6, ...children: MdPhrasing[]) => MdHeading;
|
|
522
|
+
paragraph: (...children: MdPhrasing[]) => MdParagraph;
|
|
523
|
+
code: (lang: string, value: string) => MdCode;
|
|
524
|
+
blockquote: (...children: MdBlock[]) => MdBlockquote;
|
|
525
|
+
html: (value: string) => MdHtml;
|
|
526
|
+
thematicBreak: () => MdThematicBreak;
|
|
527
|
+
listItem: (...children: MdBlock[]) => MdListItem;
|
|
528
|
+
list: (items: MdListItem[], ordered?: boolean) => MdList;
|
|
529
|
+
tableCell: (...children: MdPhrasing[]) => MdTableCell;
|
|
530
|
+
tableRow: (...cells: MdTableCell[]) => MdTableRow;
|
|
531
|
+
table: (align: ("left" | "center" | "right" | null)[] | null, ...rows: MdTableRow[]) => MdTable;
|
|
532
|
+
root: (...children: MdBlock[]) => MdRoot;
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* Serialize an mdast tree to a well-formed markdown string.
|
|
536
|
+
*
|
|
537
|
+
* Uses remark-stringify with GFM table support. The serializer handles
|
|
538
|
+
* all escaping (pipes in table cells, special characters in text, etc.)
|
|
539
|
+
* so callers never need manual escape functions.
|
|
540
|
+
*
|
|
541
|
+
* @param tree - The mdast root node to serialize.
|
|
542
|
+
* @returns The serialized markdown string.
|
|
543
|
+
*/
|
|
544
|
+
declare function serializeMarkdown(tree: MdRoot): string;
|
|
545
|
+
/**
|
|
546
|
+
* Truncate a string to at most maxLen chars.
|
|
547
|
+
* Avoids cutting inside backtick-delimited code spans to prevent
|
|
548
|
+
* broken inline code that would cause escaping issues.
|
|
549
|
+
*/
|
|
550
|
+
declare function truncate(text: string, maxLen?: number): string;
|
|
551
|
+
/** Convert a label to a GitHub-compatible anchor slug. */
|
|
552
|
+
declare function toAnchor(text: string): string;
|
|
553
|
+
/**
|
|
554
|
+
* Strip extension from a link path and normalize to a slug.
|
|
555
|
+
* Produces bare slug links compatible with Mintlify and most SSGs.
|
|
556
|
+
*/
|
|
557
|
+
declare function slugLink(path: string): string;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Shared markdown/MDX utilities powered by gray-matter and the unified/remark ecosystem.
|
|
561
|
+
*
|
|
562
|
+
* Provides:
|
|
563
|
+
* - Frontmatter parsing and serialization (gray-matter)
|
|
564
|
+
* - AST-aware MDX sanitization (remark-parse + position-based transforms)
|
|
565
|
+
* - AST-aware FORGE:AUTO section updates (remark-parse + position-based splicing)
|
|
566
|
+
*
|
|
567
|
+
* @internal
|
|
568
|
+
*/
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Result of parsing frontmatter from markdown/MDX content.
|
|
572
|
+
* @public
|
|
573
|
+
*/
|
|
574
|
+
interface FrontmatterResult {
|
|
575
|
+
/** The body content without the frontmatter block. */
|
|
576
|
+
body: string;
|
|
577
|
+
/** The parsed frontmatter data as a key-value map. */
|
|
578
|
+
data: Record<string, unknown>;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Parse frontmatter from markdown/MDX content.
|
|
582
|
+
*
|
|
583
|
+
* Uses gray-matter for robust YAML parsing — handles multi-line values,
|
|
584
|
+
* quoted strings, and edge cases that regex-based stripping misses.
|
|
585
|
+
*
|
|
586
|
+
* @param content - The full file content including frontmatter.
|
|
587
|
+
* @returns The body (without frontmatter) and the parsed data object.
|
|
588
|
+
* @public
|
|
589
|
+
*/
|
|
590
|
+
declare function parseFrontmatter(content: string): FrontmatterResult;
|
|
591
|
+
/**
|
|
592
|
+
* Serialize content with frontmatter prepended.
|
|
593
|
+
*
|
|
594
|
+
* Produces the standard format:
|
|
595
|
+
* ```
|
|
596
|
+
* ---
|
|
597
|
+
* key: value
|
|
598
|
+
* ---
|
|
599
|
+
*
|
|
600
|
+
* body
|
|
601
|
+
* ```
|
|
602
|
+
*
|
|
603
|
+
* @param body - The markdown body content (without frontmatter).
|
|
604
|
+
* @param data - The frontmatter fields to serialize.
|
|
605
|
+
* @returns The combined frontmatter + body string.
|
|
606
|
+
* @public
|
|
607
|
+
*/
|
|
608
|
+
declare function stringifyWithFrontmatter(body: string, data: Record<string, string | number | boolean>): string;
|
|
609
|
+
/**
|
|
610
|
+
* Strip frontmatter from content, returning only the body.
|
|
611
|
+
*
|
|
612
|
+
* @param content - The full file content including frontmatter.
|
|
613
|
+
* @returns The body content without the frontmatter block.
|
|
614
|
+
* @public
|
|
615
|
+
*/
|
|
616
|
+
declare function stripFrontmatter(content: string): string;
|
|
617
|
+
/**
|
|
618
|
+
* Parse a markdown string and extract inline (phrasing) content.
|
|
619
|
+
*
|
|
620
|
+
* Use for TSDoc text that may contain backtick code, bold, links, etc.
|
|
621
|
+
* The returned nodes can be spread into paragraphs, table cells, or
|
|
622
|
+
* any other context that accepts inline content.
|
|
623
|
+
*
|
|
624
|
+
* This prevents double-escaping: backticks become proper `inlineCode`
|
|
625
|
+
* nodes instead of text that gets escaped by the serializer.
|
|
626
|
+
*
|
|
627
|
+
* @param markdown - The TSDoc content string (may contain markdown).
|
|
628
|
+
* @returns Array of inline mdast nodes.
|
|
629
|
+
* @public
|
|
630
|
+
*/
|
|
631
|
+
declare function parseInline(markdown: string): MdPhrasing[];
|
|
632
|
+
/**
|
|
633
|
+
* Parse a markdown string and extract block-level content.
|
|
634
|
+
*
|
|
635
|
+
* Use for multi-line TSDoc content that may contain headings,
|
|
636
|
+
* lists, blockquotes, code blocks, etc.
|
|
637
|
+
*
|
|
638
|
+
* @param markdown - The markdown string to parse.
|
|
639
|
+
* @returns Array of block-level mdast nodes.
|
|
640
|
+
* @public
|
|
641
|
+
*/
|
|
642
|
+
declare function parseBlocks(markdown: string): MdBlock[];
|
|
643
|
+
/**
|
|
644
|
+
* Sanitize markdown content for MDX compatibility using AST-aware processing.
|
|
645
|
+
*
|
|
646
|
+
* Parses the document with remark to understand its structure, then applies
|
|
647
|
+
* targeted string replacements only to text and HTML comment nodes —
|
|
648
|
+
* code blocks, inline code, and frontmatter are automatically preserved.
|
|
649
|
+
*
|
|
650
|
+
* Transformations applied outside code:
|
|
651
|
+
* - HTML comments to MDX comments
|
|
652
|
+
* - Curly braces in text escaped (prevents MDX expression parsing)
|
|
653
|
+
* - Angle brackets around word chars escaped (prevents JSX tag parsing)
|
|
654
|
+
*
|
|
655
|
+
* @param content - The markdown content to sanitize.
|
|
656
|
+
* @returns The sanitized content safe for MDX consumption.
|
|
657
|
+
* @public
|
|
658
|
+
*/
|
|
659
|
+
declare function sanitizeForMdx(content: string): string;
|
|
660
|
+
|
|
398
661
|
/** Options controlling README sync behaviour. */
|
|
399
662
|
interface ReadmeSyncOptions {
|
|
400
663
|
/** Include a "Documented with forge-ts" badge above the API table. */
|
|
@@ -555,4 +818,4 @@ interface GenerateOptions {
|
|
|
555
818
|
*/
|
|
556
819
|
declare function generate(config: ForgeConfig, options?: GenerateOptions): Promise<ForgeResult>;
|
|
557
820
|
|
|
558
|
-
export { type AdapterContext, DEFAULT_TARGET, type DevServerCommand, type DocPage, type GenerateOptions, type GeneratedFile, type MarkdownOptions, type ReadmeSyncOptions, type SSGAdapter, type SSGConfigFile, type SSGStyleGuide, type SSGTarget, type ScaffoldManifest, type SiteGeneratorOptions, type SkillPackage, escapeMdx, generate, generateDocSite, generateLlmsFullTxt, generateLlmsTxt, generateMarkdown, generateSSGConfigs, generateSkillMd, generateSkillPackage, getAdapter, getAvailableTargets, groupSymbolsByPackage, registerAdapter, syncReadme };
|
|
821
|
+
export { type AdapterContext, DEFAULT_TARGET, type DevServerCommand, type DocPage, type FrontmatterResult, type GenerateOptions, type GeneratedFile, type MarkdownOptions, type ReadmeSyncOptions, type SSGAdapter, type SSGConfigFile, type SSGStyleGuide, type SSGTarget, type ScaffoldManifest, type SiteGeneratorOptions, type SkillPackage, escapeMdx, generate, generateDocSite, generateLlmsFullTxt, generateLlmsTxt, generateMarkdown, generateSSGConfigs, generateSkillMd, generateSkillPackage, getAdapter, getAvailableTargets, groupSymbolsByPackage, md, parseBlocks, parseFrontmatter, parseInline, registerAdapter, sanitizeForMdx, serializeMarkdown, slugLink, stringifyWithFrontmatter, stripFrontmatter, syncReadme, toAnchor, truncate };
|