Skip to content

Commit 67571a1

Browse files
committed
Fix invalid range in SetexToAtx
1 parent b9c5c34 commit 67571a1

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ftplugin/markdown.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,9 @@ endfunction
494494
function! s:SetexToAtx(line1, line2)
495495
let l:originalNumLines = line('$')
496496
execute 'silent! ' . a:line1 . ',' . a:line2 . 'substitute/\v(.*\S.*)\n\=+$/# \1/'
497-
execute 'silent! ' . a:line1 . ',' . a:line2 . 'substitute/\v(.*\S.*)\n-+$/## \1/'
497+
498+
let l:changed = l:originalNumLines - line('$')
499+
execute 'silent! ' . a:line1 . ',' . (a:line2 - l:changed) . 'substitute/\v(.*\S.*)\n-+$/## \1'
498500
return l:originalNumLines - line('$')
499501
endfunction
500502

test/setextoatx.vader

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,29 @@ Expect (convert setex-style headings to atx):
2020
## b
2121

2222
## b
23+
24+
Given markdown;
25+
a
26+
=
27+
28+
b
29+
=
30+
31+
c
32+
-
33+
34+
d
35+
-
36+
37+
Execute (SetexToAtx with range):
38+
:1,8SetexToAtx
39+
40+
Expect (only convert setex headings in original range):
41+
# a
42+
43+
# b
44+
45+
## c
46+
47+
d
48+
-

0 commit comments

Comments
 (0)