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 if has('conceal') && get(g:, 'vim_markdown_conceal', 1)
40 let s:conceal = ' conceal'
41 let s:concealends = ' concealends'
44 " additions to HTML groups
45 if get(g:, 'vim_markdown_emphasis_multiline', 1)
48 let s:oneline = ' oneline'
50 execute 'syn region htmlItalic start="\%(^\|\s\)\zs\*\ze[^\\\*\t ]\%(\%([^*]\|\\\*\|\n\)*[^\\\*\t ]\)\?\*\_W" end="[^\\\*\t ]\zs\*\ze\_W" keepend' . s:oneline
51 execute 'syn region htmlItalic start="\%(^\|\s\)\zs_\ze[^\\_\t ]" end="[^\\_\t ]\zs_\ze\_W" keepend' . s:oneline
52 execute 'syn region htmlBold start="\%(^\|\s\)\*\*\ze\S" end="\S\zs\*\*" keepend' . s:oneline
53 execute 'syn region htmlBold start="\%(^\|\s\)\zs__\ze\S" end="\S\zs__" keepend' . s:oneline
54 execute 'syn region htmlBoldItalic start="\%(^\|\s\)\zs\*\*\*\ze\S" end="\S\zs\*\*\*" keepend' . s:oneline
55 execute 'syn region htmlBoldItalic start="\%(^\|\s\)\zs___\ze\S" end="\S\zs___" keepend' . s:oneline
57 " [link](URL) | [link][id] | [link][] | ![image](URL)
58 syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^" end="\]"
59 execute 'syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained oneline' . s:conceal
60 execute 'syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained oneline' . s:conceal
61 execute 'syn region mkdLink matchgroup=mkdDelimiter start="\\\@<!!\?\[" end="\n\{-,1}[^]]\{-}\zs\]\ze[[(]" contains=@mkdNonListItem,@Spell nextgroup=mkdURL,mkdID skipwhite oneline' . s:concealends
63 " Autolink without angle brackets.
64 " mkd inline links: protocol optional user:pass@ sub/domain .com, .co.uk, etc optional port path/querystring/hash fragment
65 " ------------ _____________________ ----------------------------- _________________________ ----------------- __
66 syn match mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z0-9][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
68 " Autolink with parenthesis.
69 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=")"
71 " Autolink with angle brackets.
72 syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@<!<\ze[a-z][a-z0-9,.-]\{1,22}:\/\/[^> ]*>" end=">"
74 " Link definitions: [id]: URL (Optional Title)
75 syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
76 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
77 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained
78 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
79 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained
82 syn region htmlH1 start="^\s*#" end="$" contains=mkdLink,mkdInlineURL,@Spell
83 syn region htmlH2 start="^\s*##" end="$" contains=mkdLink,mkdInlineURL,@Spell
84 syn region htmlH3 start="^\s*###" end="$" contains=mkdLink,mkdInlineURL,@Spell
85 syn region htmlH4 start="^\s*####" end="$" contains=mkdLink,mkdInlineURL,@Spell
86 syn region htmlH5 start="^\s*#####" end="$" contains=mkdLink,mkdInlineURL,@Spell
87 syn region htmlH6 start="^\s*######" end="$" contains=mkdLink,mkdInlineURL,@Spell
88 syn match htmlH1 /^.\+\n=\+$/ contains=mkdLink,mkdInlineURL,@Spell
89 syn match htmlH2 /^.\+\n-\+$/ contains=mkdLink,mkdInlineURL,@Spell
91 "define Markdown groups
92 syn match mkdLineBreak / \+$/
93 syn region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLink,mkdInlineURL,mkdLineBreak,@Spell
94 syn region mkdCode start=/\(\([^\\]\|^\)\\\)\@<!`/ end=/\(\([^\\]\|^\)\\\)\@<!`/
95 syn region mkdCode start=/\s*``[^`]*/ end=/[^`]*``\s*/
96 syn region mkdCode start=/^\s*\z(`\{3,}\)[^`]*$/ end=/^\s*\z1`*\s*$/
97 syn region mkdCode start=/\s*\~\~[^\~]*/ end=/[^\~]*\~\~\s*/
98 syn region mkdCode start=/^\s*\z(\~\{3,}\)\s*[0-9A-Za-z_+-]*\s*$/ end=/^\s*\z1\~*\s*$/
99 syn region mkdCode start="<pre[^>]*\\\@<!>" end="</pre>"
100 syn region mkdCode start="<code[^>]*\\\@<!>" end="</code>"
101 syn region mkdFootnote start="\[^" end="\]"
102 syn match mkdCode /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/
103 syn match mkdCode /\%^\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/
104 syn match mkdCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained
105 syn match mkdListItem /^\s*\%([-*+]\|\d\+\.\)\ze\s\+/ contained
106 syn region mkdListItemLine start="^\s*\%([-*+]\|\d\+\.\)\s\+" end="$" oneline contains=@mkdNonListItem,mkdListItem,@Spell
107 syn region mkdNonListItemBlock start="\(\%^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@!\|\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!\)" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
108 syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
109 syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/
110 syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/
111 syn match mkdRule /^\s*-\{3,}$/
112 syn match mkdRule /^\s*\*\{3,5}$/
115 if get(g:, 'vim_markdown_frontmatter', 0)
116 syn include @yamlTop syntax/yaml.vim
117 syn region Comment matchgroup=mkdDelimiter start="\%^---$" end="^---$" contains=@yamlTop keepend
118 unlet! b:current_syntax
121 if get(g:, 'vim_markdown_toml_frontmatter', 0)
123 syn include @tomlTop syntax/toml.vim
124 syn region Comment matchgroup=mkdDelimiter start="\%^+++$" end="^+++$" transparent contains=@tomlTop keepend
125 unlet! b:current_syntax
127 syn region Comment matchgroup=mkdDelimiter start="\%^+++$" end="^+++$"
131 if get(g:, 'vim_markdown_json_frontmatter', 0)
133 syn include @jsonTop syntax/json.vim
134 syn region Comment matchgroup=mkdDelimiter start="\%^{$" end="^}$" contains=@jsonTop keepend
135 unlet! b:current_syntax
137 syn region Comment matchgroup=mkdDelimiter start="\%^{$" end="^}$"
141 if get(g:, 'vim_markdown_math', 0)
142 syn include @tex syntax/tex.vim
143 syn region mkdMath start="\\\@<!\$" end="\$" contains=@tex keepend
144 syn region mkdMath start="\\\@<!\$\$" end="\$\$" contains=@tex keepend
147 syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath
149 "highlighting for Markdown groups
150 HtmlHiLink mkdString String
151 HtmlHiLink mkdCode String
152 HtmlHiLink mkdCodeStart String
153 HtmlHiLink mkdCodeEnd String
154 HtmlHiLink mkdFootnote Comment
155 HtmlHiLink mkdBlockquote Comment
156 HtmlHiLink mkdListItem Identifier
157 HtmlHiLink mkdRule Identifier
158 HtmlHiLink mkdLineBreak Visual
159 HtmlHiLink mkdFootnotes htmlLink
160 HtmlHiLink mkdLink htmlLink
161 HtmlHiLink mkdURL htmlString
162 HtmlHiLink mkdInlineURL htmlLink
163 HtmlHiLink mkdID Identifier
164 HtmlHiLink mkdLinkDef mkdID
165 HtmlHiLink mkdLinkDefTarget mkdURL
166 HtmlHiLink mkdLinkTitle htmlString
167 HtmlHiLink mkdDelimiter Delimiter
169 let b:current_syntax = "mkd"
171 delcommand HtmlHiLink