mkd.vim (4314B)
1 " Vim syntax file 2 " Language: Markdown 3 " Maintainer: Ben Williams <benw@plasticboy.com> 4 " URL: http://plasticboy.com/markdown-vim-mode/ 5 " Version: 9 6 " Last Change: 2009 May 18 7 " Remark: Uses HTML syntax file 8 " Remark: I don't do anything with angle brackets (<>) because that would too easily 9 " easily conflict with HTML syntax 10 " TODO: Handle stuff contained within stuff (e.g. headings within blockquotes) 11 12 13 " Read the HTML syntax to start with 14 if version < 600 15 so <sfile>:p:h/html.vim 16 else 17 runtime! syntax/html.vim 18 unlet b:current_syntax 19 endif 20 21 if version < 600 22 syntax clear 23 elseif exists("b:current_syntax") 24 finish 25 endif 26 27 " don't use standard HiLink, it will not work with included syntax files 28 if version < 508 29 command! -nargs=+ HtmlHiLink hi link <args> 30 else 31 command! -nargs=+ HtmlHiLink hi def link <args> 32 endif 33 34 syn spell toplevel 35 syn case ignore 36 syn sync linebreaks=1 37 38 "additions to HTML groups 39 syn region htmlBold start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\*\@!/ end=/\\\@<!\*\@<!\*\*\*\@!\($\|\A\)\@=/ contains=@Spell,htmlItalic 40 syn region htmlItalic start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\@!/ end=/\\\@<!\*\@<!\*\*\@!\($\|\A\)\@=/ contains=htmlBold,@Spell 41 42 " [link](URL) | [link][id] | [link][] 43 syn region mkdLink matchgroup=mkdDelimiter start="\!\?\[" end="\]\ze\s*[[(]" contains=@Spell nextgroup=mkdURL,mkdID skipwhite oneline 44 syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained 45 syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained 46 47 " Link definitions: [id]: URL (Optional Title) 48 " TODO handle automatic links without colliding with htmlTag (<URL>) 49 syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite 50 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline 51 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained 52 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained 53 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained 54 55 "define Markdown groups 56 syn match mkdLineContinue ".$" contained 57 syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/ 58 syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/ 59 syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/ 60 syn match mkdRule /^\s*-\{3,}$/ 61 syn match mkdRule /^\s*\*\{3,5}$/ 62 syn match mkdListItem "^\s*[-*+]\s\+" 63 syn match mkdListItem "^\s*\d\+\.\s\+" 64 syn match mkdCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ 65 syn match mkdLineBreak / \+$/ 66 syn region mkdCode start=/\\\@<!`/ end=/\\\@<!`/ 67 syn region mkdCode start=/\s*``[^`]*/ end=/[^`]*``\s*/ 68 syn region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLineBreak,mkdLineContinue,@Spell 69 syn region mkdCode start="<pre[^>]*>" end="</pre>" 70 syn region mkdCode start="<code[^>]*>" end="</code>" 71 72 "HTML headings 73 syn region htmlH1 start="^\s*#" end="\($\|#\+\)" contains=@Spell 74 syn region htmlH2 start="^\s*##" end="\($\|#\+\)" contains=@Spell 75 syn region htmlH3 start="^\s*###" end="\($\|#\+\)" contains=@Spell 76 syn region htmlH4 start="^\s*####" end="\($\|#\+\)" contains=@Spell 77 syn region htmlH5 start="^\s*#####" end="\($\|#\+\)" contains=@Spell 78 syn region htmlH6 start="^\s*######" end="\($\|#\+\)" contains=@Spell 79 syn match htmlH1 /^.\+\n=\+$/ contains=@Spell 80 syn match htmlH2 /^.\+\n-\+$/ contains=@Spell 81 82 "highlighting for Markdown groups 83 HtmlHiLink mkdString String 84 HtmlHiLink mkdCode String 85 HtmlHiLink mkdBlockquote Comment 86 HtmlHiLink mkdLineContinue Comment 87 HtmlHiLink mkdListItem Identifier 88 HtmlHiLink mkdRule Identifier 89 HtmlHiLink mkdLineBreak Todo 90 HtmlHiLink mkdLink htmlLink 91 HtmlHiLink mkdURL htmlString 92 HtmlHiLink mkdID Identifier 93 HtmlHiLink mkdLinkDef mkdID 94 HtmlHiLink mkdLinkDefTarget mkdURL 95 HtmlHiLink mkdLinkTitle htmlString 96 97 HtmlHiLink mkdDelimiter Delimiter 98 99 let b:current_syntax = "mkd" 100 101 delcommand HtmlHiLink 102 " vim: ts=8