Skip to content

Conversation

@jackchuka
Copy link
Owner

This pull request introduces support for expression-based heading matching in the schema, allowing dynamic validation of Markdown heading structure using boolean expressions. It adds a new expr field to heading patterns, updates the validation logic to handle expressions, and expands the documentation and tests to cover these new features. Several internal APIs and utilities were also updated to support expression-based matching.

Expression-based heading matching:

  • Added an expr field to the HeadingPattern schema, allowing boolean expressions (e.g., "slug(filename) == slug(heading)") for dynamic heading validation. The schema, JSON schema, and documentation were all updated to describe this new field, available functions, and variables. [1] [2] [3] [4]
  • Implemented expression evaluation for heading matching using the expr-lang/expr library. The new MatchesHeading method in PatternMatcher handles expressions, and the builder/validator now passes the document filename for context. [1] [2] [3] [4] [5] [6] [7]

Validation logic improvements:

  • Updated structure validation logic to use expression-based matching when expr is present, including improved error messages that show the evaluated expression and variables for easier debugging. [1] [2] [3] [4] [5]

Testing:

  • Added comprehensive tests for expression-based heading matching, covering scenarios like slug matching, prefix trimming, combined expression and pattern, and exact matches.

Internal API consistency:

  • Promoted generateSlug to an exported function GenerateSlug for use in expression evaluation and updated all references accordingly. [1] [2] [3]

@jackchuka jackchuka marked this pull request as ready for review January 30, 2026 13:26
@jackchuka jackchuka merged commit 1aa73cb into main Jan 30, 2026
2 checks passed
@jackchuka jackchuka deleted the feat/rule/heading_filename branch January 30, 2026 13:26
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.

2 participants