Highlight GitHub style fenced code blocks

One needs to opt-in to this by specifying which file types should be
highlighted:

    let g:markdown_github_languages = ['ruby', 'erb=eruby']

This may not work for all file types.
This commit is contained in:
Tim Pope
2012-05-02 21:41:22 -04:00
parent 5a70519e48
commit c1fca6e057

View File

@@ -7,9 +7,25 @@ if exists("b:current_syntax")
finish
endif
if !exists('main_syntax')
let main_syntax = 'markdown'
endif
runtime! syntax/html.vim
unlet! b:current_syntax
if !exists('g:markdown_fenced_languages')
let g:markdown_fenced_languages = []
endif
for s:type in map(copy(g:markdown_fenced_languages),'matchstr(v:val,"[^=]*$")')
if s:type =~ '\.'
let b:{matchstr(s:type,'[^.]*')}_subtype = matchstr(s:type,'\.\zs.*')
endif
exe 'syn include @markdownHighlight'.substitute(s:type,'\.','','g').' syntax/'.matchstr(s:type,'[^.]*').'.vim'
unlet! b:current_syntax
endfor
unlet! s:type
syn sync minlines=10
syn case ignore
@@ -68,6 +84,13 @@ syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" keepe
syn region markdownCode matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" keepend contains=markdownLineStart
syn region markdownCode matchgroup=markdownCodeDelimiter start="^\s*\zs```\s*\w*\ze\s*$" end="^```\ze\s*$" keepend
if main_syntax ==# 'markdown'
for s:type in g:markdown_fenced_languages
exe 'syn region markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\..*','','').' matchgroup=markdownCodeDelimiter start="^\s*\zs```'.matchstr(s:type,'[^=]*').'$" end="^```\ze\s*$" keepend contains=@markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\.','','g')
endfor
unlet! s:type
endif
syn match markdownEscape "\\[][\\`*_{}()#+.!-]"
syn match markdownError "\w\@<=_\w\@="