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 " TODO: Handle stuff contained within stuff (e.g. headings within blockquotes)
11 " Read the HTML syntax to start with
13 so <sfile>:p:h/html.vim
15 runtime! syntax/html.vim
17 if exists('b:current_syntax')
18 unlet b:current_syntax
24 elseif exists("b:current_syntax")
28 " don't use standard HiLink, it will not work with included syntax files
30 command! -nargs=+ HtmlHiLink hi link <args>
32 command! -nargs=+ HtmlHiLink hi def link <args>
39 "additions to HTML groups
40 syn region htmlItalic start="\\\@<!\*\S\@=" end="\S\@<=\\\@<!\*" keepend oneline
41 syn region htmlItalic start="\(^\|\s\)\@<=_\|\\\@<!_\([^_]\+\s\)\@=" end="\S\@<=_\|_\S\@=" keepend oneline
42 syn region htmlBold start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend oneline
43 syn region htmlBold start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" keepend oneline
44 syn region htmlBoldItalic start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend oneline
45 syn region htmlBoldItalic start="\S\@<=___\|___\S\@=" end="\S\@<=___\|___\S\@=" keepend oneline
47 " [link](URL) | [link][id] | [link][]
48 syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^" end="\]"
49 syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained oneline
50 syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained oneline
51 syn region mkdLink matchgroup=mkdDelimiter start="\\\@<!\[" end="\]\ze\s*[[(]" contains=@Spell nextgroup=mkdURL,mkdID skipwhite oneline
53 " Autolink without angle brackets.
54 " mkd inline links: protocol optional user:pass@ sub/domain .com, .co.uk, etc optional port path/querystring/hash fragment
55 " ------------ _____________________ --------------------------- ________________________ ----------------- __
56 syntax match mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
58 " Autolink with angle brackets.
59 syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@<!<\(\(coap\|doi\|javascript\|aaa\|aaas\|about\|acap\|cap\|cid\|crid\|data\|dav\|dict\|dns\|file\|ftp\|geo\|go\|gopher\|h323\|http\|https\|iax\|icap\|im\|imap\|info\|ipp\|iris\|iris.beep\|iris.xpc\|iris.xpcs\|iris.lwz\|ldap\|mailto\|mid\|msrp\|msrps\|mtqp\|mupdate\|news\|nfs\|ni\|nih\|nntp\|opaquelocktoken\|pop\|pres\|rtsp\|service\|session\|shttp\|sieve\|sip\|sips\|sms\|snmp,soap.beep\|soap.beeps\|tag\|tel\|telnet\|tftp\|thismessage\|tn3270\|tip\|tv\|urn\|vemmi\|ws\|wss\|xcon\|xcon-userid\|xmlrpc.beep\|xmlrpc.beeps\|xmpp\|z39.50r\|z39.50s\|adiumxtra\|afp\|afs\|aim\|apt,attachment\|aw\|beshare\|bitcoin\|bolo\|callto\|chrome,chrome-extension\|com-eventbrite-attendee\|content\|cvs,dlna-playsingle\|dlna-playcontainer\|dtn\|dvb\|ed2k\|facetime\|feed\|finger\|fish\|gg\|git\|gizmoproject\|gtalk\|hcp\|icon\|ipn\|irc\|irc6\|ircs\|itms\|jar\|jms\|keyparc\|lastfm\|ldaps\|magnet\|maps\|market,message\|mms\|ms-help\|msnim\|mumble\|mvn\|notes\|oid\|palm\|paparazzi\|platform\|proxy\|psyc\|query\|res\|resource\|rmi\|rsync\|rtmp\|secondlife\|sftp\|sgn\|skype\|smb\|soldat\|spotify\|ssh\|steam\|svn\|teamspeak\|things\|udp\|unreal\|ut2004\|ventrilo\|view-source\|webcal\|wtai\|wyciwyg\|xfire\|xri\|ymsgr\):\/\/[^> ]*>\)\@=" end=">"
61 " Link definitions: [id]: URL (Optional Title)
62 syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
63 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
64 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained
65 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
66 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained
68 "define Markdown groups
69 syn match mkdLineContinue ".$" contained
70 syn match mkdLineBreak / \+$/
71 syn region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLineBreak,mkdLineContinue,@Spell
72 syn region mkdCode start=/\(\([^\\]\|^\)\\\)\@<!`/ end=/\(\([^\\]\|^\)\\\)\@<!`/
73 syn region mkdCode start=/\s*``[^`]*/ end=/[^`]*``\s*/
74 syn region mkdCode start=/^\s*```\s*[0-9A-Za-z_-]*\s*$/ end=/^\s*```\s*$/
75 syn region mkdCode start="<pre[^>]*>" end="</pre>"
76 syn region mkdCode start="<code[^>]*>" end="</code>"
77 syn region mkdFootnote start="\[^" end="\]"
78 syn match mkdCode /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/
79 syn match mkdIndentCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained
80 syn match mkdListItem "^\s*[-*+]\s\+"
81 syn match mkdListItem "^\s*\d\+\.\s\+"
82 syn region mkdNonListItemBlock start="\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
83 syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
84 syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/
85 syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/
86 syn match mkdRule /^\s*-\{3,}$/
87 syn match mkdRule /^\s*\*\{3,5}$/
90 syn region htmlH1 start="^\s*#" end="\($\|#\+\)" contains=@Spell
91 syn region htmlH2 start="^\s*##" end="\($\|#\+\)" contains=@Spell
92 syn region htmlH3 start="^\s*###" end="\($\|#\+\)" contains=@Spell
93 syn region htmlH4 start="^\s*####" end="\($\|#\+\)" contains=@Spell
94 syn region htmlH5 start="^\s*#####" end="\($\|#\+\)" contains=@Spell
95 syn region htmlH6 start="^\s*######" end="\($\|#\+\)" contains=@Spell
96 syn match htmlH1 /^.\+\n=\+$/ contains=@Spell
97 syn match htmlH2 /^.\+\n-\+$/ contains=@Spell
99 if get(g:, 'vim_markdown_math', 0)
100 syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$" end="\$"
101 syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$\$" end="\$\$"
105 if get(g:, 'vim_markdown_frontmatter', 0)
106 syn include @yamlTop syntax/yaml.vim
107 syn region Comment matchgroup=mkdDelimiter start="\%^---$" end="^---$" contains=@yamlTop
110 syn cluster mkdNonListItem contains=htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdID,mkdURL,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdIndentCode,mkdListItem,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath
112 "highlighting for Markdown groups
113 HtmlHiLink mkdString String
114 HtmlHiLink mkdCode String
115 HtmlHiLink mkdIndentCode String
116 HtmlHiLink mkdFootnote Comment
117 HtmlHiLink mkdBlockquote Comment
118 HtmlHiLink mkdLineContinue Comment
119 HtmlHiLink mkdListItem Identifier
120 HtmlHiLink mkdRule Identifier
121 HtmlHiLink mkdLineBreak Todo
122 HtmlHiLink mkdFootnotes htmlLink
123 HtmlHiLink mkdLink htmlLink
124 HtmlHiLink mkdURL htmlString
125 HtmlHiLink mkdInlineURL htmlLink
126 HtmlHiLink mkdID Identifier
127 HtmlHiLink mkdLinkDef mkdID
128 HtmlHiLink mkdLinkDefTarget mkdURL
129 HtmlHiLink mkdLinkTitle htmlString
130 HtmlHiLink mkdMath Statement
131 HtmlHiLink mkdDelimiter Delimiter
133 " Automatically insert bullets
134 setlocal formatoptions+=r
135 " Do not automatically insert bullets when auto-wrapping with text-width
136 setlocal formatoptions-=c
137 " Accept various markers as bullets
138 setlocal comments=b:*,b:+,b:-
140 " Automatically continue blockquote on line break
141 setlocal comments+=b:>
143 let b:current_syntax = "mkd"
145 delcommand HtmlHiLink