Summary
Add support for automatically refactoring heading links when headings are modified in markdown files.
Problem
Currently, markmv can track and update markdown links when files are moved, but it doesn't handle cases where heading content is modified. When headings change:
- Internal anchor links pointing to those headings become broken
- Links using heading-based slugs need manual updating
- Cross-file references to specific sections break silently
Current Capabilities
The codebase already has good foundation for this feature:
- TocGenerator (
src/utils/toc-generator.ts) extracts headings and generates slugs
- LinkParser (
src/core/link-parser.ts) identifies anchor links (#heading-slug)
- LinkRefactorer (
src/core/link-refactorer.ts) updates link paths
- Comprehensive link tracking and validation infrastructure
Proposed Solution
Add a new command and capability:
CLI Interface
# Refactor headings in a file
markmv refactor-headings file.md --old-heading "Original Heading" --new-heading "Updated Heading"
# Refactor headings across multiple files
markmv refactor-headings docs/ --old-heading "API Reference" --new-heading "API Documentation" --recursive
Implementation Approach
- Heading Detection: Use existing
TocGenerator to extract current headings
- Link Analysis: Use existing
LinkParser to find anchor links
- Slug Matching: Match old heading slugs to anchor links across files
- Link Updates: Use existing
LinkRefactorer patterns to update references
- Validation: Ensure all heading references are updated consistently
Features
Example Use Cases
- Documentation Reorganization: Renaming sections and updating all references
- Content Migration: Moving headings between files while preserving links
- Consistency Enforcement: Standardizing heading formats across documentation
- Refactoring Support: Updating technical documentation when code structure changes
Benefits
- Maintains link integrity during content reorganization
- Reduces manual effort in large documentation projects
- Leverages existing markmv infrastructure and patterns
- Provides safe operations with dry-run and rollback capabilities
Related Files
src/utils/toc-generator.ts - Heading extraction and slug generation
src/core/link-parser.ts - Link parsing and anchor detection
src/core/link-refactorer.ts - Link updating infrastructure
src/commands/ - Command structure patterns
This feature would extend markmv's excellent file movement capabilities to heading-level refactoring while maintaining the same quality standards and safety features.
Summary
Add support for automatically refactoring heading links when headings are modified in markdown files.
Problem
Currently, markmv can track and update markdown links when files are moved, but it doesn't handle cases where heading content is modified. When headings change:
Current Capabilities
The codebase already has good foundation for this feature:
src/utils/toc-generator.ts) extracts headings and generates slugssrc/core/link-parser.ts) identifies anchor links (#heading-slug)src/core/link-refactorer.ts) updates link pathsProposed Solution
Add a new command and capability:
CLI Interface
Implementation Approach
TocGeneratorto extract current headingsLinkParserto find anchor linksLinkRefactorerpatterns to update referencesFeatures
#old-heading→#new-heading)TocGenerator.slugify)TransactionManagerExample Use Cases
Benefits
Related Files
src/utils/toc-generator.ts- Heading extraction and slug generationsrc/core/link-parser.ts- Link parsing and anchor detectionsrc/core/link-refactorer.ts- Link updating infrastructuresrc/commands/- Command structure patternsThis feature would extend markmv's excellent file movement capabilities to heading-level refactoring while maintaining the same quality standards and safety features.