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.
3 " Maintainer: Ben Williams <benw@plasticboy.com>
4 " URL: http://plasticboy.com/markdown-vim-mode/
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)
13 " Read the HTML syntax to start with
15 so <sfile>:p:h/html.vim
17 runtime! syntax/html.vim
18 unlet b:current_syntax
23 elseif exists("b:current_syntax")
27 " don't use standard HiLink, it will not work with included syntax files
29 command! -nargs=+ HtmlHiLink hi link <args>
31 command! -nargs=+ HtmlHiLink hi def link <args>
38 "additions to HTML groups
39 syn region htmlItalic start="\\\@<!\*\S\@=" end="\S\@<=\\\@<!\*" keepend oneline
40 syn region htmlItalic start="\(^\|\s\)\@<=_\|\\\@<!_\([^_]\+\s\)\@=" end="\S\@<=_\|_\S\@=" keepend oneline
41 syn region htmlBold start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend oneline
42 syn region htmlBold start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" keepend oneline
43 syn region htmlBoldItalic start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend oneline
44 syn region htmlBoldItalic start="\S\@<=___\|___\S\@=" end="\S\@<=___\|___\S\@=" keepend oneline
46 " [link](URL) | [link][id] | [link][]
47 syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^" end="\]"
48 syn region mkdLink matchgroup=mkdDelimiter start="\\\@<!\[" end="\]\ze\s*[[(]" contains=@Spell nextgroup=mkdURL,mkdID skipwhite
49 syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained
50 syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained
51 " mkd inline links: protocol optional user:pass@ sub/domain .com, .co.uk, etc optional port path/querystring/hash fragment
52 " ------------ _____________________ --------------------------- ________________________ ----------------- __
53 syntax match mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
55 " Link definitions: [id]: URL (Optional Title)
56 " TODO handle automatic links without colliding with htmlTag (<URL>)
57 syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
58 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
59 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained
60 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
61 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained
63 "define Markdown groups
64 syn match mkdLineContinue ".$" contained
65 syn match mkdLineBreak / \+$/
66 syn region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLineBreak,mkdLineContinue,@Spell
67 syn region mkdCode start=/\(\([^\\]\|^\)\\\)\@<!`/ end=/\(\([^\\]\|^\)\\\)\@<!`/
68 syn region mkdCode start=/\s*``[^`]*/ end=/[^`]*``\s*/
69 syn region mkdCode start=/^```\s*\w*\s*$/ end=/^```\s*$/
70 syn region mkdCode start="<pre[^>]*>" end="</pre>"
71 syn region mkdCode start="<code[^>]*>" end="</code>"
72 syn match mkdCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/
73 syn match mkdListItem "^\s*[-*+]\s\+"
74 syn match mkdListItem "^\s*\d\+\.\s\+"
75 syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
76 syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/
77 syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/
78 syn match mkdRule /^\s*-\{3,}$/
79 syn match mkdRule /^\s*\*\{3,5}$/
82 syn region htmlH1 start="^\s*#" end="\($\|#\+\)" contains=@Spell
83 syn region htmlH2 start="^\s*##" end="\($\|#\+\)" contains=@Spell
84 syn region htmlH3 start="^\s*###" end="\($\|#\+\)" contains=@Spell
85 syn region htmlH4 start="^\s*####" end="\($\|#\+\)" contains=@Spell
86 syn region htmlH5 start="^\s*#####" end="\($\|#\+\)" contains=@Spell
87 syn region htmlH6 start="^\s*######" end="\($\|#\+\)" contains=@Spell
88 syn match htmlH1 /^.\+\n=\+$/ contains=@Spell
89 syn match htmlH2 /^.\+\n-\+$/ contains=@Spell
91 "highlighting for Markdown groups
92 HtmlHiLink mkdString String
93 HtmlHiLink mkdCode String
94 HtmlHiLink mkdBlockquote Comment
95 HtmlHiLink mkdLineContinue Comment
96 HtmlHiLink mkdListItem Identifier
97 HtmlHiLink mkdRule Identifier
98 HtmlHiLink mkdLineBreak Todo
99 HtmlHiLink mkdFootnotes htmlLink
100 HtmlHiLink mkdLink htmlLink
101 HtmlHiLink mkdURL htmlString
102 HtmlHiLink mkdInlineURL htmlLink
103 HtmlHiLink mkdID Identifier
104 HtmlHiLink mkdLinkDef mkdID
105 HtmlHiLink mkdLinkDefTarget mkdURL
106 HtmlHiLink mkdLinkTitle htmlString
108 HtmlHiLink mkdDelimiter Delimiter
110 let b:current_syntax = "mkd"
112 delcommand HtmlHiLink