All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Completely stolen from vim-notes - http://peterodding.com/code/vim/notes/
2 function! s:Markdown_highlight_sources(force)
3 " Syntax highlight source code embedded in notes.
4 " Look for code blocks in the current file
6 for line in getline(1, '$')
7 let ft = matchstr(line, '```\zs\w\+\>')
8 if ft !~ '^\d*$' | let filetypes[ft] = 1 | endif
10 " Don't refresh the highlighting if nothing has changed.
11 if !a:force && exists('b:mkd_previous_sources') && b:mkd_previous_sources == filetypes
14 let b:mkd_previous_sources = filetypes
16 " Now we're ready to actually highlight the code blocks.
18 let startgroup = 'mkdCodeStart'
19 let endgroup = 'mkdCodeEnd'
20 for ft in keys(filetypes)
21 let group = 'mkdSnippet' . toupper(ft)
22 let include = s:syntax_include(ft)
23 let command = 'syntax region %s matchgroup=%s start="^```%s$" matchgroup=%s end="^```$" keepend contains=%s%s'
24 execute printf(command, group, startgroup, ft, endgroup, include, has('conceal') ? ' concealends' : '')
25 execute printf('syntax cluster mkdNonListItem add=%s', group)
30 function! s:syntax_include(filetype)
31 " Include the syntax highlighting of another {filetype}.
32 let grouplistname = '@' . toupper(a:filetype)
33 " Unset the name of the current syntax while including the other syntax
34 " because some syntax scripts do nothing when "b:current_syntax" is set
35 if exists('b:current_syntax')
36 let syntax_save = b:current_syntax
37 unlet b:current_syntax
40 execute 'syntax include' grouplistname 'syntax/' . a:filetype . '.vim'
41 execute 'syntax include' grouplistname 'after/syntax/' . a:filetype . '.vim'
43 " Ignore missing scripts
45 " Restore the name of the current syntax
46 if exists('syntax_save')
47 let b:current_syntax = syntax_save
48 elseif exists('b:current_syntax')
49 unlet b:current_syntax
55 function! s:Markdown_refresh_syntax()
56 if &filetype == 'mkd' && line('$') > 1
57 call s:Markdown_highlight_sources(0)
63 au BufReadPost * call s:Markdown_refresh_syntax()
64 au BufReadPost,BufWritePost * call s:Markdown_refresh_syntax()
65 au InsertEnter,InsertLeave * call s:Markdown_refresh_syntax()
66 au CursorHold,CursorHoldI * call s:Markdown_refresh_syntax()