From b2697b0adfe5428b86c8470a5f9d8da667bb2785 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 2 May 2012 21:41:22 -0400 Subject: [PATCH] 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. Closes #17. --- syntax/markdown.vim | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index bc1563b..558b854 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -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*.*$" 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\@="