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
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.
Requirements
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 characterThis PR is necessary to prevent things like
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 theend
pattern, causing it to end on the following line (and scoping that line as a heading).Screenshot
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 werebegin/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.