UNPKG

markmv

Version:

TypeScript CLI for markdown file operations with intelligent link refactoring

106 lines 3.74 kB
import { type SplitSection } from '../strategies/split-strategies.js'; import type { OperationResult, SplitOperationOptions } from '../types/operations.js'; /** * Result of redistributing links after a content split operation. * * When a markdown file is split into multiple files, links may need to be updated to maintain * proper references. This interface captures the results of that redistribution process. * * @category Core */ export interface LinkRedistributionResult { /** Updated sections with redistributed links */ updatedSections: SplitSection[]; /** Links that need to be updated in external files */ externalLinkUpdates: Array<{ filePath: string; oldHref: string; newHref: string; line: number; }>; /** Any errors during redistribution */ errors: string[]; } /** * Splits large markdown files into smaller, manageable sections using various strategies. * * The ContentSplitter provides intelligent content division with support for header-based, * size-based, manual marker-based, and line-based splitting strategies. It handles link * redistribution, maintains content integrity, and ensures proper cross-references between the * resulting files. * * @category Core * * @example * Header-based splitting * ```typescript * const splitter = new ContentSplitter(); * const result = await splitter.splitFile('large-guide.md', { * strategy: 'headers', * headerLevel: 2, * outputDir: './split-guides/', * preserveLinks: true * }); * * console.log(`Created ${result.createdFiles.length} files`); * ``` * * @example * Size-based splitting * ```typescript * const splitter = new ContentSplitter(); * const result = await splitter.splitFile('large-document.md', { * strategy: 'size', * maxSize: '50KB', * outputDir: './chunks/', * dryRun: true // Preview without creating files * }); * ``` */ export declare class ContentSplitter { private linkParser; /** * Splits a markdown file into multiple smaller files using the specified strategy. * * This method analyzes the source file content and divides it into logical sections based on the * chosen strategy. It handles link redistribution, maintains proper cross-references, and ensures * content integrity across the split files. * * @example * Basic header splitting * ```typescript * const result = await splitter.splitFile('documentation.md', { * strategy: 'headers', * headerLevel: 1, // Split on H1 headers * outputDir: './docs-sections/', * preserveLinks: true * }); * ``` * * @example * Manual marker splitting * ```typescript * const result = await splitter.splitFile('article.md', { * strategy: 'manual', * markers: ['<!-- split -->', '---split---'], * outputDir: './article-parts/' * }); * ``` * * @param sourceFilePath - Path to the markdown file to split * @param options - Configuration options for the split operation * * @returns Promise resolving to operation result with details of created files */ splitFile(sourceFilePath: string, options: SplitOperationOptions): Promise<OperationResult>; private createSplitStrategy; /** Redistribute links across split sections */ private redistributeLinks; private updateLinkForNewLocation; private replaceLinkInLine; /** Find files that reference the source file */ private findExternalReferences; /** Update external files that reference the split file */ private updateExternalFileLinks; } //# sourceMappingURL=content-splitter.d.ts.map