Skip to content

Commit

Permalink
Add space in header regex
Browse files Browse the repository at this point in the history
  • Loading branch information
lggruspe committed Sep 16, 2022
1 parent 3a96439 commit 4b5e197
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
14 changes: 7 additions & 7 deletions ftplugin/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@
" For each level, contains the regexp that matches at that level only.
"
let s:levelRegexpDict = {
\ 1: '\v^(#[^#]@=|.+\n\=+$)',
\ 2: '\v^(##[^#]@=|.+\n-+$)',
\ 3: '\v^###[^#]@=',
\ 4: '\v^####[^#]@=',
\ 5: '\v^#####[^#]@=',
\ 6: '\v^######[^#]@='
\ 1: '\v^(#[^#]@=\s+|.+\n\=+$)',
\ 2: '\v^(##[^#]@=\s+|.+\n-+$)',
\ 3: '\v^###[^#]@=\s+',
\ 4: '\v^####[^#]@=\s+',
\ 5: '\v^#####[^#]@=\s+',
\ 6: '\v^######[^#]@=\s+'
\ }

" Maches any header level of any type.
"
" This could be deduced from `s:levelRegexpDict`, but it is more
" efficient to have a single regexp for this.
"
let s:headersRegexp = '\v^(#|.+\n(\=+|-+)$)'
let s:headersRegexp = '\v^(#{1,6}\s+|.+\n(\=+|-+)$)'

" Returns the line number of the first header before `line`, called the
" current header.
Expand Down
12 changes: 9 additions & 3 deletions test/map.vader
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ Given markdown;

b

#ignore

# c

d

Execute (]] same level):
AssertEqual line('.'), 1
normal ]]
AssertEqual line('.'), 5
AssertEqual line('.'), 7
normal [[
AssertEqual line('.'), 1

Expand All @@ -110,14 +112,16 @@ Given markdown;

b

##ignore

## c

d

Execute (]] different levels level):
AssertEqual line('.'), 1
normal ]]
AssertEqual line('.'), 5
AssertEqual line('.'), 7
normal [[
AssertEqual line('.'), 1

Expand All @@ -126,6 +130,8 @@ Given markdown;

b

#ignore

## c

d
Expand All @@ -137,7 +143,7 @@ f
Execute (][ different levels level):
AssertEqual line('.'), 1
normal ][
AssertEqual line('.'), 9
AssertEqual line('.'), 11
normal []
AssertEqual line('.'), 1

Expand Down
3 changes: 0 additions & 3 deletions test/toc.vader
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,11 @@ Execute (Toc multiple headers):

Expect (multiple headers):
h1 space
h1 nospace
h1 2 spaces
h1 trailing hash
h2 space
h2 nospace
h2 trailing hash
h3 space
h3 nospace
h3 trailing hash
h4
h5
Expand Down

0 comments on commit 4b5e197

Please sign in to comment.