Skip to content

Commit

Permalink
fix(headings): disallow whitespace before heading #22
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk authored Sep 28, 2022
1 parent 2ba61cf commit 55292d9
Show file tree
Hide file tree
Showing 4 changed files with 447 additions and 448 deletions.
16 changes: 16 additions & 0 deletions corpus/heading1_2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Text
NOT h1 h2 heading
================================================================================

===============================================================================
must-start-at-column-1

===============================================================================
must-start-at-column-1

====
Not-a-heading-1 *heading1*

Expand All @@ -93,6 +99,16 @@ Text
--------------------------------------------------------------------------------

(help_file
(block
(line
(word))
(line
(word)))
(block
(line
(word))
(line
(word)))
(block
(line
(word))
Expand Down
4 changes: 2 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ module.exports = grammar({

h1: ($) =>
seq(
field('delimiter', /[\t ]*============+[\t ]*\n/),
token.immediate(field('delimiter', /============+[\t ]*\n/)),
repeat1($._atom),
'\n',
repeat(_blank()),
),

h2: ($) =>
seq(
field('delimiter', /[\t ]*------------+[\t ]*\n/),
token.immediate(field('delimiter', /------------+[\t ]*\n/)),
repeat1($._atom),
'\n',
repeat(_blank()),
Expand Down
22 changes: 14 additions & 8 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,14 @@
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "delimiter",
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[\\t ]*============+[\\t ]*\\n"
"type": "FIELD",
"name": "delimiter",
"content": {
"type": "PATTERN",
"value": "============+[\\t ]*\\n"
}
}
},
{
Expand Down Expand Up @@ -567,11 +570,14 @@
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "delimiter",
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[\\t ]*------------+[\\t ]*\\n"
"type": "FIELD",
"name": "delimiter",
"content": {
"type": "PATTERN",
"value": "------------+[\\t ]*\\n"
}
}
},
{
Expand Down
Loading

0 comments on commit 55292d9

Please sign in to comment.