AvidSeeker | b584410 | 2024-07-16 21:10:50 +0200 | [diff] [blame] | 1 | " mediawiki.vim (formerly named Wikipedia.vim) |
| 2 | " |
| 3 | " Vim syntax file |
| 4 | " Language: MediaWiki |
| 5 | " Maintainer: Avid Seeker <avidseeker7@protonmail.com> |
| 6 | " Home: http://en.wikipedia.org/wiki/Wikipedia:Text_editor_support#Vim |
| 7 | " Last Change: 2024 Jul 14 |
| 8 | " Credits: [[User:Unforgettableid]] [[User:Aepd87]], [[User:Danny373]], [[User:Ingo Karkat]], et al. |
| 9 | " |
| 10 | " Published on Wikipedia in 2003-04 and declared authorless. |
| 11 | " |
| 12 | " Based on the HTML syntax file. Probably too closely based, in fact. |
| 13 | " There may well be name collisions everywhere, but ignorance is bliss, |
| 14 | " so they say. |
| 15 | " |
| 16 | |
| 17 | if exists("b:current_syntax") |
| 18 | finish |
| 19 | endif |
| 20 | |
| 21 | syntax case ignore |
| 22 | syntax spell toplevel |
| 23 | |
| 24 | " Mark illegal characters |
| 25 | sy match htmlError "[<>&]" |
| 26 | |
| 27 | " Tags |
| 28 | sy region htmlString contained start=+"+ end=+"+ contains=htmlSpecialChar,@htmlPreproc |
| 29 | sy region htmlString contained start=+'+ end=+'+ contains=htmlSpecialChar,@htmlPreproc |
| 30 | sy match htmlValue contained "=[\t ]*[^'" \t>][^ \t>]*"hs=s+1 contains=@htmlPreproc |
| 31 | sy region htmlEndTag start=+</+ end=+>+ contains=htmlTagN,htmlTagError |
| 32 | sy region htmlTag start=+<[^/]+ end=+>+ contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster |
| 33 | sy match htmlTagN contained +<\s*[-a-zA-Z0-9]\++hs=s+1 contains=htmlTagName,htmlSpecialTagName,@htmlTagNameCluster |
| 34 | sy match htmlTagN contained +</\s*[-a-zA-Z0-9]\++hs=s+2 contains=htmlTagName,htmlSpecialTagName,@htmlTagNameCluster |
| 35 | sy match htmlTagError contained "[^>]<"ms=s+1 |
| 36 | |
| 37 | " Allowed HTML tag names |
| 38 | sy keyword htmlTagName contained big blockquote br caption center cite code |
| 39 | sy keyword htmlTagName contained dd del div dl dt font hr ins li |
| 40 | sy keyword htmlTagName contained ol p pre rb rp rt ruby s small span strike sub |
| 41 | sy keyword htmlTagName contained sup table td th tr tt ul var |
| 42 | sy match htmlTagName contained "\<\(b\|i\|u\|h[1-6]\|em\|strong\)\>" |
| 43 | " Allowed Wiki tag names |
| 44 | sy keyword htmlTagName contained math nowiki references source syntaxhighlight |
| 45 | |
| 46 | " Allowed arg names |
| 47 | sy keyword htmlArg contained align lang dir width height nowrap bgcolor clear |
| 48 | sy keyword htmlArg contained noshade cite datetime size face color type start |
| 49 | sy keyword htmlArg contained value compact summary border frame rules |
| 50 | sy keyword htmlArg contained cellspacing cellpadding valign char charoff |
| 51 | sy keyword htmlArg contained colgroup col span abbr axis headers scope rowspan |
| 52 | sy keyword htmlArg contained colspan id class name style title |
| 53 | |
| 54 | " Special characters |
| 55 | sy match htmlSpecialChar "&#\=[0-9A-Za-z]\{1,8};" |
| 56 | |
| 57 | " Comments |
| 58 | sy region htmlComment start=+<!+ end=+>+ contains=htmlCommentPart,htmlCommentError |
| 59 | sy match htmlCommentError contained "[^><!]" |
| 60 | sy region htmlCommentPart contained start=+--+ end=+--\s*+ contains=@htmlPreProc |
| 61 | sy region htmlComment start=+<!DOCTYPE+ keepend end=+>+ |
| 62 | |
| 63 | if !exists("html_no_rendering") |
| 64 | sy cluster htmlTop contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLink,@htmlPreproc |
| 65 | |
| 66 | sy region htmlBold start="<b\>" end="</b>"me=e-4 contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic |
| 67 | sy region htmlBold start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic |
| 68 | sy region htmlBoldUnderline contained start="<u\>" end="</u>"me=e-4 contains=@htmlTop,htmlBoldUnderlineItalic |
| 69 | sy region htmlBoldItalic contained start="<i\>" end="</i>"me=e-4 contains=@htmlTop,htmlBoldItalicUnderline |
| 70 | sy region htmlBoldItalic contained start="<em\>" end="</em>"me=e-5 contains=@htmlTop,htmlBoldItalicUnderline |
| 71 | sy region htmlBoldUnderlineItalic contained start="<i\>" end="</i>"me=e-4 contains=@htmlTop |
| 72 | sy region htmlBoldUnderlineItalic contained start="<em\>" end="</em>"me=e-5 contains=@htmlTop |
| 73 | sy region htmlBoldItalicUnderline contained start="<u\>" end="</u>"me=e-4 contains=@htmlTop,htmlBoldUnderlineItalic |
| 74 | |
| 75 | sy region htmlUnderline start="<u\>" end="</u>"me=e-4 contains=@htmlTop,htmlUnderlineBold,htmlUnderlineItalic |
| 76 | sy region htmlUnderlineBold contained start="<b\>" end="</b>"me=e-4 contains=@htmlTop,htmlUnderlineBoldItalic |
| 77 | sy region htmlUnderlineBold contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop,htmlUnderlineBoldItalic |
| 78 | sy region htmlUnderlineItalic contained start="<i\>" end="</i>"me=e-4 contains=@htmlTop,htmlUnderlineItalicBold |
| 79 | sy region htmlUnderlineItalic contained start="<em\>" end="</em>"me=e-5 contains=@htmlTop,htmlUnderlineItalicBold |
| 80 | sy region htmlUnderlineItalicBold contained start="<b\>" end="</b>"me=e-4 contains=@htmlTop |
| 81 | sy region htmlUnderlineItalicBold contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop |
| 82 | sy region htmlUnderlineBoldItalic contained start="<i\>" end="</i>"me=e-4 contains=@htmlTop |
| 83 | sy region htmlUnderlineBoldItalic contained start="<em\>" end="</em>"me=e-5 contains=@htmlTop |
| 84 | |
| 85 | sy region htmlItalic start="<i\>" end="</i>"me=e-4 contains=@htmlTop,htmlItalicBold,htmlItalicUnderline |
| 86 | sy region htmlItalic start="<em\>" end="</em>"me=e-5 contains=@htmlTop |
| 87 | sy region htmlItalicBold contained start="<b\>" end="</b>"me=e-4 contains=@htmlTop,htmlItalicBoldUnderline |
| 88 | sy region htmlItalicBold contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop,htmlItalicBoldUnderline |
| 89 | sy region htmlItalicBoldUnderline contained start="<u\>" end="</u>"me=e-4 contains=@htmlTop |
| 90 | sy region htmlItalicUnderline contained start="<u\>" end="</u>"me=e-4 contains=@htmlTop,htmlItalicUnderlineBold |
| 91 | sy region htmlItalicUnderlineBold contained start="<b\>" end="</b>"me=e-4 contains=@htmlTop |
| 92 | sy region htmlItalicUnderlineBold contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop |
| 93 | |
| 94 | sy region htmlH1 start="<h1\>" end="</h1>"me=e-5 contains=@htmlTop |
| 95 | sy region htmlH2 start="<h2\>" end="</h2>"me=e-5 contains=@htmlTop |
| 96 | sy region htmlH3 start="<h3\>" end="</h3>"me=e-5 contains=@htmlTop |
| 97 | sy region htmlH4 start="<h4\>" end="</h4>"me=e-5 contains=@htmlTop |
| 98 | sy region htmlH5 start="<h5\>" end="</h5>"me=e-5 contains=@htmlTop |
| 99 | sy region htmlH6 start="<h6\>" end="</h6>"me=e-5 contains=@htmlTop |
| 100 | endif |
| 101 | |
| 102 | |
| 103 | " No htmlTop and wikiPre inside HTML preformatted areas, because |
| 104 | " MediaWiki renders everything in there literally (HTML tags and |
| 105 | " entities, too): <pre> tags work as the combination of <nowiki> and |
| 106 | " the standard HTML <pre> tag: the content will preformatted, and it |
| 107 | " will not be parsed, but shown as in the wikitext source. |
| 108 | " |
| 109 | " With wikiPre, indented lines would be rendered differently from |
| 110 | " unindented lines. |
| 111 | sy match htmlPreTag /<pre\>[^>]*>/ contains=htmlTag |
| 112 | sy match htmlPreEndTag /<\/pre>/ contains=htmlEndTag |
| 113 | sy match wikiNowikiTag /<nowiki>/ contains=htmlTag |
| 114 | sy match wikiNowikiEndTag /<\/nowiki>/ contains=htmlEndTag |
| 115 | sy match wikiSourceTag /<source\s\+[^>]\+>/ contains=htmlTag |
| 116 | sy match wikiSourceEndTag /<\/source>/ contains=htmlEndTag |
| 117 | sy match wikiSyntaxHLTag /<syntaxhighlight\s\+[^>]\+>/ contains=htmlTag |
| 118 | sy match wikiSyntaxHLEndTag /<\/syntaxhighlight>/ contains=htmlEndTag |
| 119 | |
| 120 | " Note: Cannot use 'start="<pre>"rs=e', so still have the <pre> tag |
| 121 | " highlighted correctly via separate sy-match. Unfortunately, this will |
| 122 | " also highlight <pre> tags inside the preformatted region. |
| 123 | sy region htmlPre start="<pre\>[^>]*>" end="<\/pre>"me=e-6 contains=htmlPreTag |
| 124 | sy region wikiNowiki start="<nowiki>" end="<\/nowiki>"me=e-9 contains=wikiNowikiTag |
| 125 | sy region wikiSource start="<source\s\+[^>]\+>" keepend end="<\/source>"me=e-9 contains=wikiSourceTag |
| 126 | sy region wikiSyntaxHL start="<syntaxhighlight\s\+[^>]\+>" keepend end="<\/syntaxhighlight>"me=e-18 contains=wikiSyntaxHLTag |
| 127 | |
| 128 | sy include @TeX syntax/tex.vim |
| 129 | unlet b:current_syntax |
| 130 | sy region wikiTeX matchgroup=htmlTag start="<math>" end="<\/math>" contains=@texMathZoneGroup,wikiNowiki,wikiNowikiEndTag |
| 131 | sy region wikiRef matchgroup=htmlTag start="<ref>" end="<\/ref>" contains=wikiNowiki,wikiNowikiEndTag |
| 132 | |
| 133 | sy cluster wikiText contains=wikiLink,wikiTemplate,wikiNowiki,wikiNowikiEndTag,wikiItalic,wikiBold,wikiBoldAndItalic |
| 134 | |
| 135 | " Tables |
| 136 | sy cluster wikiTableFormat contains=wikiTemplate,htmlString,htmlArg,htmlValue |
| 137 | sy region wikiTable matchgroup=wikiTableSeparator start="{|" end="|}" contains=wikiTableHeaderLine,wikiTableCaptionLine,wikiTableNewRow,wikiTableHeadingCell,wikiTableNormalCell,@wikiText |
| 138 | sy match wikiTableSeparator /^!/ contained |
| 139 | sy match wikiTableSeparator /^|/ contained |
| 140 | sy match wikiTableSeparator /^|[+-]/ contained |
| 141 | sy match wikiTableSeparator /||/ contained |
| 142 | sy match wikiTableSeparator /!!/ contained |
| 143 | sy match wikiTableFormatEnd /[!|]/ contained |
| 144 | sy match wikiTableHeadingCell /\(^!\|!!\)\([^!|]*|\)\?.*/ contains=wikiTableSeparator,@wikiText,wikiTableHeadingFormat |
| 145 | " Require at least one '=' in the format, to avoid spurious matches (e.g. |
| 146 | " the | in [[foo|bar]] might be taken as the final |, indicating the beginning |
| 147 | " of the cell). The same is done for wikiTableNormalFormat below. |
| 148 | sy match wikiTableHeadingFormat /\%(^!\|!!\)[^!|]\+=[^!|]\+\([!|]\)\(\1\)\@!/me=e-1 contains=@wikiTableFormat,wikiTableSeparator nextgroup=wikiTableFormatEnd |
| 149 | sy match wikiTableNormalCell /\(^|\|||\)\([^|]*|\)\?.*/ contains=wikiTableSeparator,@wikiText,wikiTableNormalFormat |
| 150 | sy match wikiTableNormalFormat /\(^|\|||\)[^|]\+=[^|]\+||\@!/me=e-1 contains=@wikiTableFormat,wikiTableSeparator nextgroup=wikiTableFormatEnd |
| 151 | sy match wikiTableHeaderLine /\(^{|\)\@<=.*$/ contained contains=@wikiTableFormat |
| 152 | sy match wikiTableCaptionLine /^|+.*$/ contained contains=wikiTableSeparator,@wikiText |
| 153 | sy match wikiTableNewRow /^|-.*$/ contained contains=wikiTableSeparator,@wikiTableFormat |
| 154 | |
| 155 | sy cluster wikiTop contains=@Spell,wikiLink,wikiNowiki,wikiNowikiEndTag |
| 156 | |
| 157 | sy region wikiItalic start=+'\@<!'''\@!+ end=+''+ oneline contains=@wikiTop,wikiItalicBold |
| 158 | sy region wikiBold start=+'''+ end=+'''+ oneline contains=@wikiTop,wikiBoldItalic |
| 159 | sy region wikiBoldAndItalic start=+'''''+ end=+'''''+ oneline contains=@wikiTop |
| 160 | |
| 161 | sy region wikiBoldItalic contained start=+'\@<!'''\@!+ end=+''+ oneline contains=@wikiTop |
| 162 | sy region wikiItalicBold contained start=+'''+ end=+'''+ oneline contains=@wikiTop |
| 163 | |
| 164 | sy region wikiH1 start="^=" end="=" oneline contains=@wikiTop |
| 165 | sy region wikiH2 start="^==" end="==" oneline contains=@wikiTop |
| 166 | sy region wikiH3 start="^===" end="===" oneline contains=@wikiTop |
| 167 | sy region wikiH4 start="^====" end="====" oneline contains=@wikiTop |
| 168 | sy region wikiH5 start="^=====" end="=====" oneline contains=@wikiTop |
| 169 | sy region wikiH6 start="^======" end="======" oneline contains=@wikiTop |
| 170 | |
| 171 | sy region wikiLink start="\[\[" end="\]\]\(s\|'s\|es\|ing\|\)" oneline contains=wikiLink,wikiNowiki,wikiNowikiEndTag |
| 172 | |
| 173 | sy region wikiLink start="https\?://" end="\W*\_s"me=s-1 oneline |
| 174 | sy region wikiLink start="\[http:" end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag |
| 175 | sy region wikiLink start="\[https:" end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag |
| 176 | sy region wikiLink start="\[ftp:" end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag |
| 177 | sy region wikiLink start="\[gopher:" end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag |
| 178 | sy region wikiLink start="\[news:" end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag |
| 179 | sy region wikiLink start="\[mailto:" end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag |
| 180 | |
| 181 | sy match wikiTemplateName /{{[^{|}<>\[\]]\+/hs=s+2 contained |
| 182 | sy region wikiTemplate start="{{" end="}}" keepend extend contains=wikiNowiki,wikiNowikiEndTag,wikiTemplateName,wikiTemplateParam,wikiTemplate,wikiLink |
| 183 | sy region wikiTemplateParam start="{{{\s*\d" end="}}}" extend contains=wikiTemplateName |
| 184 | |
| 185 | sy match wikiParaFormatChar /^[\:|\*|;|#]\+/ |
| 186 | sy match wikiParaFormatChar /^-----*/ |
| 187 | sy match wikiPre /^\ .*$/ contains=wikiNowiki,wikiNowikiEndTag |
| 188 | |
| 189 | " HTML highlighting |
| 190 | |
| 191 | hi def link htmlTag Function |
| 192 | hi def link htmlEndTag Identifier |
| 193 | hi def link htmlArg Type |
| 194 | hi def link htmlTagName htmlStatement |
| 195 | hi def link htmlSpecialTagName Exception |
| 196 | hi def link htmlValue String |
| 197 | hi def link htmlSpecialChar Special |
| 198 | |
| 199 | if !exists("html_no_rendering") |
| 200 | hi def link htmlTitle Title |
| 201 | hi def link htmlH1 htmlTitle |
| 202 | hi def link htmlH2 htmlTitle |
| 203 | hi def link htmlH3 htmlTitle |
| 204 | hi def link htmlH4 htmlTitle |
| 205 | hi def link htmlH5 htmlTitle |
| 206 | hi def link htmlH6 htmlTitle |
| 207 | |
| 208 | hi def link htmlPreProc PreProc |
| 209 | hi def link htmlHead htmlPreProc |
| 210 | hi def link htmlPreProcAttrName htmlPreProc |
| 211 | hi def link htmlPreStmt htmlPreProc |
| 212 | |
| 213 | hi def link htmlSpecial Special |
| 214 | hi def link htmlCssDefinition htmlSpecial |
| 215 | hi def link htmlEvent htmlSpecial |
| 216 | hi def link htmlSpecialChar htmlSpecial |
| 217 | |
| 218 | hi def link htmlComment Comment |
| 219 | hi def link htmlCommentPart htmlComment |
| 220 | hi def link htmlCssStyleComment htmlComment |
| 221 | |
| 222 | hi def link htmlString String |
| 223 | hi def link htmlPreAttr htmlString |
| 224 | hi def link htmlValue htmlString |
| 225 | |
| 226 | hi def link htmlError Error |
| 227 | hi def link htmlBadArg htmlError |
| 228 | hi def link htmlBadTag htmlError |
| 229 | hi def link htmlCommentError htmlError |
| 230 | hi def link htmlPreError htmlError |
| 231 | hi def link htmlPreProcAttrError htmlError |
| 232 | hi def link htmlTagError htmlError |
| 233 | |
| 234 | hi def link htmlStatement Statement |
| 235 | |
| 236 | hi def link htmlConstant Constant |
| 237 | |
| 238 | hi def link htmlBoldItalicUnderline htmlBoldUnderlineItalic |
| 239 | hi def link htmlUnderlineItalicBold htmlBoldUnderlineItalic |
| 240 | hi def link htmlUnderlineBoldItalic htmlBoldUnderlineItalic |
| 241 | hi def link htmlItalicBoldUnderline htmlBoldUnderlineItalic |
| 242 | hi def link htmlItalicUnderlineBold htmlBoldUnderlineItalic |
| 243 | |
| 244 | hi def link htmlItalicBold htmlBoldItalic |
| 245 | hi def link htmlItalicUnderline htmlUnderlineItalic |
| 246 | hi def link htmlUnderlineBold htmlBoldUnderline |
| 247 | |
| 248 | hi def link htmlLink Underlined |
| 249 | |
| 250 | if !exists("html_style_rendering") |
| 251 | hi def htmlBold term=bold cterm=bold gui=bold |
| 252 | hi def htmlBoldUnderline term=bold,underline cterm=bold,underline gui=bold,underline |
| 253 | hi def htmlBoldItalic term=bold,italic cterm=bold,italic gui=bold,italic |
| 254 | hi def htmlBoldUnderlineItalic term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline |
| 255 | hi def htmlUnderline term=underline cterm=underline gui=underline |
| 256 | hi def htmlUnderlineItalic term=italic,underline cterm=italic,underline gui=italic,underline |
| 257 | hi def htmlItalic term=italic cterm=italic gui=italic |
| 258 | endif |
| 259 | endif |
| 260 | |
| 261 | " Wiki highlighting |
| 262 | |
| 263 | hi def link wikiItalic htmlItalic |
| 264 | hi def link wikiBold htmlBold |
| 265 | hi def link wikiBoldItalic htmlBoldItalic |
| 266 | hi def link wikiItalicBold htmlBoldItalic |
| 267 | hi def link wikiBoldAndItalic htmlBoldItalic |
| 268 | |
| 269 | hi def link wikiH1 htmlTitle |
| 270 | hi def link wikiH2 htmlTitle |
| 271 | hi def link wikiH3 htmlTitle |
| 272 | hi def link wikiH4 htmlTitle |
| 273 | hi def link wikiH5 htmlTitle |
| 274 | hi def link wikiH6 htmlTitle |
| 275 | |
| 276 | hi def link wikiLink htmlLink |
| 277 | hi def link wikiTemplate htmlSpecial |
| 278 | hi def link wikiTemplateParam htmlSpecial |
| 279 | hi def link wikiTemplateName Type |
| 280 | hi def link wikiParaFormatChar htmlSpecial |
| 281 | hi def link wikiPre htmlConstant |
| 282 | hi def link wikiRef htmlComment |
| 283 | |
| 284 | hi def link htmlPre wikiPre |
| 285 | hi def link wikiSource wikiPre |
| 286 | hi def link wikiSyntaxHL wikiPre |
| 287 | |
| 288 | hi def link wikiTableSeparator Statement |
| 289 | hi def link wikiTableFormatEnd wikiTableSeparator |
| 290 | hi def link wikiTableHeadingCell htmlBold |
| 291 | |
| 292 | let b:current_syntax = "mediawiki" |