" original version from Steve Losh's gist: https://gist.github.com/1038710
function! s:is_mkdCode(lnum)
- return synIDattr(synID(a:lnum, 1, 0), 'name') == 'mkdCode'
+ let name = synIDattr(synID(a:lnum, 1, 0), 'name')
+ return (name =~ '^mkd\%(Code$\|Snippet\)' || name != '' && name !~ '^\%(mkd\|html\)')
endfunction
if get(g:, "vim_markdown_folding_style_pythonic", 0)
command! -buffer Toct call s:Toc('tab')
" Heavily based on vim-notes - http://peterodding.com/code/vim/notes/
+let s:filetype_dict = {
+ \ 'c++': 'cpp',
+ \ 'viml': 'vim'
+\ }
+
function! s:Markdown_highlight_sources(force)
" Syntax highlight source code embedded in notes.
" Look for code blocks in the current file
let filetypes = {}
for line in getline(1, '$')
- let ft = matchstr(line, '```\zs\w*\>')
+ let ft = matchstr(line, '```\zs[0-9A-Za-z_+-]*')
if !empty(ft) && ft !~ '^\d*$' | let filetypes[ft] = 1 | endif
endfor
if !exists('b:mkd_known_filetypes')
let endgroup = 'mkdCodeEnd'
for ft in keys(filetypes)
if a:force || !has_key(b:mkd_known_filetypes, ft)
-
- let group = 'mkdSnippet' . toupper(ft)
- let include = s:syntax_include(ft)
+ if has_key(s:filetype_dict, ft)
+ let filetype = s:filetype_dict[ft]
+ else
+ let filetype = ft
+ endif
+ let group = 'mkdSnippet' . toupper(substitute(filetype, "[+-]", "_", "g"))
+ let include = s:syntax_include(filetype)
let command = 'syntax region %s matchgroup=%s start="^\s*```%s$" matchgroup=%s end="\s*```$" keepend contains=%s%s'
execute printf(command, group, startgroup, ft, endgroup, include, has('conceal') ? ' concealends' : '')
execute printf('syntax cluster mkdNonListItem add=%s', group)
if exists("*GetMarkdownIndent") | finish | endif
function! s:is_mkdCode(lnum)
- return synIDattr(synID(a:lnum, 1, 0), 'name') == 'mkdCode'
+ let name = synIDattr(synID(a:lnum, 1, 0), 'name')
+ return (name =~ '^mkd\%(Code$\|Snippet\)' || name != '' && name !~ '^\%(mkd\|html\)')
endfunction
function! s:is_li_start(line)
syn region mkdCode start=/^\s*```\s*[0-9A-Za-z_+-]*\s*$/ end=/^\s*```\s*$/
syn region mkdCode start=/\s*\~\~[^\~]*/ end=/[^\~]*\~\~\s*/
syn region mkdCode start=/^\s*\~\~\~\s*[0-9A-Za-z_+-]*\s*$/ end=/^\s*\~\~\~\s*$/
-syn match mkdCodeStart /^```\w*$/
-syn match mkdCodeEnd /^```$/
syn region mkdCode start="<pre[^>]*>" end="</pre>"
syn region mkdCode start="<code[^>]*>" end="</code>"
syn region mkdFootnote start="\[^" end="\]"
syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$\$" end="\$\$" contains=@tex
endif
-syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdListItem,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath,mkdCodeStart,mkdCodeEnd
+syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdListItem,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath
"highlighting for Markdown groups
HtmlHiLink mkdString String
HtmlHiLink mkdCode String
+HtmlHiLink mkdCodeStart String
+HtmlHiLink mkdCodeEnd String
HtmlHiLink mkdFootnote Comment
HtmlHiLink mkdBlockquote Comment
HtmlHiLink mkdLineContinue Comment
AssertNotEqual SyntaxOf('b'), 'mkdCode'
AssertEqual SyntaxOf('c'), 'mkdCode'
+Given markdown;
+```c++
+#include <iostream>
+code
+```
+
+```ruby
+def a
+end
+```
+
+Execute (fenced code block syntax with a language specifier):
+ let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'Markdown_refresh_syntax')
+ call b:func(0)
+ AssertEqual SyntaxOf('include'), 'cInclude'
+ AssertEqual SyntaxOf('code'), 'mkdSnippetCPP'
+ AssertEqual SyntaxOf('def'), 'rubyDefine'
+
+Given markdown;
+```a+b-
+code
+```
+
+Execute (fenced code block syntax with an unknown language specifier):
+ let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'Markdown_refresh_syntax')
+ call b:func(0)
+ AssertEqual SyntaxOf('code'), 'mkdSnippetA_B_'
+
# Math
Given markdown;