Skip to content

Commit

Permalink
Match empty atx headings
Browse files Browse the repository at this point in the history
  • Loading branch information
lggruspe committed Oct 25, 2022
1 parent 4455ea6 commit 7b9425e
Showing 1 changed file with 8 additions and 8 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^(#[^#]@=\s+|.+\n\=+$)',
\ 2: '\v^(##[^#]@=\s+|.+\n-+$)',
\ 3: '\v^###[^#]@=\s+',
\ 4: '\v^####[^#]@=\s+',
\ 5: '\v^#####[^#]@=\s+',
\ 6: '\v^######[^#]@=\s+'
\ 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^(#{1,6}\s+|.+\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

0 comments on commit 7b9425e

Please sign in to comment.