Fix Links Command
Automatically fixes broken anchor links in MDX files based on validation reports.
Usage
writechoice fix links [options]
Options
| Option | Alias | Description | Default |
|---|---|---|---|
--report <path> | -r | Path to JSON validation report | links_report.json |
--quiet | - | Suppress terminal output | false |
How It Works
Reads the JSON report from check links and corrects broken anchor links in your MDX files.
What Gets Fixed
- Anchor links where the target heading exists but uses a different slug
- The report must contain both the incorrect anchor and the correct one
What Doesn't Get Fixed
- Links to non-existent pages or headings
- Links with network errors or timeouts
- External links
Fix Process
- Parses the JSON report to find all fixable failures
- Locates each broken link in the source MDX file by line number
- Replaces the incorrect anchor with the correct one
- Preserves the original link format (markdown, HTML, or JSX)
- Saves the updated file
Examples
# Fix links using default report file
writechoice fix links
# Fix links from custom report file
writechoice fix links -r custom_report.json
# Quiet mode (useful for CI/CD)
writechoice fix links --quiet
Example Fix
<!-- Before (incorrect anchor) -->
[Installation Guide](./installation#setup)
<!-- After (corrected anchor) -->
[Installation Guide](./installation#setup-process)
Recommended Workflow
- Run validation:
writechoice check links https://docs.example.com
- Review
links_report.mdfor a readable summary. - Apply fixes:
writechoice fix links
- Review with
git diff. - Re-validate to confirm.
Safety
- Only modifies the anchor portion of links, not paths
- Preserves link format (markdown/HTML/JSX)
- Idempotent: running twice produces the same result
- Revert with
git checkout .if needed
Troubleshooting
Report file not found:
# Generate the report first
writechoice check links https://docs.example.com
Note: The fix command requires the JSON report file (links_report.json), not the Markdown one.