Skip to content

Commit

Permalink
Implement HeadingDepth() for underlined headings.
Browse files Browse the repository at this point in the history
  • Loading branch information
nelstrom committed Oct 24, 2012
1 parent 06ff407 commit a80b1b3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
9 changes: 9 additions & 0 deletions after/ftplugin/markdown/folding.vim
Expand Up @@ -5,6 +5,15 @@ function! HeadingDepth(lnum)
let hashCount = len(matchstr(thisline, '^#\{1,6}'))
if hashCount > 0
let level = hashCount
else
if thisline != ''
let nextline = getline(a:lnum + 1)
if nextline =~ '^==='
let level = 1
elseif nextline =~ '^---'
let level = 2
endif
endif
endif
return level
endfunction
Expand Down
39 changes: 38 additions & 1 deletion test/folding.vim
Expand Up @@ -68,7 +68,7 @@ describe 'HeadingDepth'
Expect HeadingDepth(2) ==# 0
end

it 'returns 0 for content lines'
it 'returns 0 for lines of content'
call PopulateBuffer([
\ 'lorem ipsum dolor sit amet',
\ 'consequeteur blah blah'
Expand All @@ -92,4 +92,41 @@ describe 'HeadingDepth'
Expect HeadingDepth(1) ==# 3
end

it 'returns 1 for === underscored headings'
call PopulateBuffer([
\ 'Level one heading',
\ '=================',
\ ])
Expect HeadingDepth(1) ==# 1
Expect HeadingDepth(2) ==# 0
end

it 'returns 2 for --- underscored headings'
call PopulateBuffer([
\ 'Level two heading',
\ '-----------------',
\ ])
Expect HeadingDepth(1) ==# 2
Expect HeadingDepth(2) ==# 0
end

it 'ignores --- and === when preceded by a blank line'
call PopulateBuffer([
\ '=================',
\ '',
\ '=================',
\ '',
\ '-----------------',
\ '',
\ '-----------------',
\ ])
Expect HeadingDepth(1) ==# 0
Expect HeadingDepth(2) ==# 0
Expect HeadingDepth(3) ==# 0
Expect HeadingDepth(4) ==# 0
Expect HeadingDepth(5) ==# 0
Expect HeadingDepth(6) ==# 0
Expect HeadingDepth(7) ==# 0
end

end

0 comments on commit a80b1b3

Please sign in to comment.