Skip to content

Conversation

Mearman
Copy link
Member

@Mearman Mearman commented Jul 30, 2025

Summary

Implements a comprehensive heading refactoring command that allows users to update heading text across multiple markdown files while automatically maintaining link integrity.

Features

  • Heading Text Updates: Updates all instances of specified heading text across files
  • Automatic Slug Generation: Generates URL-friendly anchor slugs using consistent algorithm
  • Anchor Link Updates: Automatically updates all anchor links that reference changed headings
  • Cross-File References: Updates heading references across the entire project
  • Custom Slug Generation: Support for custom slugify functions for specialized use cases
  • Recursive Processing: Process directories recursively with depth control
  • Dry Run Support: Preview changes before applying them
  • Comprehensive Reporting: Detailed reporting of all heading changes and link updates

Implementation Details

  • Added src/commands/refactor-headings.ts with full functionality
  • Leverages existing TocGenerator for consistent slug generation
  • Uses LinkParser for anchor link detection and updates
  • Supports glob patterns and directory processing
  • Comprehensive error handling with graceful degradation

Testing

  • Added 15 comprehensive test cases covering all functionality
  • Integration tests with real filesystem operations
  • Tests for heading updates, link updates, dry-run mode, error handling
  • Custom slug generation and regex escaping edge cases
  • Multi-file processing and cross-reference scenarios

Usage Examples

# Basic heading refactoring
markmv refactor-headings docs/ --old-heading "Getting Started" --new-heading "Quick Start Guide" --recursive

# With custom options
markmv refactor-headings README.md --old-heading "Installation" --new-heading "Setup" --dry-run

# Skip cross-references
markmv refactor-headings **/*.md --old-heading "API" --new-heading "API Reference" --no-update-cross-references

Test Coverage

All tests pass with comprehensive coverage:

  • ✅ Basic heading refactoring with duplicate headings
  • ✅ Multiple heading levels and exact text matching
  • ✅ Anchor link updates with proper slug mapping
  • ✅ Cross-reference update control
  • ✅ Dry-run mode functionality
  • ✅ Multi-file processing
  • ✅ Error handling for missing files
  • ✅ Custom slug generation support
  • ✅ Special character handling in headings
  • ✅ Comprehensive result formatting

Closes #31

- Implements refactor-headings command to update heading text across files
- Automatically updates anchor links when headings change
- Supports custom slug generation with configurable options
- Includes recursive directory processing and cross-file reference updates
- Comprehensive test suite with 15 test cases covering all functionality
- Dry-run support for safe preview of changes
- Detailed reporting of heading changes and link updates

Closes #31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add heading refactoring support
1 participant