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 " Heavily based on vim-notes - http://peterodding.com/code/vim/notes/
2 function! s:Markdown_highlight_sources()
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 !empty(ft) && ft !~ '^\d*$' | let filetypes[ft] = 1 | endif
10 if !exists('b:mkd_known_filetypes')
11 let b:mkd_known_filetypes = {}
13 if b:mkd_known_filetypes == filetypes || empty(filetypes)
17 " 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 if !has_key(b:mkd_known_filetypes, ft)
23 let group = 'mkdSnippet' . toupper(ft)
24 let include = s:syntax_include(ft)
25 let command = 'syntax region %s matchgroup=%s start="^\s*```%s$" matchgroup=%s end="\s*```$" keepend contains=%s%s'
26 execute printf(command, group, startgroup, ft, endgroup, include, has('conceal') ? ' concealends' : '')
27 execute printf('syntax cluster mkdNonListItem add=%s', group)
29 let b:mkd_known_filetypes[ft] = 1
34 function! s:syntax_include(filetype)
35 " Include the syntax highlighting of another {filetype}.
36 let grouplistname = '@' . toupper(a:filetype)
37 " Unset the name of the current syntax while including the other syntax
38 " because some syntax scripts do nothing when "b:current_syntax" is set
39 if exists('b:current_syntax')
40 let syntax_save = b:current_syntax
41 unlet b:current_syntax
44 execute 'syntax include' grouplistname 'syntax/' . a:filetype . '.vim'
45 execute 'syntax include' grouplistname 'after/syntax/' . a:filetype . '.vim'
47 " Ignore missing scripts
49 " Restore the name of the current syntax
50 if exists('syntax_save')
51 let b:current_syntax = syntax_save
52 elseif exists('b:current_syntax')
53 unlet b:current_syntax
59 function! s:Markdown_refresh_syntax()
60 if &filetype == 'mkd' && line('$') > 1
61 call s:Markdown_highlight_sources()
67 au BufReadPost * call s:Markdown_refresh_syntax()
68 au BufReadPost,BufWritePost * call s:Markdown_refresh_syntax()
69 au InsertEnter,InsertLeave * call s:Markdown_refresh_syntax()
70 au CursorHold,CursorHoldI * call s:Markdown_refresh_syntax()