fix: detect ATX headings indented up to 3 spaces#26
Merged
Conversation
The markdown parser anchored the heading pattern at column 0, so a heading with any leading whitespace (e.g. " # Title") was not detected. Allow 0-3 leading spaces per CommonMark; 4+ spaces remain an indented code block.
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.
Problem
The Markdown parser missed ATX headings that had any leading whitespace.
# Titlewas detected, but# Title(indented) was not — even thoughCommonMark treats up to 3 leading spaces as a valid heading.
Cause
The heading pattern was anchored at column 0:
Any space before # made the match fail.
Fix
Allow 0–3 leading spaces, and keep 4+ spaces as an indented code block
(per CommonMark):
Tests
Added regression tests in tests/parser_spec.lua:
Full suite: 78 passed / 0 failed.
Scope
Other parsers were audited for the same class of bug. Org headlines, reST
section adornments, and Vim-help rules are all required to sit in column 0 by
their formats, so their column-0 anchoring is correct — no change needed. The
HTML heading matcher already allows leading whitespace.