diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index fd510eb772..1be01088e1 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -1847,6 +1847,17 @@ have the following in your vimrc: > let filetype_m = "mma" +MEDIAWIKI *ft-mediawiki-syntax* + +Be default, syntax highlighting includes basic HTML tags like style and +headers |html.vim|. For strict Mediawiki syntax highlighting: > + + let g:html_no_rendering = 1 + +If HTML highlighting is desired, terminal-based text formatting such as bold +and italic is possible by: > + + let g:html_style_rendering = 1 MODULA2 *modula2.vim* *ft-modula2-syntax* diff --git a/runtime/ftplugin/mediawiki.vim b/runtime/ftplugin/mediawiki.vim new file mode 100644 index 0000000000..efd2ae5c9b --- /dev/null +++ b/runtime/ftplugin/mediawiki.vim @@ -0,0 +1,42 @@ +" Language: MediaWiki +" Maintainer: Avid Seeker +" Home: http://en.wikipedia.org/wiki/Wikipedia:Text_editor_support#Vim +" Last Change: 2024 Jul 14 +" Credits: chikamichi +" + +if exists("b:did_ftplugin") + finish +endif +let g:did_ftplugin = 1 + +" Many MediaWiki wikis prefer line breaks only at the end of paragraphs +" (like in a text processor), which results in long, wrapping lines. +setlocal wrap linebreak +setlocal textwidth=0 + +setlocal formatoptions-=tc formatoptions+=l formatoptions+=roq +setlocal matchpairs+=<:> + +" Treat lists, indented text and tables as comment lines and continue with the +" same formatting in the next line (i.e. insert the comment leader) when hitting +" or using "o". +setlocal comments=n:#,n:*,n:\:,s:{\|,m:\|,ex:\|},s: +setlocal commentstring= + +" match HTML tags (taken directly from $VIM/ftplugin/html.vim) +if exists("loaded_matchit") + let b:match_ignorecase=0 + let b:match_skip = 's:Comment' + let b:match_words = '<:>,' . + \ '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' . + \ '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,' . + \ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>' +endif + +" Enable folding based on ==sections== +setlocal foldexpr=getline(v:lnum)=~'^\\(=\\+\\)[^=]\\+\\1\\(\\s*\\)\\=\\s*$'?\">\".(len(matchstr(getline(v:lnum),'^=\\+'))-1):\"=\" +setlocal foldmethod=expr + +let b:undo_ftplugin = "setl commentstring< comments< formatoptions< foldexpr< foldmethod<" +let b:undo_ftplugin += " matchpairs< linebreak< wrap< textwidth<" diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index bbe24a6e06..aa406b229e 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -698,6 +698,8 @@ local extension = { dm3 = 'maxima', dmt = 'maxima', wxm = 'maxima', + mw = 'mediawiki', + wiki = 'mediawiki', mel = 'mel', mmd = 'mermaid', mmdc = 'mermaid', diff --git a/runtime/syntax/mediawiki.vim b/runtime/syntax/mediawiki.vim new file mode 100644 index 0000000000..8ac30b93db --- /dev/null +++ b/runtime/syntax/mediawiki.vim @@ -0,0 +1,292 @@ +" mediawiki.vim (formerly named Wikipedia.vim) +" +" Vim syntax file +" Language: MediaWiki +" Maintainer: Avid Seeker +" Home: http://en.wikipedia.org/wiki/Wikipedia:Text_editor_support#Vim +" Last Change: 2024 Jul 14 +" Credits: [[User:Unforgettableid]] [[User:Aepd87]], [[User:Danny373]], [[User:Ingo Karkat]], et al. +" +" Published on Wikipedia in 2003-04 and declared authorless. +" +" Based on the HTML syntax file. Probably too closely based, in fact. +" There may well be name collisions everywhere, but ignorance is bliss, +" so they say. +" + +if exists("b:current_syntax") + finish +endif + +syntax case ignore +syntax spell toplevel + +" Mark illegal characters +sy match htmlError "[<>&]" + +" Tags +sy region htmlString contained start=+"+ end=+"+ contains=htmlSpecialChar,@htmlPreproc +sy region htmlString contained start=+'+ end=+'+ contains=htmlSpecialChar,@htmlPreproc +sy match htmlValue contained "=[\t ]*[^'" \t>][^ \t>]*"hs=s+1 contains=@htmlPreproc +sy region htmlEndTag start=++ contains=htmlTagN,htmlTagError +sy region htmlTag start=+<[^/]+ end=+>+ contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster +sy match htmlTagN contained +<\s*[-a-zA-Z0-9]\++hs=s+1 contains=htmlTagName,htmlSpecialTagName,@htmlTagNameCluster +sy match htmlTagN contained +]<"ms=s+1 + +" Allowed HTML tag names +sy keyword htmlTagName contained big blockquote br caption center cite code +sy keyword htmlTagName contained dd del div dl dt font hr ins li +sy keyword htmlTagName contained ol p pre rb rp rt ruby s small span strike sub +sy keyword htmlTagName contained sup table td th tr tt ul var +sy match htmlTagName contained "\<\(b\|i\|u\|h[1-6]\|em\|strong\)\>" +" Allowed Wiki tag names +sy keyword htmlTagName contained math nowiki references source syntaxhighlight + +" Allowed arg names +sy keyword htmlArg contained align lang dir width height nowrap bgcolor clear +sy keyword htmlArg contained noshade cite datetime size face color type start +sy keyword htmlArg contained value compact summary border frame rules +sy keyword htmlArg contained cellspacing cellpadding valign char charoff +sy keyword htmlArg contained colgroup col span abbr axis headers scope rowspan +sy keyword htmlArg contained colspan id class name style title + +" Special characters +sy match htmlSpecialChar "&#\=[0-9A-Za-z]\{1,8};" + +" Comments +sy region htmlComment start=++ contains=htmlCommentPart,htmlCommentError +sy match htmlCommentError contained "[^>+ + +if !exists("html_no_rendering") + sy cluster htmlTop contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLink,@htmlPreproc + + sy region htmlBold start="" end=""me=e-4 contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic + sy region htmlBold start="" end=""me=e-9 contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic + sy region htmlBoldUnderline contained start="" end=""me=e-4 contains=@htmlTop,htmlBoldUnderlineItalic + sy region htmlBoldItalic contained start="" end=""me=e-4 contains=@htmlTop,htmlBoldItalicUnderline + sy region htmlBoldItalic contained start="" end=""me=e-5 contains=@htmlTop,htmlBoldItalicUnderline + sy region htmlBoldUnderlineItalic contained start="" end=""me=e-4 contains=@htmlTop + sy region htmlBoldUnderlineItalic contained start="" end=""me=e-5 contains=@htmlTop + sy region htmlBoldItalicUnderline contained start="" end=""me=e-4 contains=@htmlTop,htmlBoldUnderlineItalic + + sy region htmlUnderline start="" end=""me=e-4 contains=@htmlTop,htmlUnderlineBold,htmlUnderlineItalic + sy region htmlUnderlineBold contained start="" end=""me=e-4 contains=@htmlTop,htmlUnderlineBoldItalic + sy region htmlUnderlineBold contained start="" end=""me=e-9 contains=@htmlTop,htmlUnderlineBoldItalic + sy region htmlUnderlineItalic contained start="" end=""me=e-4 contains=@htmlTop,htmlUnderlineItalicBold + sy region htmlUnderlineItalic contained start="" end=""me=e-5 contains=@htmlTop,htmlUnderlineItalicBold + sy region htmlUnderlineItalicBold contained start="" end=""me=e-4 contains=@htmlTop + sy region htmlUnderlineItalicBold contained start="" end=""me=e-9 contains=@htmlTop + sy region htmlUnderlineBoldItalic contained start="" end=""me=e-4 contains=@htmlTop + sy region htmlUnderlineBoldItalic contained start="" end=""me=e-5 contains=@htmlTop + + sy region htmlItalic start="" end=""me=e-4 contains=@htmlTop,htmlItalicBold,htmlItalicUnderline + sy region htmlItalic start="" end=""me=e-5 contains=@htmlTop + sy region htmlItalicBold contained start="" end=""me=e-4 contains=@htmlTop,htmlItalicBoldUnderline + sy region htmlItalicBold contained start="" end=""me=e-9 contains=@htmlTop,htmlItalicBoldUnderline + sy region htmlItalicBoldUnderline contained start="" end=""me=e-4 contains=@htmlTop + sy region htmlItalicUnderline contained start="" end=""me=e-4 contains=@htmlTop,htmlItalicUnderlineBold + sy region htmlItalicUnderlineBold contained start="" end=""me=e-4 contains=@htmlTop + sy region htmlItalicUnderlineBold contained start="" end=""me=e-9 contains=@htmlTop + + sy region htmlH1 start="" end=""me=e-5 contains=@htmlTop + sy region htmlH2 start="" end=""me=e-5 contains=@htmlTop + sy region htmlH3 start="" end=""me=e-5 contains=@htmlTop + sy region htmlH4 start="" end=""me=e-5 contains=@htmlTop + sy region htmlH5 start="" end=""me=e-5 contains=@htmlTop + sy region htmlH6 start="" end=""me=e-5 contains=@htmlTop +endif + + +" No htmlTop and wikiPre inside HTML preformatted areas, because +" MediaWiki renders everything in there literally (HTML tags and +" entities, too):
 tags work as the combination of  and
+" the standard HTML 
 tag: the content will preformatted, and it
+" will not be parsed, but shown as in the wikitext source.
+"
+" With wikiPre, indented lines would be rendered differently from
+" unindented lines.
+sy match htmlPreTag       /[^>]*>/         contains=htmlTag
+sy match htmlPreEndTag    /<\/pre>/       contains=htmlEndTag
+sy match wikiNowikiTag    //      contains=htmlTag
+sy match wikiNowikiEndTag /<\/nowiki>/    contains=htmlEndTag
+sy match wikiSourceTag    /]\+>/ contains=htmlTag
+sy match wikiSourceEndTag /<\/source>/    contains=htmlEndTag
+sy match wikiSyntaxHLTag    /]\+>/ contains=htmlTag
+sy match wikiSyntaxHLEndTag /<\/syntaxhighlight>/    contains=htmlEndTag
+
+" Note: Cannot use 'start="
"rs=e', so still have the 
 tag
+" highlighted correctly via separate sy-match. Unfortunately, this will
+" also highlight 
 tags inside the preformatted region.
+sy region htmlPre    start="[^>]*>"                 end="<\/pre>"me=e-6    contains=htmlPreTag
+sy region wikiNowiki start=""              end="<\/nowiki>"me=e-9 contains=wikiNowikiTag
+sy region wikiSource start="]\+>"         keepend end="<\/source>"me=e-9 contains=wikiSourceTag
+sy region wikiSyntaxHL start="]\+>" keepend end="<\/syntaxhighlight>"me=e-18 contains=wikiSyntaxHLTag
+
+sy include @TeX syntax/tex.vim
+unlet b:current_syntax
+sy region wikiTeX matchgroup=htmlTag start="" end="<\/math>"  contains=@texMathZoneGroup,wikiNowiki,wikiNowikiEndTag
+sy region wikiRef matchgroup=htmlTag start=""  end="<\/ref>"   contains=wikiNowiki,wikiNowikiEndTag
+
+sy cluster wikiText contains=wikiLink,wikiTemplate,wikiNowiki,wikiNowikiEndTag,wikiItalic,wikiBold,wikiBoldAndItalic
+
+" Tables
+sy cluster wikiTableFormat contains=wikiTemplate,htmlString,htmlArg,htmlValue
+sy region wikiTable matchgroup=wikiTableSeparator start="{|" end="|}" contains=wikiTableHeaderLine,wikiTableCaptionLine,wikiTableNewRow,wikiTableHeadingCell,wikiTableNormalCell,@wikiText
+sy match  wikiTableSeparator /^!/ contained
+sy match  wikiTableSeparator /^|/ contained
+sy match  wikiTableSeparator /^|[+-]/ contained
+sy match  wikiTableSeparator /||/ contained
+sy match  wikiTableSeparator /!!/ contained
+sy match  wikiTableFormatEnd /[!|]/ contained
+sy match  wikiTableHeadingCell /\(^!\|!!\)\([^!|]*|\)\?.*/ contains=wikiTableSeparator,@wikiText,wikiTableHeadingFormat
+" Require at least one '=' in the format, to avoid spurious matches (e.g.
+" the | in [[foo|bar]] might be taken as the final |, indicating the beginning
+" of the cell). The same is done for wikiTableNormalFormat below.
+sy match  wikiTableHeadingFormat /\%(^!\|!!\)[^!|]\+=[^!|]\+\([!|]\)\(\1\)\@!/me=e-1 contains=@wikiTableFormat,wikiTableSeparator nextgroup=wikiTableFormatEnd
+sy match  wikiTableNormalCell /\(^|\|||\)\([^|]*|\)\?.*/ contains=wikiTableSeparator,@wikiText,wikiTableNormalFormat
+sy match  wikiTableNormalFormat /\(^|\|||\)[^|]\+=[^|]\+||\@!/me=e-1 contains=@wikiTableFormat,wikiTableSeparator nextgroup=wikiTableFormatEnd
+sy match  wikiTableHeaderLine /\(^{|\)\@<=.*$/ contained contains=@wikiTableFormat
+sy match  wikiTableCaptionLine /^|+.*$/ contained contains=wikiTableSeparator,@wikiText
+sy match  wikiTableNewRow /^|-.*$/ contained contains=wikiTableSeparator,@wikiTableFormat
+
+sy cluster wikiTop contains=@Spell,wikiLink,wikiNowiki,wikiNowikiEndTag
+
+sy region wikiItalic        start=+'\@\[\]]\+/hs=s+2 contained
+sy region wikiTemplate start="{{" end="}}" keepend extend contains=wikiNowiki,wikiNowikiEndTag,wikiTemplateName,wikiTemplateParam,wikiTemplate,wikiLink
+sy region wikiTemplateParam start="{{{\s*\d" end="}}}" extend contains=wikiTemplateName
+
+sy match wikiParaFormatChar /^[\:|\*|;|#]\+/
+sy match wikiParaFormatChar /^-----*/
+sy match wikiPre            /^\ .*$/         contains=wikiNowiki,wikiNowikiEndTag
+
+" HTML highlighting
+
+hi def link htmlTag            Function
+hi def link htmlEndTag         Identifier
+hi def link htmlArg            Type
+hi def link htmlTagName        htmlStatement
+hi def link htmlSpecialTagName Exception
+hi def link htmlValue          String
+hi def link htmlSpecialChar    Special
+
+if !exists("html_no_rendering")
+  hi def link htmlTitle Title
+  hi def link htmlH1    htmlTitle
+  hi def link htmlH2    htmlTitle
+  hi def link htmlH3    htmlTitle
+  hi def link htmlH4    htmlTitle
+  hi def link htmlH5    htmlTitle
+  hi def link htmlH6    htmlTitle
+
+  hi def link htmlPreProc          PreProc
+  hi def link htmlHead             htmlPreProc
+  hi def link htmlPreProcAttrName  htmlPreProc
+  hi def link htmlPreStmt          htmlPreProc
+
+  hi def link htmlSpecial          Special
+  hi def link htmlCssDefinition    htmlSpecial
+  hi def link htmlEvent            htmlSpecial
+  hi def link htmlSpecialChar      htmlSpecial
+
+  hi def link htmlComment          Comment
+  hi def link htmlCommentPart      htmlComment
+  hi def link htmlCssStyleComment  htmlComment
+
+  hi def link htmlString           String
+  hi def link htmlPreAttr          htmlString
+  hi def link htmlValue            htmlString
+
+  hi def link htmlError            Error
+  hi def link htmlBadArg           htmlError
+  hi def link htmlBadTag           htmlError
+  hi def link htmlCommentError     htmlError
+  hi def link htmlPreError         htmlError
+  hi def link htmlPreProcAttrError htmlError
+  hi def link htmlTagError         htmlError
+
+  hi def link htmlStatement        Statement
+
+  hi def link htmlConstant         Constant
+
+  hi def link htmlBoldItalicUnderline htmlBoldUnderlineItalic
+  hi def link htmlUnderlineItalicBold htmlBoldUnderlineItalic
+  hi def link htmlUnderlineBoldItalic htmlBoldUnderlineItalic
+  hi def link htmlItalicBoldUnderline htmlBoldUnderlineItalic
+  hi def link htmlItalicUnderlineBold htmlBoldUnderlineItalic
+
+  hi def link htmlItalicBold          htmlBoldItalic
+  hi def link htmlItalicUnderline     htmlUnderlineItalic
+  hi def link htmlUnderlineBold       htmlBoldUnderline
+
+  hi def link htmlLink Underlined
+
+  if !exists("html_style_rendering")
+    hi def htmlBold                term=bold                  cterm=bold                  gui=bold
+    hi def htmlBoldUnderline       term=bold,underline        cterm=bold,underline        gui=bold,underline
+    hi def htmlBoldItalic          term=bold,italic           cterm=bold,italic           gui=bold,italic
+    hi def htmlBoldUnderlineItalic term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline
+    hi def htmlUnderline           term=underline             cterm=underline             gui=underline
+    hi def htmlUnderlineItalic     term=italic,underline      cterm=italic,underline      gui=italic,underline
+    hi def htmlItalic              term=italic                cterm=italic                gui=italic
+  endif
+endif
+
+" Wiki highlighting
+
+hi def link wikiItalic        htmlItalic
+hi def link wikiBold          htmlBold
+hi def link wikiBoldItalic    htmlBoldItalic
+hi def link wikiItalicBold    htmlBoldItalic
+hi def link wikiBoldAndItalic htmlBoldItalic
+
+hi def link wikiH1 htmlTitle
+hi def link wikiH2 htmlTitle
+hi def link wikiH3 htmlTitle
+hi def link wikiH4 htmlTitle
+hi def link wikiH5 htmlTitle
+hi def link wikiH6 htmlTitle
+
+hi def link wikiLink           htmlLink
+hi def link wikiTemplate       htmlSpecial
+hi def link wikiTemplateParam  htmlSpecial
+hi def link wikiTemplateName   Type
+hi def link wikiParaFormatChar htmlSpecial
+hi def link wikiPre            htmlConstant
+hi def link wikiRef            htmlComment
+
+hi def link htmlPre            wikiPre
+hi def link wikiSource         wikiPre
+hi def link wikiSyntaxHL       wikiPre
+
+hi def link wikiTableSeparator Statement
+hi def link wikiTableFormatEnd wikiTableSeparator
+hi def link wikiTableHeadingCell htmlBold
+
+let b:current_syntax = "mediawiki"
diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim
index 82e9c877ca..6db4cfd696 100644
--- a/test/old/testdir/test_filetype.vim
+++ b/test/old/testdir/test_filetype.vim
@@ -437,6 +437,7 @@ func s:GetFilenameChecks() abort
     \ 'matlab': ['file.m'],
     \ 'maxima': ['file.demo', 'file.dmt', 'file.dm1', 'file.dm2', 'file.dm3',
     \            'file.wxm', 'maxima-init.mac'],
+    \ 'mediawiki': ['file.mw', 'file.wiki'],
     \ 'mel': ['file.mel'],
     \ 'mermaid': ['file.mmd', 'file.mmdc', 'file.mermaid'],
     \ 'meson': ['meson.build', 'meson.options', 'meson_options.txt'],