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 = ''
39 let s:concealcode = ''
40 if has('conceal') && get(g:, 'vim_markdown_conceal', 1)
41 let s:conceal = ' conceal'
42 let s:concealends = ' concealends'
44 if has('conceal') && get(g:, 'vim_markdown_conceal_code_blocks', 1)
45 let s:concealcode = ' concealends'
48 " additions to HTML groups
49 if get(g:, 'vim_markdown_emphasis_multiline', 1)
52 let s:oneline = ' oneline'
54 syn region mkdItalic matchgroup=mkdItalic start="\%(\*\|_\)" end="\%(\*\|_\)"
55 syn region mkdBold matchgroup=mkdBold start="\%(\*\*\|__\)" end="\%(\*\*\|__\)"
56 syn region mkdBoldItalic matchgroup=mkdBoldItalic start="\%(\*\*\*\|___\)" end="\%(\*\*\*\|___\)"
57 execute 'syn region htmlItalic matchgroup=mkdItalic start="\%(^\|\s\)\zs\*\ze[^\\\*\t ]\%(\%([^*]\|\\\*\|\n\)*[^\\\*\t ]\)\?\*\_W" end="[^\\\*\t ]\zs\*\ze\_W" keepend contains=@Spell' . s:oneline . s:concealends
58 execute 'syn region htmlItalic matchgroup=mkdItalic start="\%(^\|\s\)\zs_\ze[^\\_\t ]" end="[^\\_\t ]\zs_\ze\_W" keepend contains=@Spell' . s:oneline . s:concealends
59 execute 'syn region htmlBold matchgroup=mkdBold start="\%(^\|\s\)\zs\*\*\ze\S" end="\S\zs\*\*" keepend contains=@Spell' . s:oneline . s:concealends
60 execute 'syn region htmlBold matchgroup=mkdBold start="\%(^\|\s\)\zs__\ze\S" end="\S\zs__" keepend contains=@Spell' . s:oneline . s:concealends
61 execute 'syn region htmlBoldItalic matchgroup=mkdBoldItalic start="\%(^\|\s\)\zs\*\*\*\ze\S" end="\S\zs\*\*\*" keepend contains=@Spell' . s:oneline . s:concealends
62 execute 'syn region htmlBoldItalic matchgroup=mkdBoldItalic start="\%(^\|\s\)\zs___\ze\S" end="\S\zs___" keepend contains=@Spell' . s:oneline . s:concealends
64 " [link](URL) | [link][id] | [link][] | ![image](URL)
65 syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^" end="\]"
66 execute 'syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained oneline' . s:conceal
67 execute 'syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained oneline' . s:conceal
68 execute 'syn region mkdLink matchgroup=mkdDelimiter start="\\\@<!!\?\[\ze[^]\n]*\n\?[^]\n]*\][[(]" end="\]" contains=@mkdNonListItem,@Spell nextgroup=mkdURL,mkdID skipwhite' . s:concealends
70 " Autolink without angle brackets.
71 " mkd inline links: protocol optional user:pass@ sub/domain .com, .co.uk, etc optional port path/querystring/hash fragment
72 " ------------ _____________________ ----------------------------- _________________________ ----------------- __
73 syn match mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z0-9][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
75 " Autolink with parenthesis.
76 syn region mkdInlineURL matchgroup=mkdDelimiter start="(\(https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z0-9][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*)\)\@=" end=")"
78 " Autolink with angle brackets.
79 syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@<!<\ze[a-z][a-z0-9,.-]\{1,22}:\/\/[^> ]*>" end=">"
81 " Link definitions: [id]: URL (Optional Title)
82 syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[\^\@!" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
83 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
84 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained
85 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
86 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained
89 syn region htmlH1 matchgroup=mkdHeading start="^\s*#" end="$" contains=mkdLink,mkdInlineURL,@Spell
90 syn region htmlH2 matchgroup=mkdHeading start="^\s*##" end="$" contains=mkdLink,mkdInlineURL,@Spell
91 syn region htmlH3 matchgroup=mkdHeading start="^\s*###" end="$" contains=mkdLink,mkdInlineURL,@Spell
92 syn region htmlH4 matchgroup=mkdHeading start="^\s*####" end="$" contains=mkdLink,mkdInlineURL,@Spell
93 syn region htmlH5 matchgroup=mkdHeading start="^\s*#####" end="$" contains=mkdLink,mkdInlineURL,@Spell
94 syn region htmlH6 matchgroup=mkdHeading start="^\s*######" end="$" contains=mkdLink,mkdInlineURL,@Spell
95 syn match htmlH1 /^.\+\n=\+$/ contains=mkdLink,mkdInlineURL,@Spell
96 syn match htmlH2 /^.\+\n-\+$/ contains=mkdLink,mkdInlineURL,@Spell
98 "define Markdown groups
99 syn match mkdLineBreak / \+$/
100 syn region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLink,mkdInlineURL,mkdLineBreak,@Spell
101 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/\(\([^\\]\|^\)\\\)\@<!`/ end=/`/' . s:concealcode
102 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/\(\([^\\]\|^\)\\\)\@<!``/ skip=/[^`]`[^`]/ end=/\(\([^\\]\|^\)\\\)\@<!``/' . s:concealcode
103 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/^\s*\z(`\{3,}\)[^`]*$/ end=/^\s*\z1`*\s*$/' . s:concealcode
104 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/\(\([^\\]\|^\)\\\)\@<!\~\~/ end=/\(\([^\\]\|^\)\\\)\@<!\~\~/' . s:concealcode
105 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/^\s*\z(\~\{3,}\)\s*[0-9A-Za-z_+-]*\s*$/ end=/^\s*\z1\~*\s*$/' . s:concealcode
106 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start="<pre[^>]*\\\@<!>" end="</pre>"' . s:concealcode
107 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start="<code[^>]*\\\@<!>" end="</code>"' . s:concealcode
108 syn region mkdFootnote start="\[^" end="\]"
109 syn match mkdCode /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/
110 syn match mkdCode /\%^\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/
111 syn match mkdCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained
112 syn match mkdListItem /^\s*\%([-*+]\|\d\+\.\)\ze\s\+/ contained
113 syn region mkdListItemLine start="^\s*\%([-*+]\|\d\+\.\)\s\+" end="$" oneline contains=@mkdNonListItem,mkdListItem,@Spell
114 syn region mkdNonListItemBlock start="\(\%^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@!\|\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!\)" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
115 syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*\(\*\|\s\)*$/
116 syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-\(-\|\s\)*$/
117 syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_\(_\|\s\)*$/
120 if get(g:, 'vim_markdown_frontmatter', 0)
121 syn include @yamlTop syntax/yaml.vim
122 syn region Comment matchgroup=mkdDelimiter start="\%^---$" end="^\(---\|\.\.\.\)$" contains=@yamlTop keepend
123 unlet! b:current_syntax
126 if get(g:, 'vim_markdown_toml_frontmatter', 0)
128 syn include @tomlTop syntax/toml.vim
129 syn region Comment matchgroup=mkdDelimiter start="\%^+++$" end="^+++$" transparent contains=@tomlTop keepend
130 unlet! b:current_syntax
132 syn region Comment matchgroup=mkdDelimiter start="\%^+++$" end="^+++$"
136 if get(g:, 'vim_markdown_json_frontmatter', 0)
138 syn include @jsonTop syntax/json.vim
139 syn region Comment matchgroup=mkdDelimiter start="\%^{$" end="^}$" contains=@jsonTop keepend
140 unlet! b:current_syntax
142 syn region Comment matchgroup=mkdDelimiter start="\%^{$" end="^}$"
146 if get(g:, 'vim_markdown_math', 0)
147 syn include @tex syntax/tex.vim
148 syn region mkdMath start="\\\@<!\$" end="\$" skip="\\\$" contains=@tex keepend
149 syn region mkdMath start="\\\@<!\$\$" end="\$\$" skip="\\\$" contains=@tex keepend
153 if get(g:, 'vim_markdown_strikethrough', 0)
154 syn region mkdStrike matchgroup=mkdStrike start="\%(\~\~\)" end="\%(\~\~\)"
155 HtmlHiLink mkdStrike htmlStrike
158 syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath
160 "highlighting for Markdown groups
161 HtmlHiLink mkdString String
162 HtmlHiLink mkdCode String
163 HtmlHiLink mkdCodeDelimiter String
164 HtmlHiLink mkdCodeStart String
165 HtmlHiLink mkdCodeEnd String
166 HtmlHiLink mkdFootnote Comment
167 HtmlHiLink mkdBlockquote Comment
168 HtmlHiLink mkdListItem Identifier
169 HtmlHiLink mkdRule Identifier
170 HtmlHiLink mkdLineBreak Visual
171 HtmlHiLink mkdFootnotes htmlLink
172 HtmlHiLink mkdLink htmlLink
173 HtmlHiLink mkdURL htmlString
174 HtmlHiLink mkdInlineURL htmlLink
175 HtmlHiLink mkdID Identifier
176 HtmlHiLink mkdLinkDef mkdID
177 HtmlHiLink mkdLinkDefTarget mkdURL
178 HtmlHiLink mkdLinkTitle htmlString
179 HtmlHiLink mkdDelimiter Delimiter
181 let b:current_syntax = "mkd"
183 delcommand HtmlHiLink