Skip to content

[Repo Assist] Improve CommonMark ATX heading compliance#1028

Merged
nojaf merged 6 commits intomainfrom
repo-assist/fix-191-commonmark-atx-headings-26ab2fbf1051d319
Feb 26, 2026
Merged

[Repo Assist] Improve CommonMark ATX heading compliance#1028
nojaf merged 6 commits intomainfrom
repo-assist/fix-191-commonmark-atx-headings-26ab2fbf1051d319

Conversation

@github-actions
Copy link
Contributor

🤖 This is a pull request created by Repo Assist, an automated AI assistant.

Closes #191

Summary

This PR improves CommonMark compliance for ATX headings in the Markdown parser. The changes fix four specific deviations from the [CommonMark spec for ATX headings]((spec.commonmark.org/redacted)

Changes to MarkdownParser.fs

The (|Heading|_|) active pattern's ATX heading case is rewritten to strictly follow CommonMark:

  1. Require a space (or end of line) after the # sequence#NoSpace and ##Tag are now correctly rendered as paragraphs instead of headings.
  2. Reject more than 6 # characters####### foo (7 hashes) is now a paragraph as required by the spec.
  3. Support 0–3 optional leading spaces ## foo (up to 3 leading spaces) is now correctly recognised as a heading.
  4. Fix empty heading body for closing-hash-only content### ### now correctly produces an empty <h3> rather than <h3>###</h3>.

Enabled CommonMark spec sections (CommonMarkSpecTest.fs)

Five additional spec sections that were already 100% passing are now enabled, adding 26 new passing test cases:

  • ATX headings (19 tests)
  • Blank lines (1 test)
  • Inlines (1 test)
  • Soft line breaks (2 tests)
  • Textual content (3 tests)

Updated tests

  • Markdown.fs: Updated Transform header 1 correctly and Transform header 2 correctly to reflect the correct CommonMark behavior (headings without a space after # are paragraphs).
  • External test reference files (Tight blocks.html, line-endings-*.html): Updated to reflect that #Header / ##Header without a space are paragraphs rather than headings.

Test Status

✅ All 220 Markdown tests pass (26 new, 194 pre-existing — 0 failures).
✅ All 101 Literate tests pass.
✅ Build succeeds.

Generated by Repo Assist for issue #191

To install this workflow, run gh aw add githubnext/agentics/workflows/repo-assist.md@f2c5cf1e4af58e09a93ba0703c6bf084711b265f. View source at https://github.com/githubnext/agentics/tree/f2c5cf1e4af58e09a93ba0703c6bf084711b265f/workflows/repo-assist.md.

- Reject ATX headings with no space after '#' (e.g. '#NoSpace' → paragraph)
- Reject ATX headings with more than 6 '#' characters (→ paragraph)
- Support 0–3 optional leading spaces before the opening '#' sequence
- Fix empty heading body when entire content is a closing '###' sequence
- Enable additional passing CommonMark spec sections: Blank lines, Inlines,
  Soft line breaks, Textual content, ATX headings (26 new test cases)
- Update test expectations and reference HTML files to match CommonMark spec

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme
Copy link
Contributor

dsyme commented Feb 26, 2026

@nojaf I'm OK with this. The code is not particularly pretty but if it's passing all tests plus the added tests I'm OK with it

@dsyme dsyme requested a review from nojaf February 26, 2026 00:23
@dsyme dsyme marked this pull request as ready for review February 26, 2026 00:56
@nojaf
Copy link
Collaborator

nojaf commented Feb 26, 2026

/repo-assist I have nitpicks on the tests.

You changed the outcome of the existing test without adding a new one for properly formatted headers. There should be a tests for something like ## title (where there is a space between ## and title).

I would also like a rename of the test let ``Transform header 1 correctly`` () = as this is more a check wether heading without space is transformed correctly. The name should reflect that.

@dsyme , can't help myself, life is too short not to nitpick.

- Rename 'Transform header 1 correctly' to 'ATX heading without space after hash is treated as paragraph' to better reflect what is being tested
- Add new test 'ATX heading with space after hash is transformed to heading element' to verify that properly formatted ATX headings (e.g. '# Header 1', '## Header 2') produce heading elements

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

Commit pushed: 500c45b

Generated by Repo Assist

@nojaf nojaf enabled auto-merge (squash) February 26, 2026 07:48
@nojaf nojaf merged commit 8df8eb8 into main Feb 26, 2026
4 checks passed
@nojaf nojaf deleted the repo-assist/fix-191-commonmark-atx-headings-26ab2fbf1051d319 branch February 26, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make F# Formatting compatible with CommonMark

2 participants