Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Improved ATX Heading Regex #222

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Improved ATX Heading Regex #222

wants to merge 3 commits into from

Conversation

Aerijo
Copy link
Contributor

@Aerijo Aerijo commented Dec 24, 2017

Requirements

  • Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • All new code requires tests to ensure against regressions

Description of the Change

Updates the header patterns to follow the specifications given here closer.

  • ^\\s{,3} - allow up to three spaces at the start of the line
  • (#{1}) - number of # characters
  • ((?:\\s*?(?=$))|(?:\\s+(?=[^$]))) - two possible situtations:
    • (?:\\s*?(?=$)) - the last # is followed by 0 or more spaces that end with a newline character. Non greedy, so the newline character is not captured.
    • (?:\\s+(?=[^$])) - the last # is followed by 1 or more spaces (greedy), and stops just before the first non-endline character

This PR is necessary to prevent things like

#
text

from having text incorrectly scoped as a heading. It allows for the 'empty' heading, which is a legal heading. That bug was caused by the (\\s*) pattern in the original, which would also capture the endline character and hide it from the end pattern, causing it to end on the following line (and scoping that line as a heading).

Screenshot

screen shot 2017-12-24 at 7 33 59 pm

Alternate Designs

As far as I can tell, these headings must be a single line. Therefore, I could have used a match pattern instead, but I didn't because the existing ones were begin/end patterns.

Benefits

More accurate syntax highlighting, in line with the specifications of the language.

Possible Drawbacks

Some GFM implementations might not follow the specifications so rigouously? They are new, after all.

Other than that, I don't know any drawbacks.

Applicable Issues

None.

Additional notes

I did not change the specs because they still pass with this change. I could add more though, to prevent regressions from this PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant