fix(rust): normalize setext headings to ATX#7
Merged
Conversation
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.
There was a problem hiding this comment.
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.
Owner
|
Thanks for this! |
Owner
|
The test for this did fail, fixing it in post. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potentially addresses issue #5
New normalization rule for setext headings:
===/---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:
is_setext_headingandnormalize_setext_to_atx_headingsfunctions 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:
Trade-offs:
This pull request was aided by Copilot AI but hand-checked.