Skip to content

Commit

Permalink
Syntax: Fix headings highlighting
Browse files Browse the repository at this point in the history
Fixes #572

Headings must start with a hashtag followed by at least one space.
They may be indented by up to three whitespace.

This commit fixes the syntax definitions to follow this rule.
  • Loading branch information
deathaxe committed May 14, 2021
1 parent 56ebdad commit 485d105
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Markdown (Standard).tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<string>(?x)^
(?= [ ]{,3}&gt;
| ([ ]{4}|\t)(?!$)
| [#]{1,6}\s*+
| [ ]{,3}[#]{1,6}\s*+
| [ ]{,3}(?&lt;marker&gt;[-*_])([ ]{,2}\k&lt;marker&gt;){2,}[ \t]*+$
)</string>
<key>comment</key>
Expand All @@ -41,7 +41,7 @@
<string>(?x)^
(?! [ ]{,3}&gt;
| ([ ]{4}|\t)
| [#]{1,6}\s*+
| [ ]{,3}[#]{1,6}\s+
| [ ]{,3}(?&lt;marker&gt;[-*_])([ ]{,2}\k&lt;marker&gt;){2,}[ \t]*+$
)</string>
<key>name</key>
Expand Down Expand Up @@ -391,7 +391,7 @@
<key>begin</key>
<string>(?x)\G
(?= ([ ]{4}|\t)
| [#]{1,6}\s*+
| [ ]{,3}[#]{1,6}\s+
| [ ]{,3}(?&lt;marker&gt;[-*_])([ ]{,2}\k&lt;marker&gt;){2,}[ \t]*+$
)</string>
<key>end</key>
Expand All @@ -418,7 +418,7 @@
(?! $
| [ ]{,3}&gt;
| ([ ]{4}|\t)
| [#]{1,6}\s*+
| [ ]{,3}[#]{1,6}\s+
| [ ]{,3}(?&lt;marker&gt;[-*_])([ ]{,2}\k&lt;marker&gt;){2,}[ \t]*+$
)</string>
<key>end</key>
Expand Down Expand Up @@ -721,7 +721,7 @@
<key>heading</key>
<dict>
<key>begin</key>
<string>\G(#{1,6})(?!#)\s*(?=\S)</string>
<string>\G[ ]{,3}(#{1,6})(?!#)\s*(?=\S)</string>
<key>captures</key>
<dict>
<key>1</key>
Expand Down
10 changes: 5 additions & 5 deletions Markdown.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contexts:
(?x)^
(?= [ ]{,3}>
| ([ ]{4}|\t)(?!$)
| [#]{1,6}\s*+
| [ ]{,3}[#]{1,6}\s+
| [ ]{,3}(?<marker>[-*_])([ ]{,2}\k<marker>){2,}[ \t]*+$
)
comment: |
Expand All @@ -59,7 +59,7 @@ contexts:
(?x)^
(?! [ ]{,3}>
| ([ ]{4}|\t)
| [#]{1,6}\s*+
| [ ]{,3}[#]{1,6}\s+
| [ ]{,3}(?<marker>[-*_])([ ]{,2}\k<marker>){2,}[ \t]*+$
)
pop: true
Expand Down Expand Up @@ -212,7 +212,7 @@ contexts:
- match: |-
(?x)\G
(?= ([ ]{4}|\t)
| [#]{1,6}\s*+
| [ ]{,3}[#]{1,6}\s+
| [ ]{,3}(?<marker>[-*_])([ ]{,2}\k<marker>){2,}[ \t]*+$
)
push:
Expand All @@ -226,7 +226,7 @@ contexts:
(?! $
| [ ]{,3}>
| ([ ]{4}|\t)
| [#]{1,6}\s*+
| [ ]{,3}[#]{1,6}\s+
| [ ]{,3}(?<marker>[-*_])([ ]{,2}\k<marker>){2,}[ \t]*+$
)
push:
Expand Down Expand Up @@ -644,7 +644,7 @@ contexts:
embed_scope: markup.raw.block.markdown markup.raw.block.fenced.markdown
escape: ^(\1)\n
heading:
- match: '\G(#{1,6})(?!#)\s*(?=\S)'
- match: '\G[ \t]{,3}(#{1,6})(?!#)\s+(?=\S)'
captures:
1: punctuation.definition.heading.markdown
push:
Expand Down
12 changes: 12 additions & 0 deletions tests/syntax_test_GFM.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ heading 2
<!-- ^ markup.heading.2.markdown -->
<!-- ^ punctuation.definition.heading.markdown -->

#NoHeadings
<!-- <-- punctuation - entity.name.section -->
<!--^^^^^^^^ - entity.name.section -->

# heading 1
<!--<- punctuation.definition.heading.markdown -->
<!--^ entity.name.section.markdown -->

# heading 1
<!--<- punctuation.definition.heading.markdown -->
<!--^ entity.name.section.markdown -->

## heading 2
<!--<- punctuation.definition.heading.markdown -->
<!--^ entity.name.section.markdown -->
Expand Down

0 comments on commit 485d105

Please sign in to comment.