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; /** Obsidian vault context enabling wikilink rewriting; without it wikilink text is preserved */ obsidianVault?: ObsidianVaultContext; } /** * Vault-wide context a wikilink rewrite needs. * * Obsidian resolves [[Note]] by basename across the whole vault, so deciding what a rewritten * wikilink should say depends on stem uniqueness across every note, not on the two files joined by * the move. * * @category Core */ export interface ObsidianVaultContext { /** Absolute path of the vault root, the base for path-qualified rewrites */ vaultRoot: string; /** How many markdown files carry each note stem (basename without .md) before the move */ noteStemCounts: Map; } /** * 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; /** Update links in a file when another file has been moved (with provided content) */ refactorLinksForFileMoveWithContent(file: ParsedMarkdownFile, movedFilePath: string, newFilePath: string, content: string): LinkRefactorResult; /** Update links when the current file is being moved */ refactorLinksForCurrentFileMove(file: ParsedMarkdownFile, newFilePath: string, movedPaths?: Map): Promise; /** Update links when the current file is being moved (with provided content) */ refactorLinksForCurrentFileMoveWithContent(file: ParsedMarkdownFile, newFilePath: string, content: string, movedPaths?: Map): LinkRefactorResult; /** Update a single link when a target file has been moved */ private updateLinkForMovedFile; /** * Update a wikilink or embed whose target moved. * * A wikilink resolves by note basename vault-wide, so a move that keeps the basename needs no * rewrite at all -- the link still resolves. A rename rewrites to the shortest unambiguous form: * the bare stem when exactly one note carries it, otherwise the vault-relative path, matching * what Obsidian itself generates. Without vault context (obsidian mode off) the link text is * preserved as-is. */ private updateWikilinkForMovedFile; /** Update a link when the source file (containing the link) is being moved */ private updateLinkForSourceFileMove; /** * Ensure a rewritten same-directory path keeps an explicit ./ prefix, matching the bystander * update convention so both rewrite passes converge on identical output. The path must already be * in unix form, as markdown links always use forward slashes. */ private ensureRelativePrefix; 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; } //# sourceMappingURL=link-refactorer.d.ts.map