markmv - v1.41.7
    Preparing search index...

    Class LinkRefactorer

    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.

    Basic link refactoring

      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`);

    Bulk refactoring with path mapping

      const pathMap = new Map([
    ['docs/old.md', 'guides/new.md'],
    ['api/legacy.md', 'reference/current.md']
    ]);

    const result = await refactorer.refactorLinksWithMapping(
    parsedFile,
    pathMap
    );
    Index
    • Updates the links inside a file that is itself being moved, so they still reach their targets from the new location. Reads the file from disk, does not write it, and records per-link failures in the result instead of throwing.

      Parameters

      • file: ParsedMarkdownFile

        Parsed file that is being moved.

      • newFilePath: string

        Path the file will be moved to.

      • OptionalmovedPaths: Map<string, string>

        Map of old to new paths for other files moved in the same operation, so links to them are rewritten to their new locations.

      Returns Promise<LinkRefactorResult>

      The rewritten content, the changes made and any per-link errors.