markmv
Version:
TypeScript CLI for markdown file operations with intelligent link refactoring
123 lines • 3.39 kB
TypeScript
/**
* Represents a heading extracted from markdown content.
*
* @category Utils
*/
export interface MarkdownHeading {
/** Heading level (1-6) */
level: number;
/** Heading text content */
text: string;
/** Anchor slug for linking */
slug: string;
/** Line number in the source file */
line: number;
}
/**
* Configuration options for table of contents generation.
*
* @category Utils
*/
export interface TocOptions {
/** Minimum heading level to include (default: 1) */
minDepth?: number;
/** Maximum heading level to include (default: 6) */
maxDepth?: number;
/** Include line numbers in output (default: false) */
includeLineNumbers?: boolean;
/** Custom slug generator function */
slugify?: (text: string) => string;
}
/**
* Result of table of contents generation.
*
* @category Utils
*/
export interface TocResult {
/** Generated table of contents markdown */
toc: string;
/** Extracted headings */
headings: MarkdownHeading[];
}
/**
* Utility for generating table of contents from markdown content.
*
* This class extracts headings from markdown content and generates formatted table of contents with
* proper indentation and anchor links.
*
* @category Utils
*
* @example
* Basic usage
* ```typescript
* const generator = new TocGenerator();
* const content = `# Title\n## Section 1\n### Subsection\n## Section 2`;
* const result = await generator.generateToc(content);
*
* console.log(result.toc);
* // Output:
* // - [Title](#title)
* // - [Section 1](#section-1)
* // - [Subsection](#subsection)
* // - [Section 2](#section-2)
* ```
*
* @example
* With custom options
* ```typescript
* const generator = new TocGenerator();
* const options = {
* minDepth: 2,
* maxDepth: 4,
* includeLineNumbers: true
* };
* const result = await generator.generateToc(content, options);
* ```
*/
export declare class TocGenerator {
private processor;
/**
* Generate table of contents from markdown content.
*
* @param content - Markdown content to analyze
* @param options - Configuration options
*
* @returns Promise resolving to TOC result
*/
generateToc(content: string, options?: TocOptions): Promise<TocResult>;
/**
* Extract headings from markdown content without generating TOC.
*
* @param content - Markdown content to analyze
* @param options - Configuration options
*
* @returns Promise resolving to array of headings
*/
extractHeadings(content: string, options?: TocOptions): Promise<MarkdownHeading[]>;
/**
* Format headings into a table of contents string.
*
* @param headings - Array of extracted headings
* @param includeLineNumbers - Whether to include line numbers
*
* @returns Formatted TOC markdown
*/
private formatToc;
/**
* Extract text content from AST nodes recursively.
*
* @param nodes - Array of AST nodes
*
* @returns Combined text content
*/
private extractTextFromNodes;
/**
* Default slugify function that converts text to URL-friendly anchors.
*
* @param text - Text to slugify
*
* @returns URL-friendly slug
*/
private defaultSlugify;
}
//# sourceMappingURL=toc-generator.d.ts.map