Skip to content

Commit f29b4e2

Browse files
committed
Add space in header regex
1 parent acae22a commit f29b4e2

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

ftplugin/markdown.vim

+8-8
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@
4848
" For each level, contains the regexp that matches at that level only.
4949
"
5050
let s:levelRegexpDict = {
51-
\ 1: '\v^(#[^#]@=|.+\n\=+$)',
52-
\ 2: '\v^(##[^#]@=|.+\n-+$)',
53-
\ 3: '\v^###[^#]@=',
54-
\ 4: '\v^####[^#]@=',
55-
\ 5: '\v^#####[^#]@=',
56-
\ 6: '\v^######[^#]@='
51+
\ 1: '\v^(#[^#]@=\s+|.+\n\=+$)',
52+
\ 2: '\v^(##[^#]@=\s+|.+\n-+$)',
53+
\ 3: '\v^###[^#]@=\s+',
54+
\ 4: '\v^####[^#]@=\s+',
55+
\ 5: '\v^#####[^#]@=\s+',
56+
\ 6: '\v^######[^#]@=\s+'
5757
\ }
5858

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

6666
" Returns the line number of the first header before `line`, called the
6767
" current header.
@@ -526,7 +526,7 @@ function! s:HeaderDecrease(line1, line2, ...)
526526
let l:numSubstitutions = s:SetexToAtx(a:line1, a:line2)
527527
let l:flags = (&gdefault ? '' : 'g')
528528
for l:level in range(replaceLevels[0], replaceLevels[1], -l:levelDelta)
529-
execute 'silent! ' . a:line1 . ',' . (a:line2 - l:numSubstitutions) . 'substitute/' . s:levelRegexpDict[l:level] . '/' . repeat('#', l:level + l:levelDelta) . '/' . l:flags
529+
execute 'silent! ' . a:line1 . ',' . (a:line2 - l:numSubstitutions) . 'substitute/' . s:levelRegexpDict[l:level] . '/' . repeat('#', l:level + l:levelDelta) . ' /' . l:flags
530530
endfor
531531
endfunction
532532

test/map.vader

+9-3
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,16 @@ Given markdown;
9494

9595
b
9696

97+
#ignore
98+
9799
# c
98100

99101
d
100102

101103
Execute (]] same level):
102104
AssertEqual line('.'), 1
103105
normal ]]
104-
AssertEqual line('.'), 5
106+
AssertEqual line('.'), 7
105107
normal [[
106108
AssertEqual line('.'), 1
107109

@@ -110,14 +112,16 @@ Given markdown;
110112

111113
b
112114

115+
##ignore
116+
113117
## c
114118

115119
d
116120

117121
Execute (]] different levels level):
118122
AssertEqual line('.'), 1
119123
normal ]]
120-
AssertEqual line('.'), 5
124+
AssertEqual line('.'), 7
121125
normal [[
122126
AssertEqual line('.'), 1
123127

@@ -126,6 +130,8 @@ Given markdown;
126130

127131
b
128132

133+
#ignore
134+
129135
## c
130136

131137
d
@@ -137,7 +143,7 @@ f
137143
Execute (][ different levels level):
138144
AssertEqual line('.'), 1
139145
normal ][
140-
AssertEqual line('.'), 9
146+
AssertEqual line('.'), 11
141147
normal []
142148
AssertEqual line('.'), 1
143149

test/toc.vader

-3
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,11 @@ Execute (Toc multiple headers):
138138

139139
Expect (multiple headers):
140140
h1 space
141-
h1 nospace
142141
h1 2 spaces
143142
h1 trailing hash
144143
h2 space
145-
h2 nospace
146144
h2 trailing hash
147145
h3 space
148-
h3 nospace
149146
h3 trailing hash
150147
h4
151148
h5

0 commit comments

Comments
 (0)