markmv - v1.41.7
    Preparing search index...

    Class LinkValidator

    Validates markdown links and identifies broken or problematic references.

    The LinkValidator checks various types of links including internal file references, external URLs, and Claude import syntax. It provides comprehensive reporting of validation issues and supports different validation modes for different use cases.

    Basic link validation

    const validator = new LinkValidator({
    checkExternal: true,
    strictInternal: true,
    externalTimeout: 10000
    });

    const result = await validator.validateFile('docs/api.md');

    if (!result.isValid) {
    console.log(`Found ${result.brokenLinks.length} broken links`);
    result.brokenLinks.forEach(link => {
    console.log(`- ${link.href} (line ${link.line}): ${link.reason}`);
    });
    }

    Batch validation

    const validator = new LinkValidator();
    const files = ['docs/guide.md', 'docs/api.md', 'docs/examples.md'];

    const results = await validator.validateFiles(files);
    const totalBroken = results.reduce((sum, r) => sum + r.brokenLinks.length, 0);
    console.log(`Found ${totalBroken} broken links across ${files.length} files`);
    Index
    • Creates a validator, filling any option left unset with its default: external links unchecked, a 5000 ms external timeout, missing internal files treated as errors, Claude imports checked, freshness and authentication detection off, authentication-required links allowed, wikilinks unchecked, no skipped domains and 2 retries for transient external failures. The freshness and authentication detectors are created only when their option is enabled.

      Parameters

      Returns LinkValidator

    • Checks for circular references. With parsed files, follows each file's dependencies and returns every cycle found as a path of files. With plain path strings there is no dependency information to follow, so the result always reports no circular references.

      Parameters

      Returns Promise<string[][]>

      The cycles for parsed files, or a summary object for paths.

    • Checks for circular references. With parsed files, follows each file's dependencies and returns every cycle found as a path of files. With plain path strings there is no dependency information to follow, so the result always reports no circular references.

      Parameters

      • files: readonly string[]

        Parsed markdown files or file paths to check.

      Returns Promise<{ circularPaths?: string[]; hasCircularReferences: boolean }>

      The cycles for parsed files, or a summary object for paths.

    • Validates one link according to its type and the validator's options. Link types whose checking is disabled, and reference links, are treated as valid. An unexpected failure while checking is reported as an invalid-format broken link rather than thrown.

      Parameters

      • link: Readonly<MarkdownLink>

        Link to check.

      • sourceFile: string

        Path of the file containing the link.

      Returns Promise<BrokenLink | null>

      A broken link description, or null when the link is valid or not checked.

    • Combines link validation with circular reference detection across a set of files.

      Parameters

      Returns Promise<
          {
              brokenLinks: BrokenLink[];
              circularReferences: string[][];
              valid: boolean;
              warnings: string[];
          },
      >

      A result whose valid flag is true only when there are no broken links and no cycles, plus the cycles, the broken links and any warnings.

    • Validates a specific array of links from a single file.

      Parameters

      • links: readonly MarkdownLink[]

        Array of links to validate

      • sourceFile: string

        Path to the source file containing the links

      Returns Promise<{ brokenLinks: BrokenLink[] }>

      Promise resolving to validation result with broken links