--- 
name: Mediawiki
fileTypes: 
- mediawiki
- wikipedia
- wiki
scopeName: text.html.mediawiki
repository: 
  comments: 
    patterns: 
    - name: comment.block.html.mediawiki
      begin: <!--
      end: --\s*>
      patterns: 
      - name: invalid.illegal.bad-comments-or-CDATA.html.mediawiki
        match: --
  inline: 
    patterns: 
    - captures: 
        "1": 
          name: constant.other.date-time.mediawiki
        "2": 
          name: invalid.illegal.too-many-tildes.mediawiki
      match: (~~~~~)(~{0,2})(?!~)
    - name: constant.other.signature.mediawiki
      match: ~~~~?
      comment: 3 ~s for sig, 4 for sig + timestamp
    - include: "#link"
    - include: "#style"
    - include: "#template"
    - include: "#block_html"
    - include: "#comments"
  template: 
    patterns: 
    - name: meta.template-parameter.mediawiki
      captures: 
        "1": 
          name: variable.parameter.template.numeric.mediawiki
      match: "{{{[ ]*([0-9]+)[ ]*}}}"
    - name: meta.template-parameter.mediawiki
      captures: 
        "1": 
          name: variable.parameter.template.named.mediawiki
      match: "{{{[ ]*(.*?)[ ]*}}}"
    - name: meta.template.parser-function.mediawiki
      endCaptures: 
        "1": 
          name: punctuation.fix_this_later.template.mediawiki
      begin: ({{)(?=[ ]*#)
      beginCaptures: 
        "1": 
          name: punctuation.fix_this_later.template.mediawiki
        "2": 
          name: meta.function-call.template.mediawiki
      end: (}})
      patterns: 
      - include: "#inline"
      comment: "\n\
        \t\t\t\t\t\tWhy oh why did mediawiki have to add these??\n\
        \t\t\t\t\t"
    - name: meta.template.mediawiki
      endCaptures: 
        "1": 
          name: punctuation.fix_this_later.template.mediawiki
      begin: ({{)([^{}\|]+)?
      beginCaptures: 
        "1": 
          name: punctuation.fix_this_later.template.mediawiki
        "2": 
          name: meta.function-call.template.mediawiki
      end: (}})
      patterns: 
      - include: "#comments"
      - begin: (\|)\s*(=)
        contentName: comment.block.template-hack.mediawiki
        beginCaptures: 
          "1": 
            name: punctuation.fix_this_later.pipe.mediawiki
          "2": 
            name: punctuation.fix_this_later.equals-sign.mediawiki
        end: (?=[|}])
      - begin: (\|)(([^{}\|=]+)(=))?
        contentName: meta.value.template.mediawiki
        beginCaptures: 
          "1": 
            name: punctuation.fix_this_later.pipe.mediawiki
          "2": 
            name: variable.parameter.template.mediawiki
          "3": 
            name: punctuation.fix_this_later.equals-sign.mediawiki
        end: (?=[|}])
        patterns: 
        - include: "#inline"
      - name: punctuation.fix_this_later.pipe.mediawiki
        match: \|
      comment: "\n\
        \t\t\t\t\t\tI am not sure I really like the scope of\n\
        \t\t\t\t\t\tmeta.function-call for templates, but it seems like\n\
        \t\t\t\t\t\tthe closest thing to what a template is really doing,\n\
        \t\t\t\t\t\twith parameters, etc.\n\
        \t\t\t\t\t"
    comment: "\n\
      \t\t\t\tThis repository item covers templates and parser functions.\n\
      \t\t\t"
  entities: 
    patterns: 
    - name: constant.character.entity.html.mediawiki
      match: "&([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+);"
    - name: invalid.illegal.bad-ampersand.html.mediawiki
      match: "&"
    comment: "\n\
      \t\t\t\tMediawiki supports Unicode, so these should not usually be\n\
      \t\t\t\tnecessary, but they do show up on pages from time to time.\n\
      \t\t\t"
  style_in_link: 
    patterns: 
    - name: markup.bold.mediawiki
      begin: "'''"
      end: "'''"
      patterns: 
      - include: "#style_in_link"
    - name: markup.italic.mediawiki
      begin: "''"
      end: "''"
      patterns: 
      - include: "#style_in_link"
    - captures: 
        "1": 
          name: meta.tag.inline.bold.html.mediawiki
      begin: (<(b|strong)>)
      contentName: markup.bold.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#style_in_link"
    - captures: 
        "1": 
          name: meta.tag.inline.italic.html.mediawiki
      begin: (<(i|em)>)
      contentName: markup.italic.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#style_in_link"
    - captures: 
        "1": 
          name: meta.tag.inline.strikethrough.html.mediawiki
      begin: (<(s|strike)>)
      contentName: markup.other.strikethrough.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#style_in_link"
    - captures: 
        "1": 
          name: meta.tag.inline.underline.html.mediawiki
      begin: (<(u)>)
      contentName: markup.underline.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#style_in_link"
    - captures: 
        "1": 
          name: meta.tag.inline.raw.html.mediawiki
      begin: (<(tt|code)>)
      contentName: markup.raw.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#style_in_link"
    - captures: 
        "1": 
          name: meta.tag.inline.any.html.mediawiki
      begin: (<(big|small|sub|sup)>)
      contentName: markup.other.inline-styles.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#style_in_link"
    - include: "#comments"
  block: 
    patterns: 
    - name: meta.redirect.mediawiki
      begin: ^\s*(?i)(#redirect)
      beginCaptures: 
        "1": 
          name: keyword.control.redirect.mediawiki
      end: \n
      patterns: 
      - include: "#link"
    - name: markup.heading.mediawiki
      match: ^=+\s*$
    - name: markup.heading.mediawiki
      begin: ^(=+)(?=.*\1\s*$)
      end: \1\s*$\n?
      patterns: 
      - name: invalid.illegal.extra-equals-sign.mediawiki
        match: (?<=^=|^==|^===|^====|^=====|^======)=+|=(?==*\s*$)
      - include: "#inline"
      comment: "\n\
        \t\t\t\t\t\tThis matches lines which begin and end with some\n\
        \t\t\t\t\t    number of \xE2\x80\x9C=\xE2\x80\x9D marks.  If they are mismatched, then\n\
        \t\t\t\t\t    interior \xE2\x80\x9C=\xE2\x80\x9D marks will be treated as invalid.\n\
        \t\t\t\t    "
    - name: meta.separator.mediawiki
      match: ^-{4,}[ \t]*($\n)?
      comment: "\n\
        \t\t\t\t\t\tA separator is made up of 4 or more -s alone on a\n\
        \t\t\t\t\t\tline by themselves.\n\
        \t\t\t\t\t"
    - name: markup.raw.block.mediawiki
      begin: ^ (?=\s*\S)
      end: ^(?=[^ ])
      patterns: 
      - include: "#inline"
      comment: "\n\
        \t\t\t\t\t\tCode blocks start with one space.  Wiki text and\n\
        \t\t\t\t\t\thtml are still interpreted in MediaWiki, unlike in\n\
        \t\t\t\t\t\tmediawiki.\n\
        \t\t\t\t\t"
    - name: markup.list.mediawiki
      begin: ^([#*:;])
      end: ^(?!\1)
      patterns: 
      - include: "#inline"
      comment: "\n\
        \t\t\t\t\t\tThis is preliminary.  Eventually it would be nice\n\
        \t\t\t\t\t\tto scope each type of list differently, and even to\n\
        \t\t\t\t\t\tdo scopes of nested lists.  There are 4 main things\n\
        \t\t\t\t\t\twhich will be scoped as lists:\n\
        \t\t\t\t\t\t\n\
        \t\t\t\t\t\t  - numbered lists (#)\n\
        \t\t\t\t\t\t  - unnumbered lists (*)\n\
        \t\t\t\t\t\t  - definition lists (; :)\n\
        \t\t\t\t\t\t  - indented paragraphs, as used on talk pages (:)\n\
        \t\t\t\t\t\t\n\
        \t\t\t\t\t\tthis last one might not even be scoped as a list in\n\
        \t\t\t\t\t\tthe ideal case.  It is fine as a list for now,\n\
        \t\t\t\t\t\thowever.\n\
        \t\t\t\t\t"
    - include: "#table"
    - include: "#comments"
    - name: meta.paragraph.mediawiki
      begin: ^(?![\t ;*#:=]|----|$)
      end: ^(?:\s*$|(?=[;*#:=]|----))
      patterns: 
      - include: "#inline"
      comment: "\n\
        \t\t\t\t\t\tAnything that is not a code block, list, header, etc.\n\
        \t\t\t\t\t\tis a paragraph.\n\
        \t\t\t\t\t"
  table: 
    patterns: 
    - name: markup.other.table.mediawiki
      begin: ^{\|
      end: ^\|}
      patterns: 
      - name: markup.other.table.row.mediawiki
        begin: ^\|-
        end: ^(?=\|-|\|})
        patterns: 
        - include: "#inline"
        comment: "\n\
          \t\t\t\t\t\t\t\thopefully we can allow selection of a whole\n\
          \t\t\t\t\t\t\t\ttable row, and possibly later allow things\n\
          \t\t\t\t\t\t\t\tlike moving a whole row up/down, etc.\n\
          \t\t\t\t\t\t\t"
      - include: "#inline"
      comment: "\n\
        \t\t\t\t\t\twe are going to have to add the styling capabilities\n\
        \t\t\t\t\t\tto this section eventually.  It is complicated,\n\
        \t\t\t\t\t\tthough, so I am putting it off.\n\
        \t\t\t\t\t"
  block_html: 
    patterns: 
    - captures: 
        "1": 
          name: meta.tag.inline.math.mediawiki
      begin: (<math>)
      contentName: source.math.tex.embedded.mediawiki
      end: (</math>)
      patterns: 
      - include: text.tex.math
    - captures: 
        "1": 
          name: meta.tag.inline.ref.mediawiki
      begin: (<ref>)
      contentName: meta.reference.content.mediawiki
      end: (</ref>)
      patterns: 
      - include: "#inline"
    - captures: 
        "1": 
          name: meta.tag.inline.ref.mediawiki
      begin: (<gallery>)
      contentName: meta.gallery.mediawiki
      end: (</gallery>)
      patterns: 
      - name: meta.item.gallery.mediawiki
        begin: "(?x)\n\
          \t\t\t\t\t\t\t\t^(?!\\s*\\n)\t\t\t\t# not an empty line\n\
          \t\t\t\t\t\t\t\t( [ ]*(((i|I)mage)(:))  # spaces, image, colon\n\
          \t\t\t\t\t\t\t\t  ([^\\[\\]|]+)           # anything\n\
          \t\t\t\t\t\t\t\t  (?<!\\s)[ ]*           # spaces\n\
          \t\t\t\t\t\t\t\t)?\n\
          \t\t\t\t\t\t\t"
        beginCaptures: 
          "6": 
            name: constant.other.wiki-link.image.mediawiki
          "3": 
            name: constant.other.namespace.image.mediawiki
          "5": 
            name: punctuation.fix_this_later.colon.mediawiki
        end: \n
        patterns: 
        - begin: ^(?!\|)|(\|)
          contentName: string.other.title.gallery.mediawiki
          beginCaptures: 
            "1": 
              name: punctuation.fix_this_later.pipe.mediawiki
          end: \n|(?=\|)
          patterns: 
          - include: "#inline"
        - name: punctuation.fix_this_later.pipe.mediawiki
          match: \|
    comment: "\n\
      \t\t\t\tThe available block HTML tags supported are:\n\
      \t\t\t\t\n\
      \t\t\t\t  * blockquote, center, pre, div, hr, p\n\
      \t\t\t\t  * tables: table, th, tr, td, caption\n\
      \t\t\t\t  * lists: ul, ol, li\n\
      \t\t\t\t  * definition lists: dl, dt, dd\n\
      \t\t\t\t  * headers: h1, h2, h3, h4, h5, h6\n\
      \t\t\t\t  * br\n\
      \t\t\t"
  link: 
    patterns: 
    - name: meta.image.wiki.mediawiki
      endCaptures: 
        "2": 
          name: punctuation.fix_this_later.pipe.mediawiki
        "3": 
          name: string.other.title.link.wiki-link.mediawiki
      begin: |-
        (?x:
        						(\[\[)                         # opening brackets
        						  ( [ ]*(((i|I)mage)(:))       # spaces, image, colon
        						    ([^\[\]|]+)                # anything
        						    (?<!\s)[ ]*                # spaces
        						  )
        					)
      applyEndPatternLast: 1
      beginCaptures: 
        "6": 
          name: punctuation.fix_this_later.colon.mediawiki
        "7": 
          name: constant.other.wiki-link.image.mediawiki
        "1": 
          name: punctuation.fix_this_later.brackets.mediwiki
        "4": 
          name: constant.other.namespace.image.mediawiki
      end: |-
        (?x:
        						  ((\|)[ ]*( [^\[\]|]+ )[ ]*)? # pipe, spaces, anything, spaces
        						(\]\])                         # closing brackets
        					)
      patterns: 
      - captures: 
          "1": 
            name: punctuation.fix_this_later.pipe.mediawiki
          "2": 
            name: keyword.control.image.formatting.mediawiki
          "3": 
            name: keyword.control.image.alignment.mediawiki
          "4": 
            name: constant.numeric.image.width.mediawiki
          "5": 
            name: constant.other.unit.mediawiki
        match: "(?x)\n\
          \t\t\t\t\t\t\t\t(\\|)[ ]*\n\
          \t\t\t\t\t\t\t\t( (thumb|thumbnail|frame)\n\
          \t\t\t\t\t\t\t\t |(right|left|center|none)\n\
          \t\t\t\t\t\t\t\t |([0-9]+)(px)\n\
          \t\t\t\t\t\t\t\t)[ ]*\n\
          \t\t\t\t\t\t\t"
      - name: punctuation.fix_this_later.pipe.mediawiki
        match: \|
      - include: "#style_in_link"
    - name: meta.link.wiki.mediawiki
      endCaptures: 
        "2": 
          name: string.other.title.link.wiki-link.mediawiki
      begin: |-
        (?x:
        						(\[\[)                       # opening brackets
        						  (:)?                       # colon to suppress image or category?
        						  ((\s+):[^\[\]]*(?=\]\]))?  # a colon after spaces is invalid
        						  [ ]*                       # spaces
        						  ( (([^\[\]|]+)(:))?        # namespace
        						    ([^\[\]|]+)(?<!\s)[ ]*   # link name
        						  )?
        					)
      beginCaptures: 
        "7": 
          name: constant.other.namespace.mediawiki
        "8": 
          name: punctuation.fix_this_later.colon.mediawiki
        "9": 
          name: constant.other.wiki-link.mediawiki
        "1": 
          name: punctuation.fix_this_later.brackets.mediawiki
        "2": 
          name: keyword.operator.wiki-link.suppress-image-or-category.mediawiki
        "4": 
          name: invalid.illegal.whitespace.mediawiki
      end: |-
        (?x:
        						  (\|[ ]*([^\[\]|]+)[ ]*)?     # pipe, spaces, anything, spaces
        						(\]\])                         # closing brackets
        					)
      patterns: 
      - include: "#style_in_link"
    - name: meta.link.inline.external.mediawiki
      begin: \[(\S+)\s*(?=[^\]]*\])
      contentName: string.other.title.link.external.mediawiki
      beginCaptures: 
        "1": 
          name: markup.underline.link.external.mediawiki
      end: \]
      patterns: 
      - include: "#style_in_link"
    - name: markup.underline.link.external.mediawiki
      match: ((https?|ftp|file)://|mailto:)[-:@a-zA-Z0-9_.~%+/?=&#]+(?<![.?:])
  style: 
    patterns: 
    - name: markup.bold.mediawiki
      begin: "'''"
      end: "'''"
      patterns: 
      - include: "#inline"
    - name: markup.italic.mediawiki
      begin: "''"
      end: "''(?!'[^'])"
      patterns: 
      - include: "#inline"
    - captures: 
        "1": 
          name: meta.tag.inline.bold.html.mediawiki
      begin: (<(b|strong)>)
      contentName: markup.bold.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#inline"
    - captures: 
        "1": 
          name: meta.tag.inline.italic.html.mediawiki
      begin: (<(i|em)>)
      contentName: markup.italic.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#inline"
    - captures: 
        "1": 
          name: meta.tag.inline.strikethrough.html.mediawiki
      begin: (<(s|strike)>)
      contentName: markup.other.strikethrough.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#inline"
    - captures: 
        "1": 
          name: meta.tag.inline.underline.html.mediawiki
      begin: (<(u)>)
      contentName: markup.underline.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#inline"
    - captures: 
        "1": 
          name: meta.tag.inline.raw.html.mediawiki
      begin: (<(tt|code)>)
      contentName: markup.raw.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#inline"
    - captures: 
        "1": 
          name: meta.tag.inline.any.html.mediawiki
      begin: (<(big|small|sub|sup)>)
      contentName: markup.other.inline-styles.html.mediawiki
      end: (</\2>)
      patterns: 
      - include: "#inline"
    comment: "\n\
      \t\t\t\tTODO: We still need to add:\n\n\
      \t\t\t\t  * font\n\
      \t\t\t\t  * ruby, rb, rp, rt\n\
      \t\t\t\t  * cite\n\
      \t\t\t\t\n\
      \t\t\t\tinline tags to this section, and make sure that the other\n\
      \t\t\t\ttags can accept attributes in the tag opening, etc.  The\n\
      \t\t\t\tcurrent implementation is intended to be naive, but covering\n\
      \t\t\t\tthe majority of uses in mediawiki code.\n\
      \t\t\t\t\n\
      \t\t\t\tWe also need to add mediawiki-specific tags:\n\
      \t\t\t\t\n\
      \t\t\t\t  * nowiki, noinclude, includeonly\n\
      \t\t\t\t\n\
      \t\t\t"
uuid: 6AF21ADF-316A-47D1-A8B6-1BB38637DE9A
foldingStartMarker: ^(=+)
patterns: 
- include: "#block"
- include: "#inline"
foldingStopMarker: ^.*$(?=\n(=+)|(?!\n))
keyEquivalent: ^~M
comment: "\n\
  \t\tThis language grammar tries to handle Mediawiki syntax.  Mediawiki\n\
  \t\tsyntax is a mess.  This grammar will likely never quite work right.\n\
  \t\tThis is unsurprising as Mediawiki itself has never quite worked right.\n\
  \t\t\n\
  \t\t\t\t--Jacob\n\
  \t\t\n\
  \t\tTODO: lots of fixes still to do:\n\
  \t\t\n\
  \t\t 1. Add a bunch of HTML tags.  See the #block and #style sections.\n\
  \t\t 3. Correctly scope all the parser functions and their contents.\n\
  \t\t    This on will be complicated, as there are several: expr, if, etc.\n\
  \t\t 4. This is probably the biggest one: get all the lists to scope\n\
  \t\t    correctly by type of list.  Right now we just scope every list\n\
  \t\t    as a list, and do not worry about what happens beyond that.\n\
  \t\t    Eventually we want to do numbered and unnumbered separately, etc.\n\
  \t\t 5. Get some kind of folding by heading.  Maybe it should just fold\n\
  \t\t    to the next header, no matter which level it is.  Then we can\n\
  \t\t    make a contents just by folding everything.  Not completely sure\n\
  \t\t\tthis is possible with current TM folding.\n\
  \t\t 7. Make sure that illegal things are correctly scoped illegal.\n\
  \t\t    This is non-trivial, and has several parts\n\
  \t\t    \n\
  \t\t      - Bold/italic are based on brain-dead heuristics.  I want to\n\
  \t\t        be stricter than Mediawiki on this one.  Also, we should\n\
  \t\t        scope as illegal when for instance a new heading starts\n\
  \t\t        before an italic has been closed.\n\
  \t\t      - Templates... these will be pretty tough to do, as they can\n\
  \t\t        be so flexible.\n\
  \t\t      - \n\
  \t\t\n\
  \t\t 9. <timeline></timeline> tag.  I am really not sure this one is\n\
  \t\t    worth trying to do\n\
  \t\t10. Figure out a better scope for meta.function-call.  Infininight\n\
  \t\t    suggests entity.name.function.call, to be paralleled by\n\
  \t\t    entity.name.function.definition.  I am not completly sure I like\n\
  \t\t    that solution, but it is probably better than meta.function-call\n\
  \t\t\n\
  \t\t\n\
  \t\tTODO items not closely related to the grammar:\n\
  \t\t\n\
  \t\t 2. Add a drop command for links/images, add keyboard shortcuts for\n\
  \t\t    them too\n\
  \t\t 3. Make sure all the preference items are sorted out, for instance\n\
  \t\t    smart typing pairs, indent patterns, etc.\n\
  \t\t 4. Commands to do bold/italic, and maybe things like big/small \n\
  \t\t 5. \n\
  \t\t\n\
  \t\tFINISHED:\n\
  \t\t 2. Add support for LaTeX math mode inside of <math></math> tags.\n\
  \t\t 1. Add a command for new list item.  This one is trivial\n\
  \t\t 6. Get the symbol list working on headings.  Trivial.\n\
  \t\t 8. <gallery></gallery> tag.  This one adds some complication, but\n\
  \t\t    is worth supporting.\n\
  \t\t \n\
  \t"
