UNPKG

markmv

Version:

TypeScript CLI for markdown file operations with intelligent link refactoring

99 lines 3.86 kB
import type { ParsedMarkdownFile } from '../types/links.js'; import type { OperationChange } from '../types/operations.js'; /** * Result of a link refactoring operation. * * Contains the updated content with refactored links and detailed information about the changes * made during the refactoring process. * * @category Core */ export interface LinkRefactorResult { /** Updated content with refactored links */ updatedContent: string; /** Changes made to links */ changes: OperationChange[]; /** Any errors encountered during refactoring */ errors: string[]; } /** * Configuration options for link refactoring operations. * * Controls how links are processed during refactoring, including path conversion, formatting * preservation, and special handling for different link types. * * @category Core */ export interface RefactorOptions { /** Convert absolute paths to relative where possible */ preferRelativePaths?: boolean; /** Update Claude import links */ updateClaudeImports?: boolean; /** Preserve link formatting (brackets, quotes, etc.) */ preserveFormatting?: boolean; } /** * Refactors and updates markdown links when files are moved or restructured. * * The LinkRefactorer automatically updates link paths, maintains referential integrity, and handles * various link types including relative paths, absolute paths, and Claude import syntax. It ensures * that links remain valid after file operations. * * @category Core * * @example * Basic link refactoring * ```typescript * const refactorer = new LinkRefactorer({ * preferRelativePaths: true, * updateClaudeImports: true * }); * * const result = await refactorer.refactorLinks( * parsedFile, * 'old/path/file.md', * 'new/path/file.md' * ); * * console.log(`Updated ${result.changes.length} links`); * ``` * * @example * Bulk refactoring with path mapping * ```typescript * const pathMap = new Map([ * ['docs/old.md', 'guides/new.md'], * ['api/legacy.md', 'reference/current.md'] * ]); * * const result = await refactorer.refactorLinksWithMapping( * parsedFile, * pathMap * ); * ``` */ export declare class LinkRefactorer { private options; constructor(options?: RefactorOptions); /** Update links in a file when another file has been moved */ refactorLinksForFileMove(file: ParsedMarkdownFile, movedFilePath: string, newFilePath: string): Promise<LinkRefactorResult>; /** Update links in a file when another file has been moved (with provided content) */ refactorLinksForFileMoveWithContent(file: ParsedMarkdownFile, movedFilePath: string, newFilePath: string, content: string): Promise<LinkRefactorResult>; /** Update links when the current file is being moved */ refactorLinksForCurrentFileMove(file: ParsedMarkdownFile, newFilePath: string): Promise<LinkRefactorResult>; /** Update links when the current file is being moved (with provided content) */ refactorLinksForCurrentFileMoveWithContent(file: ParsedMarkdownFile, newFilePath: string, content: string): Promise<LinkRefactorResult>; /** Update a single link when a target file has been moved */ private updateLinkForMovedFile; /** Update a link when the source file (containing the link) is being moved */ private updateLinkForSourceFileMove; private updateClaudeImportPath; private updateInternalLinkPath; /** Replace a link in a line of text while preserving formatting */ private replaceLinkInLine; /** Escape special regex characters in a string */ private escapeRegex; /** Update reference-style link definitions */ refactorReferenceDefinitions(file: ParsedMarkdownFile, movedFilePath: string, newFilePath: string): Promise<LinkRefactorResult>; } //# sourceMappingURL=link-refactorer.d.ts.map