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="\%(^\|\s\)\zs\*\ze[^\\\*\t ]" end="[^\\\*\t ]\zs\*\ze\_W" keepend
46 "syn region htmlItalic start="\%(^\|\s\)\zs_\ze[^\\_\t ]" end="[^\\_\t ]\zs_\ze\_W" keepend
47 "syn region htmlBold start="\*\*\ze\S" end="\S\zs\*\*" keepend
48 "syn region htmlBold start="__\ze\S" end="\S\zs__" keepend
49 "syn region htmlBoldItalic start="\*\*\*\ze\S" end="\S\zs\*\*\*" keepend
50 "syn region htmlBoldItalic start="___\ze\S" end="\S\zs___" keepend
52 " emphasis stops at newline (in case a closing token is not found before)
53 "if get(g:, "vim_markdown_emphasis_stops_at_newline", 1)
54 " let esanl_pre = '\(\n\|'
55 " let esanl_suf = '\)'
60 "execute 'syn region htmlItalic start="\%(^\|\s\)\zs\*\ze[^\\\*\t ]" end="[^\\\*\t ]\zs' . esanl_pre . '\*' . esanl_suf . '\ze\_W" keepend'
61 "execute 'syn region htmlItalic start="\%(^\|\s\)\zs_\ze[^\\_\t ]" end="[^\\_\t ]\zs' . esanl_pre . '_' . esanl_suf . '\ze\_W" keepend'
62 "execute 'syn region htmlBold start="\*\*\ze\S" end="\S\zs' . esanl_pre . '\*\*' . esanl_suf . '" keepend'
63 "execute 'syn region htmlBold start="__\ze\S" end="\S\zs__" keepend
64 "execute 'syn region htmlBoldItalic start="\*\*\*\ze\S" end="\S\zs\*\*\*" keepend
65 "execute 'syn region htmlBoldItalic start="___\ze\S" end="\S\zs___" keepend
67 " single-line emphasis (emphasis only works with matching token in the same line)
68 syn region htmlItalic start="\%(^\|\s\)\zs\*\ze[^\\\*\t ]\([^\n]*[^\\\*\t ]\)\?\*" end="[^\\\*\t ]\zs\*\ze\_W" keepend
71 " [link](URL) | [link][id] | [link][] | ![image](URL)
72 syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^" end="\]"
73 execute 'syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained oneline' . s:conceal
74 execute 'syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained oneline' . s:conceal
75 execute 'syn region mkdLink matchgroup=mkdDelimiter start="\\\@<!!\?\[" end="\n\{-,1}[^]]\{-}\zs\]\ze[[(]" contains=@mkdNonListItem,@Spell nextgroup=mkdURL,mkdID skipwhite oneline' . s:concealends
77 " Autolink without angle brackets.
78 " mkd inline links: protocol optional user:pass@ sub/domain .com, .co.uk, etc optional port path/querystring/hash fragment
79 " ------------ _____________________ --------------------------- ________________________ ----------------- __
80 syntax match mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
82 " Autolink with parenthesis.
83 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=")"
85 " Autolink with angle brackets.
86 syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@<!<\ze[a-z][a-z0-9,.-]\{1,22}:\/\/[^> ]*>" end=">"
88 " Link definitions: [id]: URL (Optional Title)
89 syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
90 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
91 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained
92 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
93 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained
96 syn region htmlH1 start="^\s*#" end="$" contains=@Spell
97 syn region htmlH2 start="^\s*##" end="$" contains=@Spell
98 syn region htmlH3 start="^\s*###" end="$" contains=@Spell
99 syn region htmlH4 start="^\s*####" end="$" contains=@Spell
100 syn region htmlH5 start="^\s*#####" end="$" contains=@Spell
101 syn region htmlH6 start="^\s*######" end="$" contains=@Spell
102 syn match htmlH1 /^.\+\n=\+$/ contains=@Spell
103 syn match htmlH2 /^.\+\n-\+$/ contains=@Spell
105 "define Markdown groups
106 syn match mkdLineBreak / \+$/
107 syn region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLineBreak,@Spell
108 syn region mkdCode start=/\(\([^\\]\|^\)\\\)\@<!`/ end=/\(\([^\\]\|^\)\\\)\@<!`/
109 syn region mkdCode start=/\s*``[^`]*/ end=/[^`]*``\s*/
110 syn region mkdCode start=/^\s*\z(`\{3,}\)[^`]*$/ end=/^\s*\z1`*\s*$/
111 syn region mkdCode start=/\s*\~\~[^\~]*/ end=/[^\~]*\~\~\s*/
112 syn region mkdCode start=/^\s*\z(\~\{3,}\)\s*[0-9A-Za-z_+-]*\s*$/ end=/^\s*\z1\~*\s*$/
113 syn region mkdCode start="<pre[^>]*\\\@<!>" end="</pre>"
114 syn region mkdCode start="<code[^>]*\\\@<!>" end="</code>"
115 syn region mkdFootnote start="\[^" end="\]"
116 syn match mkdCode /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/
117 syn match mkdCode /\%^\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/
118 syn match mkdCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained
119 syn match mkdListItem /^\s*\%([-*+]\|\d\+\.\)\s\+/ contained
120 syn region mkdListItemLine start="^\s*\%([-*+]\|\d\+\.\)\s\+" end="$" oneline contains=@mkdNonListItem,mkdListItem,@Spell
121 syn region mkdNonListItemBlock start="\(\%^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@!\|\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!\)" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
122 syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
123 syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/
124 syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/
125 syn match mkdRule /^\s*-\{3,}$/
126 syn match mkdRule /^\s*\*\{3,5}$/
129 if get(g:, 'vim_markdown_frontmatter', 0)
130 syn include @yamlTop syntax/yaml.vim
131 syn region Comment matchgroup=mkdDelimiter start="\%^---$" end="^---$" contains=@yamlTop
132 unlet! b:current_syntax
135 if get(g:, 'vim_markdown_toml_frontmatter', 0)
137 syn include @tomlTop syntax/toml.vim
138 syn region Comment matchgroup=mkdDelimiter start="\%^+++$" end="^+++$" transparent contains=@tomlTop
139 unlet! b:current_syntax
141 syn region Comment matchgroup=mkdDelimiter start="\%^+++$" end="^+++$"
145 if get(g:, 'vim_markdown_json_frontmatter', 0)
147 syn include @jsonTop syntax/json.vim
148 syn region Comment matchgroup=mkdDelimiter start="\%^{$" end="^}$" contains=@jsonTop
149 unlet! b:current_syntax
151 syn region Comment matchgroup=mkdDelimiter start="\%^{$" end="^}$"
155 if get(g:, 'vim_markdown_math', 0)
156 syn include @tex syntax/tex.vim
157 syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$" end="\$" contains=@tex
158 syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$\$" end="\$\$" contains=@tex
161 syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath
163 "highlighting for Markdown groups
164 HtmlHiLink mkdString String
165 HtmlHiLink mkdCode String
166 HtmlHiLink mkdCodeStart String
167 HtmlHiLink mkdCodeEnd String
168 HtmlHiLink mkdFootnote Comment
169 HtmlHiLink mkdBlockquote Comment
170 HtmlHiLink mkdListItem Identifier
171 HtmlHiLink mkdRule Identifier
172 HtmlHiLink mkdLineBreak Todo
173 HtmlHiLink mkdFootnotes htmlLink
174 HtmlHiLink mkdLink htmlLink
175 HtmlHiLink mkdURL htmlString
176 HtmlHiLink mkdInlineURL htmlLink
177 HtmlHiLink mkdID Identifier
178 HtmlHiLink mkdLinkDef mkdID
179 HtmlHiLink mkdLinkDefTarget mkdURL
180 HtmlHiLink mkdLinkTitle htmlString
181 HtmlHiLink mkdDelimiter Delimiter
183 let b:current_syntax = "mkd"
185 delcommand HtmlHiLink