diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index 39c0f8e..7cda6b1 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -23,23 +23,27 @@ function! MarkdownFold() let line = getline(v:lnum) " Regular headers - if line =~# '^#\+ ' + if line =~# '^#\+ ' && s:NotCodeBlock(v:lnum) return ">" . match(line, ' ') endif " Setext style headings let nextline = getline(v:lnum + 1) - if (line =~ '^.\+$') && (nextline =~ '^=\+$') + if (line =~ '^.\+$') && (nextline =~ '^=\+$') && s:NotCodeBlock(v:lnum + 1) return ">1" endif - if (line =~ '^.\+$') && (nextline =~ '^-\+$') + if (line =~ '^.\+$') && (nextline =~ '^-\+$') && s:NotCodeBlock(v:lnum + 1) return ">2" endif return "=" endfunction +function! s:NotCodeBlock(lnum) + return synIDattr(synID(v:lnum, 1, 1), 'name') !=# 'markdownCode' +endfunction + function! MarkdownFoldText() let hash_indent = s:HashIndent(v:foldstart) let title = substitute(getline(v:foldstart), '^#\+\s*', '', '')