mirror of
https://github.com/tpope/vim-markdown.git
synced 2025-11-08 09:53:50 -05:00
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:
@@ -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*', '', '')
|
||||
|
||||
Reference in New Issue
Block a user