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 acae22a commit f29b4e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
16 changes: 8 additions & 8 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 Expand Up @@ -526,7 +526,7 @@ function! s:HeaderDecrease(line1, line2, ...)
let l:numSubstitutions = s:SetexToAtx(a:line1, a:line2)
let l:flags = (&gdefault ? '' : 'g')
for l:level in range(replaceLevels[0], replaceLevels[1], -l:levelDelta)
execute 'silent! ' . a:line1 . ',' . (a:line2 - l:numSubstitutions) . 'substitute/' . s:levelRegexpDict[l:level] . '/' . repeat('#', l:level + l:levelDelta) . '/' . l:flags
execute 'silent! ' . a:line1 . ',' . (a:line2 - l:numSubstitutions) . 'substitute/' . s:levelRegexpDict[l:level] . '/' . repeat('#', l:level + l:levelDelta) . ' /' . l:flags
endfor
endfunction

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 f29b4e2

Please sign in to comment.