Skip to content

Commit cd705f1

Browse files
authored
Merge pull request #119 from hendrikvanantwerpen/fix-heading-whitespace
Do not capture whitespace between ATX heading's marker and content
2 parents 85d0f22 + 3864f70 commit cd705f1

File tree

3 files changed

+29503
-29405
lines changed

3 files changed

+29503
-29405
lines changed

tree-sitter-markdown/grammar.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,34 +104,38 @@ module.exports = grammar({
104104
// https://github.github.com/gfm/#atx-headings
105105
_atx_heading1: $ => prec(1, seq(
106106
$.atx_h1_marker,
107-
optional(field('heading_content', alias($._line, $.inline))),
107+
optional($._atx_heading_content),
108108
$._newline
109109
)),
110110
_atx_heading2: $ => prec(1, seq(
111111
$.atx_h2_marker,
112-
optional(field('heading_content', alias($._line, $.inline))),
112+
optional($._atx_heading_content),
113113
$._newline
114114
)),
115115
_atx_heading3: $ => prec(1, seq(
116116
$.atx_h3_marker,
117-
optional(field('heading_content', alias($._line, $.inline))),
117+
optional($._atx_heading_content),
118118
$._newline
119119
)),
120120
_atx_heading4: $ => prec(1, seq(
121121
$.atx_h4_marker,
122-
optional(field('heading_content', alias($._line, $.inline))),
122+
optional($._atx_heading_content),
123123
$._newline
124124
)),
125125
_atx_heading5: $ => prec(1, seq(
126126
$.atx_h5_marker,
127-
optional(field('heading_content', alias($._line, $.inline))),
127+
optional($._atx_heading_content),
128128
$._newline
129129
)),
130130
_atx_heading6: $ => prec(1, seq(
131131
$.atx_h6_marker,
132-
optional(field('heading_content', alias($._line, $.inline))),
132+
optional($._atx_heading_content),
133133
$._newline
134134
)),
135+
_atx_heading_content: $ => prec(1, seq(
136+
optional($._whitespace),
137+
field('heading_content', alias($._line, $.inline))
138+
)),
135139

136140
// A setext heading. The underlines are currently handled by the external scanner but maybe
137141
// could be parsed using normal tree-sitter rules.

tree-sitter-markdown/src/grammar.json

Lines changed: 46 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,17 +1910,8 @@
19101910
"type": "CHOICE",
19111911
"members": [
19121912
{
1913-
"type": "FIELD",
1914-
"name": "heading_content",
1915-
"content": {
1916-
"type": "ALIAS",
1917-
"content": {
1918-
"type": "SYMBOL",
1919-
"name": "_line"
1920-
},
1921-
"named": true,
1922-
"value": "inline"
1923-
}
1913+
"type": "SYMBOL",
1914+
"name": "_atx_heading_content"
19241915
},
19251916
{
19261917
"type": "BLANK"
@@ -1948,17 +1939,8 @@
19481939
"type": "CHOICE",
19491940
"members": [
19501941
{
1951-
"type": "FIELD",
1952-
"name": "heading_content",
1953-
"content": {
1954-
"type": "ALIAS",
1955-
"content": {
1956-
"type": "SYMBOL",
1957-
"name": "_line"
1958-
},
1959-
"named": true,
1960-
"value": "inline"
1961-
}
1942+
"type": "SYMBOL",
1943+
"name": "_atx_heading_content"
19621944
},
19631945
{
19641946
"type": "BLANK"
@@ -1986,17 +1968,8 @@
19861968
"type": "CHOICE",
19871969
"members": [
19881970
{
1989-
"type": "FIELD",
1990-
"name": "heading_content",
1991-
"content": {
1992-
"type": "ALIAS",
1993-
"content": {
1994-
"type": "SYMBOL",
1995-
"name": "_line"
1996-
},
1997-
"named": true,
1998-
"value": "inline"
1999-
}
1971+
"type": "SYMBOL",
1972+
"name": "_atx_heading_content"
20001973
},
20011974
{
20021975
"type": "BLANK"
@@ -2024,17 +1997,8 @@
20241997
"type": "CHOICE",
20251998
"members": [
20261999
{
2027-
"type": "FIELD",
2028-
"name": "heading_content",
2029-
"content": {
2030-
"type": "ALIAS",
2031-
"content": {
2032-
"type": "SYMBOL",
2033-
"name": "_line"
2034-
},
2035-
"named": true,
2036-
"value": "inline"
2037-
}
2000+
"type": "SYMBOL",
2001+
"name": "_atx_heading_content"
20382002
},
20392003
{
20402004
"type": "BLANK"
@@ -2062,17 +2026,8 @@
20622026
"type": "CHOICE",
20632027
"members": [
20642028
{
2065-
"type": "FIELD",
2066-
"name": "heading_content",
2067-
"content": {
2068-
"type": "ALIAS",
2069-
"content": {
2070-
"type": "SYMBOL",
2071-
"name": "_line"
2072-
},
2073-
"named": true,
2074-
"value": "inline"
2075-
}
2029+
"type": "SYMBOL",
2030+
"name": "_atx_heading_content"
20762031
},
20772032
{
20782033
"type": "BLANK"
@@ -2100,17 +2055,8 @@
21002055
"type": "CHOICE",
21012056
"members": [
21022057
{
2103-
"type": "FIELD",
2104-
"name": "heading_content",
2105-
"content": {
2106-
"type": "ALIAS",
2107-
"content": {
2108-
"type": "SYMBOL",
2109-
"name": "_line"
2110-
},
2111-
"named": true,
2112-
"value": "inline"
2113-
}
2058+
"type": "SYMBOL",
2059+
"name": "_atx_heading_content"
21142060
},
21152061
{
21162062
"type": "BLANK"
@@ -2124,6 +2070,40 @@
21242070
]
21252071
}
21262072
},
2073+
"_atx_heading_content": {
2074+
"type": "PREC",
2075+
"value": 1,
2076+
"content": {
2077+
"type": "SEQ",
2078+
"members": [
2079+
{
2080+
"type": "CHOICE",
2081+
"members": [
2082+
{
2083+
"type": "SYMBOL",
2084+
"name": "_whitespace"
2085+
},
2086+
{
2087+
"type": "BLANK"
2088+
}
2089+
]
2090+
},
2091+
{
2092+
"type": "FIELD",
2093+
"name": "heading_content",
2094+
"content": {
2095+
"type": "ALIAS",
2096+
"content": {
2097+
"type": "SYMBOL",
2098+
"name": "_line"
2099+
},
2100+
"named": true,
2101+
"value": "inline"
2102+
}
2103+
}
2104+
]
2105+
}
2106+
},
21272107
"_setext_heading1": {
21282108
"type": "SEQ",
21292109
"members": [

0 commit comments

Comments
 (0)