Skip to content

refactor(markdown-parser): hardcoded link/anchor patterns to Strategy Pattern #8

@WesleyMFrederick

Description

@WesleyMFrederick

Problem

Link and anchor extraction uses hardcoded regex patterns scattered throughout extractLinks() and extractAnchors() methods.

Patterns Currently Hardcoded

Type Pattern Code Location
Link [text](file.md#anchor) extractLinks:118
Link [cite: path] extractLinks:165
Link [[file#anchor|text]] extractLinks:266
Link [[#anchor|text]] extractLinks:313
Link [text](#anchor) extractLinks:354
Link ^anchor-id reference extractLinks:395
Anchor ## Header Text extractAnchors:600
Anchor ^block-id extractAnchors:551

Proposed Solution

Refactor to Strategy Pattern (like ExtractionStrategy in ContentExtractor) for:

  • Pluggable pattern registration
  • Easier testing of individual patterns
  • Support for custom/user-defined patterns

Priority

Low - current implementation works; refactor when adding new patterns.


Acceptance Criteria

  • Each link/anchor pattern extracted into its own Strategy class
  • Strategy registry allows adding/removing patterns without modifying core parser
  • All existing link types detected identically to current implementation
  • Individual strategies are independently testable
  • No regression in extraction accuracy or performance

Definition of Done

  • Snapshot tests written: current extraction output captured for all pattern types (RED phase)
  • Strategy interface defined and individual strategies implemented (GREEN phase)
  • Snapshot tests pass with identical output post-refactor
  • All existing citation-manager tests pass
  • Build succeeds: npm run build -w tools/citation-manager && npm link -w tools/citation-manager
  • No measurable performance regression on large files
  • Committed with conventional commit message referencing this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions