Skip to content

fix(rust): normalize setext headings to ATX#7

Merged
ttscoff merged 2 commits into
ttscoff:mainfrom
jaredhowland:main
May 25, 2026
Merged

fix(rust): normalize setext headings to ATX#7
ttscoff merged 2 commits into
ttscoff:mainfrom
jaredhowland:main

Conversation

@jaredhowland

Copy link
Copy Markdown
Contributor

Potentially addresses issue #5

New normalization rule for setext headings:

  • Added rule 34 (not that one): "Normalize setext headings to ATX headings" (converts headings using ===/--- underlines to #/## ATX style). This is reflected in the rule list, configuration documentation, and sample config generation. [1] [2] [3] [4] [5] [6] [7]

Implementation in code:

  • Introduced is_setext_heading and normalize_setext_to_atx_headings functions to detect and convert setext headings during file processing. The conversion logic is integrated into the main processing loop, respecting skip rules. [1] [2]

Testing:

  • Added comprehensive tests to ensure setext headings are converted correctly, that horizontal rules are not misinterpreted, and that the rule can be disabled via configuration.

Trade-offs:

  • We intentionally normalize all setext headings to ATX in output. This is a formatting choice that reduces parser ambiguity and yields more predictable downstream rule application, at the cost of not preserving original setext style.
  • Detection is conservative (skips list items, blockquotes, existing headlines, code fences, and blank lines) to avoid broad behavioral changes.

This pull request was aided by Copilot AI but hand-checked.

Setext-style headings were not being normalized, which left
`---` underlines vulnerable to misclassification as a horizontal rule.

This change adds a focused setext detection pass in the main processing loop:
when a normal text line is immediately followed by a setext underline, the pair
is converted to `#`/`##` and the underline line is consumed. The conversion is
positioned before headline/horizontal-rule handling to remove the ambiguity
at the source. Existing horizontal-rule behavior is preserved when there is no
valid setext heading context.

Trade-offs:
- We intentionally normalize all setext headings to ATX in output. This is a
  formatting choice that reduces parser ambiguity and yields more predictable
  downstream rule application, at the cost of not preserving original setext
  style.
- Detection is conservative (skips list items, blockquotes, existing headlines,
  code fences, and blank lines) to avoid broad behavioral changes.

Tests add explicit coverage for:
1)  setext conversion (including the ambiguous three-dash case), and
2) standalone  preservation as a horizontal rule.

This results in the creation of rule 34 (not that one) to convert setext style headings to ATX.
Copilot AI review requested due to automatic review settings May 20, 2026 20:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Rust-side normalization rule to convert Setext-style headings (=== / --- underlines) into ATX headings (# / ##), addressing the Setext/horizontal-rule ambiguity that contributed to issue #5.

Changes:

  • Added rule 34 (setext-to-atx) to the Rust rule registry and integrated Setext-to-ATX conversion into the main per-line processing pipeline.
  • Updated generated config output and README rule documentation to include the new rule.
  • Added Rust tests covering Setext conversion, horizontal-rule non-conversion, and configurability via skipping rule 34.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
rust/src/main.rs Implements rule 34, wires it into processing, updates config init output, and adds tests.
README.md Updates rule count and documents rule 34 in the rules and configuration sections.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rust/src/main.rs Outdated
Comment thread rust/src/main.rs
@ttscoff ttscoff merged commit 0ff0949 into ttscoff:main May 25, 2026
1 of 2 checks passed
@ttscoff

ttscoff commented May 25, 2026

Copy link
Copy Markdown
Owner

Thanks for this!

@ttscoff

ttscoff commented May 25, 2026

Copy link
Copy Markdown
Owner

The test for this did fail, fixing it in post.

@ttscoff ttscoff mentioned this pull request May 25, 2026
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.

3 participants