Skip to content

Commit

Permalink
Fix invalid range in SetexToAtx
Browse files Browse the repository at this point in the history
  • Loading branch information
lggruspe committed Oct 25, 2022
1 parent b9c5c34 commit 67571a1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ftplugin/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,9 @@ endfunction
function! s:SetexToAtx(line1, line2)
let l:originalNumLines = line('$')
execute 'silent! ' . a:line1 . ',' . a:line2 . 'substitute/\v(.*\S.*)\n\=+$/# \1/'
execute 'silent! ' . a:line1 . ',' . a:line2 . 'substitute/\v(.*\S.*)\n-+$/## \1/'

let l:changed = l:originalNumLines - line('$')
execute 'silent! ' . a:line1 . ',' . (a:line2 - l:changed) . 'substitute/\v(.*\S.*)\n-+$/## \1'
return l:originalNumLines - line('$')
endfunction

Expand Down
26 changes: 26 additions & 0 deletions test/setextoatx.vader
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,29 @@ Expect (convert setex-style headings to atx):
## b

## b

Given markdown;
a
=

b
=

c
-

d
-

Execute (SetexToAtx with range):
:1,8SetexToAtx

Expect (only convert setex headings in original range):
# a

# b

## c

d
-

0 comments on commit 67571a1

Please sign in to comment.