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/
5 " Remark: Uses HTML syntax file
6 " TODO: Handle stuff contained within stuff (e.g. headings within blockquotes)
9 " Read the HTML syntax to start with
11 so <sfile>:p:h/html.vim
13 runtime! syntax/html.vim
15 if exists('b:current_syntax')
16 unlet b:current_syntax
22 elseif exists("b:current_syntax")
26 " don't use standard HiLink, it will not work with included syntax files
28 command! -nargs=+ HtmlHiLink hi link <args>
30 command! -nargs=+ HtmlHiLink hi def link <args>
38 let s:concealends = ''
40 let s:conceal = ' conceal'
41 let s:concealends = ' concealends'
44 "additions to HTML groups
45 syn region htmlItalic start="\\\@<!\*\ze[^\\\*\t ]" end="[^\\\*\t ]\zs\*" keepend oneline
46 syn region htmlItalic start="\\\@<!_\ze[^\\_\t ]" end="[^\\_\t ]\zs_" keepend oneline
47 syn region htmlBold start="\*\*\ze\S" end="\S\zs\*\*" keepend oneline
48 syn region htmlBold start="__\ze\S" end="\S\zs__" keepend oneline
49 syn region htmlBoldItalic start="\*\*\*\ze\S" end="\S\zs\*\*\*" keepend oneline
50 syn region htmlBoldItalic start="___\ze\S" end="\S\zs___" keepend oneline
52 " [link](URL) | [link][id] | [link][] | ![image](URL)
53 syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^" end="\]"
54 execute 'syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained oneline' . s:conceal
55 execute 'syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained oneline' . s:conceal
56 execute 'syn region mkdLink matchgroup=mkdDelimiter start="\\\@<!!\?\[" end="\]\ze\s*[[(]" contains=@mkdNonListItem,@Spell nextgroup=mkdURL,mkdID skipwhite oneline' . s:concealends
58 " Autolink without angle brackets.
59 " mkd inline links: protocol optional user:pass@ sub/domain .com, .co.uk, etc optional port path/querystring/hash fragment
60 " ------------ _____________________ --------------------------- ________________________ ----------------- __
61 syntax match mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
63 " Autolink with parenthesis.
64 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=")"
66 " Autolink with angle brackets.
67 syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@<!<\ze[a-z][a-z0-9,.-]\{1,22}:\/\/[^> ]*>" end=">"
69 " Link definitions: [id]: URL (Optional Title)
70 syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
71 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
72 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained
73 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
74 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained
77 syn region htmlH1 start="^\s*#" end="$" contains=@Spell
78 syn region htmlH2 start="^\s*##" end="$" contains=@Spell
79 syn region htmlH3 start="^\s*###" end="$" contains=@Spell
80 syn region htmlH4 start="^\s*####" end="$" contains=@Spell
81 syn region htmlH5 start="^\s*#####" end="$" contains=@Spell
82 syn region htmlH6 start="^\s*######" end="$" contains=@Spell
83 syn match htmlH1 /^.\+\n=\+$/ contains=@Spell
84 syn match htmlH2 /^.\+\n-\+$/ contains=@Spell
86 "define Markdown groups
87 syn match mkdLineContinue ".$" contained
88 syn match mkdLineBreak / \+$/
89 syn region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLineBreak,mkdLineContinue,@Spell
90 syn region mkdCode start=/\(\([^\\]\|^\)\\\)\@<!`/ end=/\(\([^\\]\|^\)\\\)\@<!`/
91 syn region mkdCode start=/\s*``[^`]*/ end=/[^`]*``\s*/
92 syn region mkdCode start=/^\s*\z(`\{3,}\)\s*[0-9A-Za-z_+-]*\s*$/ end=/^\s*\z1`*\s*$/
93 syn region mkdCode start=/\s*\~\~[^\~]*/ end=/[^\~]*\~\~\s*/
94 syn region mkdCode start=/^\s*\z(\~\{3,}\)\s*[0-9A-Za-z_+-]*\s*$/ end=/^\s*\z1\~*\s*$/
95 syn region mkdCode start="<pre[^>]*>" end="</pre>"
96 syn region mkdCode start="<code[^>]*>" end="</code>"
97 syn region mkdFootnote start="\[^" end="\]"
98 syn match mkdCode /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/
99 syn match mkdCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained
100 syn region mkdListItemLine matchgroup=mkdListItem start="^\s*\%([-*+]\|\d\+\.\)\s\+" end="$" contains=@mkdNonListItem,@Spell
101 syn region mkdNonListItemBlock start="\(\%^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@!\|\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!\)" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
102 syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
103 syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/
104 syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/
105 syn match mkdRule /^\s*-\{3,}$/
106 syn match mkdRule /^\s*\*\{3,5}$/
109 if get(g:, 'vim_markdown_frontmatter', 0)
110 syn include @yamlTop syntax/yaml.vim
111 syn region Comment matchgroup=mkdDelimiter start="\%^---$" end="^---$" contains=@yamlTop
114 if get(g:, 'vim_markdown_math', 0)
115 syn include @tex syntax/tex.vim
116 syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$" end="\$" contains=@tex
117 syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$\$" end="\$\$" contains=@tex
120 syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdListItem,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath
122 "highlighting for Markdown groups
123 HtmlHiLink mkdString String
124 HtmlHiLink mkdCode String
125 HtmlHiLink mkdCodeStart String
126 HtmlHiLink mkdCodeEnd String
127 HtmlHiLink mkdFootnote Comment
128 HtmlHiLink mkdBlockquote Comment
129 HtmlHiLink mkdLineContinue Comment
130 HtmlHiLink mkdListItem Identifier
131 HtmlHiLink mkdRule Identifier
132 HtmlHiLink mkdLineBreak Todo
133 HtmlHiLink mkdFootnotes htmlLink
134 HtmlHiLink mkdLink htmlLink
135 HtmlHiLink mkdURL htmlString
136 HtmlHiLink mkdInlineURL htmlLink
137 HtmlHiLink mkdID Identifier
138 HtmlHiLink mkdLinkDef mkdID
139 HtmlHiLink mkdLinkDefTarget mkdURL
140 HtmlHiLink mkdLinkTitle htmlString
141 HtmlHiLink mkdDelimiter Delimiter
143 let b:current_syntax = "mkd"
145 delcommand HtmlHiLink