]> git.madduck.net Git - etc/vim.git/blob - syntax/markdown.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

39d5e53ac18dea9e178f2894c5adc09709bbdee0
[etc/vim.git] / syntax / markdown.vim
1 " Vim syntax file
2 " Language:     Markdown
3 " Maintainer:   Ben Williams <benw@plasticboy.com>
4 " URL:          http://plasticboy.com/markdown-vim-mode/
5 " Remark:       Uses HTML syntax file
6 " TODO:         Handle stuff contained within stuff (e.g. headings within blockquotes)
7
8
9 " Read the HTML syntax to start with
10 if version < 600
11   so <sfile>:p:h/html.vim
12 else
13   runtime! syntax/html.vim
14
15   if exists('b:current_syntax')
16     unlet b:current_syntax
17   endif
18 endif
19
20 if version < 600
21   syntax clear
22 elseif exists("b:current_syntax")
23   finish
24 endif
25
26 " don't use standard HiLink, it will not work with included syntax files
27 if version < 508
28   command! -nargs=+ HtmlHiLink hi link <args>
29 else
30   command! -nargs=+ HtmlHiLink hi def link <args>
31 endif
32
33 syn spell toplevel
34 syn case ignore
35 syn sync linebreaks=1
36
37 "additions to HTML groups
38 syn region htmlItalic start="\\\@<!\*\ze\S" end="\S\zs\\\@<!\*" keepend oneline
39 syn region htmlItalic start="\(^\|\s\)\@<=_\|\\\@<!_\([^_]\+\s\)\@=" end="\S\@<=[^\\]_\|[^\\]_\S\@=" keepend oneline
40 syn region htmlBold start="\*\*\ze\S" end="\S\zs\*\*" keepend oneline
41 syn region htmlBold start="__\ze\S" end="\S\zs__" keepend oneline
42 syn region htmlBoldItalic start="\*\*\*\ze\S" end="\S\zs\*\*\*" keepend oneline
43 syn region htmlBoldItalic start="___\ze\S" end="\S\zs___" keepend oneline
44
45 " [link](URL) | [link][id] | [link][] | ![image](URL)
46 syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^"    end="\]"
47 syn region mkdID matchgroup=mkdDelimiter        start="\["    end="\]" contained oneline
48 syn region mkdURL matchgroup=mkdDelimiter       start="("     end=")"  contained oneline
49 syn region mkdLink matchgroup=mkdDelimiter      start="\\\@<!!\?\[" end="\]\ze\s*[[(]" contains=@mkdNonListItem,@Spell nextgroup=mkdURL,mkdID skipwhite oneline
50
51 " Autolink without angle brackets.
52 " mkd  inline links:           protocol   optional  user:pass@       sub/domain                 .com, .co.uk, etc      optional port   path/querystring/hash fragment
53 "                            ------------ _____________________ --------------------------- ________________________ ----------------- __
54 syntax match   mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
55
56 " Autolink with parenthesis.
57 syntax region  mkdInlineURL matchgroup=mkdDelimiter start="(\(https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*)\)\@=" end=")"
58
59 " Autolink with angle brackets.
60 syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@<!<\(\(https\?\|ftp\|git\|coap\|doi\|javascript\|aaas\?\|about\|acap\|cap\|cid\|crid\|data\|dav\|dict\|dns\|file\|geo\|go\|gopher\|h323\|iax\|icap\|im\|imap\|info\|ipp\|iris\|iris.beep\|iris.xpc\|iris.xpcs\|iris.lwz\|ldaps\?\|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\|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\|gizmoproject\|gtalk\|hcp\|icon\|ipn\|irc6\|ircs\?\|itms\|jar\|jms\|keyparc\|lastfm\|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
62 " Link definitions: [id]: URL (Optional Title)
63 syn region mkdLinkDef matchgroup=mkdDelimiter   start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
64 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]"   contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
65 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+     end=+"+  contained
66 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+     end=+'+  contained
67 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+     end=+)+  contained
68
69 "HTML headings
70 syn region htmlH1       start="^\s*#"                   end="$" contains=@Spell
71 syn region htmlH2       start="^\s*##"                  end="$" contains=@Spell
72 syn region htmlH3       start="^\s*###"                 end="$" contains=@Spell
73 syn region htmlH4       start="^\s*####"                end="$" contains=@Spell
74 syn region htmlH5       start="^\s*#####"               end="$" contains=@Spell
75 syn region htmlH6       start="^\s*######"              end="$" contains=@Spell
76 syn match  htmlH1       /^.\+\n=\+$/ contains=@Spell
77 syn match  htmlH2       /^.\+\n-\+$/ contains=@Spell
78
79 "define Markdown groups
80 syn match  mkdLineContinue ".$" contained
81 syn match  mkdLineBreak    /  \+$/
82 syn region mkdBlockquote   start=/^\s*>/                   end=/$/ contains=mkdLineBreak,mkdLineContinue,@Spell
83 syn region mkdCode         start=/\(\([^\\]\|^\)\\\)\@<!`/ end=/\(\([^\\]\|^\)\\\)\@<!`/
84 syn region mkdCode         start=/\s*``[^`]*/              end=/[^`]*``\s*/
85 syn region mkdCode         start=/^\s*\z(`\{3,}\)\s*[0-9A-Za-z_+-]*\s*$/          end=/^\s*\z1`*\s*$/
86 syn region mkdCode         start=/\s*\~\~[^\~]*/              end=/[^\~]*\~\~\s*/
87 syn region mkdCode         start=/^\s*\z(\~\{3,}\)\s*[0-9A-Za-z_+-]*\s*$/         end=/^\s*\z1\~*\s*$/
88 syn region mkdCode         start="<pre[^>]*>"              end="</pre>"
89 syn region mkdCode         start="<code[^>]*>"             end="</code>"
90 syn region mkdFootnote     start="\[^"                     end="\]"
91 syn match  mkdCode         /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/
92 syn match  mkdCode         /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained
93 syn region mkdListItemLine matchgroup=mkdListItem start="^\s*\%([-*+]\|\d\+\.\)\s\+" end="$" contains=@mkdNonListItem,@Spell
94 syn region mkdNonListItemBlock start="\(\%^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@!\|\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!\)" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
95 syn match  mkdRule         /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
96 syn match  mkdRule         /^\s*-\s\{0,1}-\s\{0,1}-$/
97 syn match  mkdRule         /^\s*_\s\{0,1}_\s\{0,1}_$/
98 syn match  mkdRule         /^\s*-\{3,}$/
99 syn match  mkdRule         /^\s*\*\{3,5}$/
100
101 " YAML frontmatter
102 if get(g:, 'vim_markdown_frontmatter', 0)
103   syn include @yamlTop syntax/yaml.vim
104   syn region Comment matchgroup=mkdDelimiter start="\%^---$" end="^---$" contains=@yamlTop
105 endif
106
107 if get(g:, 'vim_markdown_math', 0)
108   syn include @tex syntax/tex.vim
109   syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$" end="\$" contains=@tex
110   syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$\$" end="\$\$" contains=@tex
111 endif
112
113 syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdListItem,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath
114
115 "highlighting for Markdown groups
116 HtmlHiLink mkdString        String
117 HtmlHiLink mkdCode          String
118 HtmlHiLink mkdCodeStart     String
119 HtmlHiLink mkdCodeEnd       String
120 HtmlHiLink mkdFootnote      Comment
121 HtmlHiLink mkdBlockquote    Comment
122 HtmlHiLink mkdLineContinue  Comment
123 HtmlHiLink mkdListItem      Identifier
124 HtmlHiLink mkdRule          Identifier
125 HtmlHiLink mkdLineBreak     Todo
126 HtmlHiLink mkdFootnotes     htmlLink
127 HtmlHiLink mkdLink          htmlLink
128 HtmlHiLink mkdURL           htmlString
129 HtmlHiLink mkdInlineURL     htmlLink
130 HtmlHiLink mkdID            Identifier
131 HtmlHiLink mkdLinkDef       mkdID
132 HtmlHiLink mkdLinkDefTarget mkdURL
133 HtmlHiLink mkdLinkTitle     htmlString
134 HtmlHiLink mkdDelimiter     Delimiter
135
136 let b:current_syntax = "mkd"
137
138 delcommand HtmlHiLink
139 " vim: ts=8