Skip to content

Fix highlight broken by code fence nested in block quote #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions syntax/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ if !exists('g:markdown_fenced_languages')
endif
let s:done_include = {}
for s:type in map(copy(g:markdown_fenced_languages),'matchstr(v:val,"[^=]*$")')
if has_key(s:done_include, matchstr(s:type,'[^.]*'))
let s:lang = matchstr(s:type,'[^.]*')
if has_key(s:done_include, s:lang)
continue
endif
if s:type =~ '\.'
let b:{matchstr(s:type,'[^.]*')}_subtype = matchstr(s:type,'\.\zs.*')
let b:{s:lang}_subtype = matchstr(s:type,'\.\zs.*')
endif
syn case match
exe 'syn include @markdownHighlight_'.tr(s:type,'.','_').' syntax/'.matchstr(s:type,'[^.]*').'.vim'
exe 'syn include @markdownHighlight_'.tr(s:type,'.','_').' syntax/'.s:lang.'.vim'
unlet! b:current_syntax
let s:done_include[matchstr(s:type,'[^.]*')] = 1
let s:done_include[s:lang] = 1
endfor
unlet! s:type
unlet! s:done_include
unlet! s:lang

syn spell toplevel
if exists('s:foldmethod') && s:foldmethod !=# &l:foldmethod
Expand Down Expand Up @@ -122,6 +124,8 @@ syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" keepe
syn region markdownCode matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" keepend contains=markdownLineStart
syn region markdownCodeBlock matchgroup=markdownCodeDelimiter start="^\s*\z(`\{3,\}\).*$" end="^\s*\z1\ze\s*$" keepend
syn region markdownCodeBlock matchgroup=markdownCodeDelimiter start="^\s*\z(\~\{3,\}\).*$" end="^\s*\z1\ze\s*$" keepend
syn region markdownCodeBlock matchgroup=markdownCodeDelimiter start="\%(^>\s\+\)\@<=\z(`\{3,\}\).*$" end="^>\s\+\zs\z1\ze\s*$" keepend contains=markdownBlockquote
syn region markdownCodeBlock matchgroup=markdownCodeDelimiter start="\%(^>\s\+\)\@<=\z(\~\{3,\}\).*$" end="^>\s\+\zs\z1\ze\s*$" keepend contains=markdownBlockquote

syn match markdownFootnote "\[^[^\]]\+\]"
syn match markdownFootnoteDefinition "^\[^[^\]]\+\]:"
Expand All @@ -131,12 +135,20 @@ for s:type in g:markdown_fenced_languages
if has_key(s:done_include, matchstr(s:type,'[^.]*'))
continue
endif
exe 'syn region markdownHighlight_'.substitute(matchstr(s:type,'[^=]*$'),'\..*','','').' matchgroup=markdownCodeDelimiter start="^\s*\z(`\{3,\}\)\s*\%({.\{-}\.\)\='.matchstr(s:type,'[^=]*').'}\=\S\@!.*$" end="^\s*\z1\ze\s*$" keepend contains=@markdownHighlight_'.tr(matchstr(s:type,'[^=]*$'),'.','_') . s:concealends
exe 'syn region markdownHighlight_'.substitute(matchstr(s:type,'[^=]*$'),'\..*','','').' matchgroup=markdownCodeDelimiter start="^\s*\z(\~\{3,\}\)\s*\%({.\{-}\.\)\='.matchstr(s:type,'[^=]*').'}\=\S\@!.*$" end="^\s*\z1\ze\s*$" keepend contains=@markdownHighlight_'.tr(matchstr(s:type,'[^=]*$'),'.','_') . s:concealends
let s:region = substitute(matchstr(s:type,'[^=]*$'),'\..*','','')
let s:lang = matchstr(s:type,'[^=]*')
let s:include = tr(matchstr(s:type,'[^=]*$'),'.','_')
exe 'syn region markdownHighlight_'.s:region.' matchgroup=markdownCodeDelimiter start="^\s*\z(`\{3,\}\)\s*\%({.\{-}\.\)\='.s:lang.'}\=\S\@!.*$" end="^\s*\z1\ze\s*$" keepend contains=@markdownHighlight_'.s:include.s:concealends
exe 'syn region markdownHighlight_'.s:region.' matchgroup=markdownCodeDelimiter start="^\s*\z(\~\{3,\}\)\s*\%({.\{-}\.\)\='.s:lang.'}\=\S\@!.*$" end="^\s*\z1\ze\s*$" keepend contains=@markdownHighlight_'.s:include.s:concealends
exe 'syn region markdownHighlight_'.s:region.' matchgroup=markdownCodeDelimiter start="^>\s\+\z(`\{3,\}\)\s*\%({.\{-}\.\)\='.s:lang.'}\=\S\@!.*$" end="^>\s\+\z1\ze\s*$" keepend contains=markdownBlockquote,@markdownHighlight_'.s:include.s:concealends
exe 'syn region markdownHighlight_'.s:region.' matchgroup=markdownCodeDelimiter start="^>\s\+\z(\~\{3,\}\)\s*\%({.\{-}\.\)\='.s:lang.'}\=\S\@!.*$" end="^>\s\+\z1\ze\s*$" keepend contains=markdownBlockquote,@markdownHighlight_'.s:include.s:concealends
let s:done_include[matchstr(s:type,'[^.]*')] = 1
endfor
unlet! s:type
unlet! s:done_include
unlet! s:region
unlet! s:lang
unlet! s:include

if get(b:, 'markdown_yaml_head', get(g:, 'markdown_yaml_head', main_syntax ==# 'markdown'))
syn include @markdownYamlTop syntax/yaml.vim
Expand Down