Prevent the folding of heading syntax in code fences

Previously in Markdown files, Vim would treat heading syntax in code
fences as Markdown headers. This commit ensures that only headers will
be folded by checking the 'synIDattr' of the item.

E.g. The comment in this code snippet would have been treated as a
Markdown header.

```sh
 # This is a comment
 echo "Hello world"
```
This commit is contained in:
Alex Vear
2018-11-07 11:14:12 +00:00
committed by Tim Pope
parent c043a93c84
commit a2e123a288

View File

@@ -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*', '', '')