Fixed front matter heading bugs of folding and `:Toc`.
Fix #160
elseif b:fenced_block == 1
let b:fenced_block = 0
endif
+ elseif g:vim_markdown_frontmatter == 1
+ if b:front_matter == 1 && a:lnum > 2
+ let l0 = getline(a:lnum-1)
+ if l0 == '---'
+ let b:front_matter = 0
+ endif
+ elseif a:lnum == 1
+ if l1 == '---'
+ let b:front_matter = 1
+ endif
+ endif
endif
- if b:fenced_block == 1
+ if b:fenced_block == 1 || b:front_matter == 1
if a:lnum == 1
" fold any 'preamble'
return '>1'
elseif b:fenced_block == 1
let b:fenced_block = 0
endif
+ elseif g:vim_markdown_frontmatter == 1
+ if b:front_matter == 1
+ if l0 == '---'
+ let b:front_matter = 0
+ endif
+ elseif a:lnum == 2
+ if l0 == '---'
+ let b:front_matter = 1
+ endif
+ endif
endif
- if b:fenced_block == 1
+ if b:fenced_block == 1 || b:front_matter == 1
" keep previous foldlevel
return '='
endif
let b:fenced_block = 0
+let b:front_matter = 0
let g:vim_markdown_folding_level = get(g:, "vim_markdown_folding_level", 1)
if !get(g:, "vim_markdown_folding_disabled", 0)
let b:bufnr = bufnr('%')
let b:fenced_block = 0
+ let l:front_matter = 0
let b:header_list = []
let l:header_max_len = 0
let g:vim_markdown_toc_autofit = get(g:, "vim_markdown_toc_autofit", 0)
+ let l:vim_markdown_frontmatter = get(g:, "vim_markdown_frontmatter", 0)
for i in range(1, line('$'))
let l:lineraw = getline(i)
let l:l1 = getline(i+1)
elseif b:fenced_block == 1
let b:fenced_block = 0
endif
+ elseif l:vim_markdown_frontmatter == 1
+ if l:front_matter == 1
+ if l:line == '---'
+ let l:front_matter = 0
+ endif
+ elseif i == 1
+ if l:line == '---'
+ let l:front_matter = 1
+ endif
+ endif
endif
if l:line =~ '^#\+' || (l:l1 =~ '^=\+\s*$' || l:l1 =~ '^-\+\s*$') && l:line =~ '^\S'
let b:is_header = 1
else
let b:is_header = 0
endif
- if b:is_header == 1 && b:fenced_block == 0
+ if b:is_header == 1 && b:fenced_block == 0 && l:front_matter == 0
" append line to location list
let b:item = {'lnum': i, 'text': l:line, 'valid': 1, 'bufnr': b:bufnr, 'col': 1}
let b:header_list = b:header_list + [b:item]
let elem = res[7]
AssertEqual elem.lnum, 50
AssertEqual elem.text, 'chap 4.1'
+
+Given markdown;
+---
+layout: article
+title: A test of the heading folding when there is YAML frontmatter
+tags: markdown yaml vim-markdown
+---
+body
+
+heading
+-------
+
+Execute (fold level of yaml front matter):
+ let g:vim_markdown_frontmatter = 1
+ source ../after/ftplugin/markdown.vim
+ AssertEqual foldlevel(1), 0, '---'
+ AssertEqual foldlevel(2), 0, 'layout: article'
+ AssertEqual foldlevel(4), 0, 'tags: markdown yaml vim-markdown'
+ AssertEqual foldlevel(5), 0, '---'
+ AssertEqual foldlevel(6), 0, 'body'
+ AssertEqual foldlevel(8), 2, 'heading'
+ AssertEqual foldlevel(9), 2, '-------'
+ unlet g:vim_markdown_frontmatter
+
+Execute (check Toc of yaml front matter):
+ let g:vim_markdown_frontmatter = 1
+ :Toc
+ :lclose
+ let res = getloclist(0)
+ AssertEqual len(res), 1
+ let elem = res[0]
+ AssertEqual elem.lnum, 8
+ AssertEqual elem.text, 'heading'
+ unlet g:vim_markdown_frontmatter
AssertEqual foldlevel(1), 1, 'Headline'
AssertEqual foldlevel(3), 1, 'foobar'
AssertEqual foldlevel(5), 0, '# Title'
+
+Given markdown;
+---
+layout: article
+title: A test of the heading folding when there is YAML frontmatter
+tags: markdown yaml vim-markdown
+---
+body
+
+heading
+-------
+
+Execute (fold level of yaml front matter):
+ let g:vim_markdown_frontmatter = 1
+ source ../after/ftplugin/markdown.vim
+ AssertEqual foldlevel(1), 1, '---'
+ AssertEqual foldlevel(2), 1, 'layout: article'
+ AssertEqual foldlevel(4), 1, 'tags: markdown yaml vim-markdown'
+ AssertEqual foldlevel(5), 1, '---'
+ AssertEqual foldlevel(6), 1, 'body'
+ AssertEqual foldlevel(8), 1, 'heading'
+ AssertEqual foldlevel(9), 1, '-------'
+ unlet g:vim_markdown_frontmatter