markmv
Version:
TypeScript CLI for markdown file operations with intelligent link refactoring
122 lines • 3.75 kB
TypeScript
import type { OperationOptions } from '../types/operations.js';
/**
* Configuration options for TOC generation operations.
*
* Controls how table of contents is generated and inserted into markdown files.
*
* @category Commands
*/
export interface TocOperationOptions extends OperationOptions {
/** Minimum heading level to include in TOC (1-6) */
minDepth: number;
/** Maximum heading level to include in TOC (1-6) */
maxDepth: number;
/** Include line numbers in TOC entries */
includeLineNumbers: boolean;
/** Position where to insert TOC: 'top' | 'after-title' | 'before-content' | 'replace' */
position: 'top' | 'after-title' | 'before-content' | 'replace';
/** Custom TOC title (default: "Table of Contents") */
title: string;
/** TOC heading level (1-6, default: 2) */
headingLevel: number;
/** Custom marker to find existing TOC for replacement */
marker?: string;
/** Skip files that don't have any headings */
skipEmpty: boolean;
}
/**
* CLI-specific options for the toc command.
*
* @category Commands
*/
export interface TocCliOptions extends Omit<TocOperationOptions, 'position'> {
/** Position where to insert TOC */
position?: string;
/** Output results in JSON format */
json?: boolean;
}
/**
* Result of a TOC generation operation.
*
* @category Commands
*/
export interface TocResult {
/** Number of files processed */
filesProcessed: number;
/** Number of files modified */
filesModified: number;
/** Number of files skipped (no headings) */
filesSkipped: number;
/** Files that had processing errors */
fileErrors: Array<{
file: string;
error: string;
}>;
/** Processing time in milliseconds */
processingTime: number;
/** Details of each file processed */
fileDetails: Array<{
file: string;
headingsFound: number;
tocGenerated: boolean;
tocLength: number;
position: string;
}>;
}
/**
* Generate and insert table of contents into markdown files.
*
* Analyzes markdown files to extract headings and generates a formatted table of contents that can
* be inserted at various positions within the file.
*
* @example
* Basic TOC generation
* ```typescript
* const result = await generateToc(['README.md'], {
* position: 'after-title',
* minDepth: 2,
* maxDepth: 4
* });
*
* console.log(`Added TOC to ${result.filesModified} files`);
* ```
*
* @example
* Replace existing TOC
* ```typescript
* const result = await generateToc(['docs/*.md'], {
* position: 'replace',
* marker: '<!-- TOC -->',
* skipEmpty: true
* });
* ```
*
* @param filePaths - Array of file paths to process
* @param options - TOC generation configuration options
*
* @returns Promise resolving to generation results
*/
export declare function generateToc(filePaths: string[], options?: Partial<TocOperationOptions>): Promise<TocResult>;
/**
* CLI command handler for TOC operations.
*
* Processes markdown files to generate and insert table of contents. Supports various positioning
* options and customization.
*
* @example
* ```bash
* # Add TOC to a single file
* markmv toc README.md
*
* # Add TOC to multiple files with custom options
* markmv toc docs/*.md --position after-title --min-depth 2 --max-depth 4
*
* # Replace existing TOC using marker
* markmv toc file.md --position replace --marker "<!-- TOC -->"
* ```;
*
* @param filePaths - Array of file paths to process
* @param cliOptions - CLI-specific options
*/
export declare function tocCommand(filePaths: string[], cliOptions: TocCliOptions): Promise<void>;
//# sourceMappingURL=toc.d.ts.map