Browsable MediaWiki Grammar

CC-BY

Grammar connected by Vadim Zaytsev, see the Grammar Zoo entry for details: doc/wiki/mediawiki/bnf/connected
Source used for this grammar: MediaWiki, Markup spec/BNF/Article title, Revision 295042, 28 December 2009 [Page]
Source used for this grammar: MediaWiki, Markup spec/BNF/Article, Revision 281674, 17 October 2009 [Page]
Source used for this grammar: MediaWiki, Markup spec/BNF/Noparse-block, Revision 372814, 30 December 2010 [Page]
Source used for this grammar: MediaWiki, Markup spec/BNF/Links, Revision 376721, 18 January 2011 [Page]
Source used for this grammar: MediaWiki, Markup spec/BNF/Magic links, Revision 269783, 8 August 2009 [Page]
Source used for this grammar: MediaWiki, Markup spec/BNF/Special block, Revision 281676, 17 October 2009 [Page]
Source used for this grammar: MediaWiki, Markup spec/BNF/Inline text, Revision 295055, 29 December 2009 [Page]
Source used for this grammar: MediaWiki, Markup spec/BNF/Fundamental elements, Revision 212918, 17 September 2008 [Page]

Summary

Syntax

wiki-page ::=
	redirect article?
	article?
redirect ::=
	redirect-tag characters internal-link-start article-link (internal-link-end | pipe | EOL)
redirect-tag ::=
	"#redirect"
characters ::=
	character+
character ::=
	whitespace-char
	non-whitespace-char
	html-entity
whitespace-char ::=
	space-tab
	newline
space-tab ::=
	space
	TAB
space ::=
	" "
TAB ::=
	"\t"
newline ::=
	CR LF
	LF CR
	CR
	LF
CR ::=
	"\r"
LF ::=
	"\n"
non-whitespace-char ::=
	letter
	decimal-digit
	symbol
letter ::=
	ucase-letter
	lcase-letter
ucase-letter ::=
	"A"
	"B"
	"C"
	"D"
	"E"
	"F"
	"G"
	"H"
	"I"
	"J"
	"K"
	"L"
	"M"
	"N"
	"O"
	"P"
	"Q"
	"R"
	"S"
	"T"
	"U"
	"V"
	"W"
	"X"
	"Y"
	"Z"
lcase-letter ::=
	"a"
	"b"
	"c"
	"d"
	"e"
	"f"
	"g"
	"h"
	"i"
	"j"
	"k"
	"l"
	"m"
	"n"
	"o"
	"p"
	"q"
	"r"
	"s"
	"t"
	"u"
	"v"
	"w"
	"x"
	"y"
	"z"
decimal-digit ::=
	"0"
	"1"
	"2"
	"3"
	"4"
	"5"
	"6"
	"7"
	"8"
	"9"
symbol ::=
	html-unsafe-symbol
	underscore
	"."
	","
html-unsafe-symbol ::=
	unescaped-ampersand
	unescaped-less-than
	unescaped-greater-than
unescaped-ampersand ::=
	"&"
unescaped-less-than ::=
	"<"
unescaped-greater-than ::=
	">"
underscore ::=
	"_"
html-entity ::=
	"&" html-entity-name ";"
	"&#" decimal-number ";"
	"&#x" hex-number ";"
html-entity-name ::=
	wgHtmlEntities
decimal-number ::=
	decimal-digit+
hex-number ::=
	hex-digit+
hex-digit ::=
	decimal-digit
	"A"
	"B"
	"C"
	"D"
	"E"
	"F"
	"a"
	"b"
	"c"
	"d"
	"e"
	"f"
internal-link-start ::=
	"[["
article-link ::=
	(interwiki-prefix | ":")? namespace-prefix? article-title
article-link ::=
	(interwiki-prefix | ":")? namespace-prefix? article-title
	"/" article-title
	"../"* article-title?
interwiki-prefix ::=
	interwiki ":"
interwiki ::=
	"Wikipedia"
namespace-prefix ::=
	namespace? ":"
namespace ::=
	string
article-title ::=
	page sub-page*
article-title ::=
	(title-legal-char | "%")*
page ::=
	page-first-char page-char*
page-first-char ::=
	canonical-page-first-char
	lcase-letter
canonical-page-first-char ::=
	ucase-letter
	decimal-digit
	underscore
page-char ::=
	canonical-page-char
	space
canonical-page-char ::=
	letter
	decimal-digit
	underscore
sub-page ::=
	sub-page-separator page-char+
sub-page-separator ::=
	"/"
title-legal-char ::=
	space
	"%"
	"!"
	"""
	"$"
	"&"
	"'"
	"("
	")"
	"*"
	","
	"-"
	"."
	"/"
	"0"
	"1"
	"2"
	"3"
	"4"
	"5"
	"6"
	"7"
	"8"
	"9"
	":"
	";"
	"="
	"?"
	"@"
	"A"
	"B"
	"C"
	"D"
	"E"
	"F"
	"G"
	"H"
	"I"
	"J"
	"K"
	"L"
	"M"
	"N"
	"O"
	"P"
	"Q"
	"R"
	"S"
	"T"
	"U"
	"V"
	"W"
	"X"
	"Y"
	"Z"
	"\"
	"^"
	"_"
	"`"
	"a"
	"b"
	"c"
	"d"
	"e"
	"f"
	"g"
	"h"
	"i"
	"j"
	"k"
	"l"
	"m"
	"n"
	"o"
	"p"
	"q"
	"r"
	"s"
	"t"
	"u"
	"v"
	"w"
	"x"
	"y"
	"z"
	"~"
	"€"
	""
	"‚"
	"ƒ"
	"„"
	"…"
	"†"
	"‡"
	"ˆ"
	"‰"
	"Š"
	"‹"
	"Œ"
	""
	"Ž"
	""
	""
	"‘"
	"’"
	"“"
	"”"
	"•"
	"–"
	"—"
	"˜"
	"™"
	"š"
	"›"
	"œ"
	""
	"ž"
	"Ÿ"
	" "
	"¡"
	"¢"
	"£"
	"¤"
	"¥"
	"¦"
	"§"
	"¨"
	"©"
	"ª"
	"«"
	"¬"
	"­"
	"®"
	"¯"
	"°"
	"±"
	"²"
	"³"
	"´"
	"µ"
	"¶"
	"·"
	"¸"
	"¹"
	"º"
	"»"
	"¼"
	"½"
	"¾"
	"¿"
	"À"
	"Á"
	"Â"
	"Ã"
	"Ä"
	"Å"
	"Æ"
	"Ç"
	"È"
	"É"
	"Ê"
	"Ë"
	"Ì"
	"Í"
	"Î"
	"Ï"
	"Ð"
	"Ñ"
	"Ò"
	"Ó"
	"Ô"
	"Õ"
	"Ö"
	"×"
	"Ø"
	"Ù"
	"Ú"
	"Û"
	"Ü"
	"Ý"
	"Þ"
	"ß"
	"à"
	"á"
	"â"
	"ã"
	"ä"
	"å"
	"æ"
	"ç"
	"è"
	"é"
	"ê"
	"ë"
	"ì"
	"í"
	"î"
	"ï"
	"ð"
	"ñ"
	"ò"
	"ó"
	"ô"
	"õ"
	"ö"
	"÷"
	"ø"
	"ù"
	"ú"
	"û"
	"ü"
	"ý"
	"þ"
	"ÿ"
	"+"
internal-link-end ::=
	"]]"
pipe ::=
	"|"
EOL ::=
	newline
	EOF
article ::=
	special-block-and-more
	paragraph-and-more
special-block-and-more ::=
	special-block (EOF | newline? special-block-and-more | newline? paragraph-and-more)
special-block ::=
	horizontal-rule
	heading
	list-item
	table
	space-block
horizontal-rule ::=
	"----" dashes? inline-text? newline
dashes ::=
	"-"+
inline-text ::=
	inline-element inline-text?
inline-element ::=
	category-link
	link
	magic-link
	image-inline
	gallery-block
	media-inline
	text-with-formatting
category-link ::=
	internal-link-start category-namespace ":" article-title (pipe sort-key)? internal-link-end
category-namespace ::=
	"Category"
sort-key ::=
	any-text
any-text ::=
	unicode-character*
unicode-character ::=
	any-supported-unicode-character &amp; ¬Whitespaces
any-supported-unicode-character ::=
	α
Whitespaces ::=
	newline
	TAB
	space
link ::=
	internal-link
	external-link
internal-link ::=
	internal-link-start article-link ("#" section-id)? (pipe link-description?)? internal-link-end extra-description?
section-id ::=
	(title-legal-char | "%" | "#")*
link-description ::=
	article-title
extra-description ::=
	letter+
external-link ::=
	external-link-start url whitespace? link-description? external-link-end
	url
external-link-start ::=
	"["
url ::=
	protocol url-path
protocol ::=
	"http://"
	"https://"
	"ftp://"
	"ftps://"
	"mailto:"
url-path ::=
	url-char url-path?
url-char ::=
	LEGAL_URL_ENTITY
whitespace ::=
	whitespace-char whitespace?
	EOF
external-link-end ::=
	"]"
magic-link ::=
	isbn
	rfc-number
	pmid-number
isbn ::=
	"ISBN" spaces isbn-number
spaces ::=
	space+
isbn-number ::=
	"97" ("8" | "9") (space | "-")? decimal-digit (space | "-")? "9"* (decimal-digit | "X" | "x")
rfc-number ::=
	"RFC" spaces digits
digits ::=
	decimal-digit+
pmid-number ::=
	"PMID" spaces digits
image-inline ::=
	"[[" "Image:" page-name "." image-extension (pipe image-option)* "]]"
page-name ::=
	title-character (space? title-character)*
title-character ::=
	unicode-character &amp; ¬bad-title-characters
bad-title-characters ::=
	"["
	"]"
	"{"
	"}"
	"<"
	">"
	"_"
	"|"
	"#"
image-extension ::=
	"jpg"
	"jpeg"
	"png"
	"svg"
	"gif"
	"bmp"
image-option ::=
	image-mode-parameter
	image-size-parameter
	image-align-parameter
	image-valign-parameter
	caption
	image-other-parameter
image-mode-parameter ::=
	image-mode-manual-thumb
	image-mode-auto-thumb
	image-mode-frame
	image-mode-frameless
image-mode-manual-thumb ::=
	"thumbnail=" image-name
	"thumb=" image-name
image-name ::=
	page-name "." image-extension
image-mode-auto-thumb ::=
	"thumbnail"
	"thumb"
image-mode-frame ::=
	"framed"
	"enframed"
	"frame"
image-mode-frameless ::=
	"frameless"
image-size-parameter ::=
	digits "px"
image-align-parameter ::=
	image-align-left
	image-align-center
	image-align-right
	image-align-none
image-align-left ::=
	"left"
image-align-center ::=
	"center"
	"centre"
image-align-right ::=
	"right"
image-align-none ::=
	"none"
image-valign-parameter ::=
	image-valign-baseline
	image-valign-sub
	image-valign-super
	image-valign-top
	image-valign-text-top
	image-valign-middle
	image-valign-bottom
	image-valign-text-bottom
image-valign-baseline ::=
	"baseline"
image-valign-sub ::=
	"sub"
image-valign-super ::=
	"super"
	"sup"
image-valign-top ::=
	"top"
image-valign-text-top ::=
	"text-top"
image-valign-middle ::=
	"middle"
image-valign-bottom ::=
	"bottom"
image-valign-text-bottom ::=
	"text-bottom"
caption ::=
	inline-text
image-other-parameter ::=
	image-param-page
	image-param-upright
	image-param-border
image-param-page ::=
	"page=$1"
	"page $1"
image-param-upright ::=
	"upright" ("="? digits)?
image-param-border ::=
	"border"
gallery-block ::=
	"<gallery>" newline? gallery-image (newline? gallery-image)* newline? "</gallery>"
gallery-image ::=
	image-name ("|" caption)?
media-inline ::=
	"[[" "Media:" page-name "." media-extension "]]"
media-extension ::=
	"ogg"
	"wav"
text-with-formatting ::=
	formatting
	inline-html
	noparse-block
	behaviour-switch
	html-entity
	html-unsafe-symbol
	text
	random-character
formatting ::=
	bold-italic-toggle
	bold-toggle
	italic-toggle
bold-italic-toggle ::=
	"'''''"
bold-toggle ::=
	"'''"
italic-toggle ::=
	"''"
noparse-block ::=
	nowiki-block
	html-block
	math-block
	pre-block
	html-comment
nowiki-block ::=
	nowiki-opening-tag whitespace? nowiki-body whitespace? nowiki-closing-tag?
nowiki-opening-tag ::=
	"<nowiki" (whitespace characters?)? ">"
nowiki-body ::=
	characters
nowiki-closing-tag ::=
	"</nowiki" whitespace? ">"
html-block ::=
	html-opening-tag whitespace? html-body whitespace? html-closing-tag?
html-opening-tag ::=
	"<html" (whitespace characters?)? ">"
html-body ::=
	characters
html-closing-tag ::=
	"</html" whitespace? ">"
pre-block ::=
	pre-opening-tag whitespace? pre-body whitespace? pre-closing-tag?
pre-opening-tag ::=
	"<pre" (whitespace characters?)? ">"
pre-body ::=
	characters
pre-closing-tag ::=
	"</pre" whitespace? ">"
html-comment ::=
	"<!--" characters? "-->"
behaviour-switch ::=
	behaviourswitch-toc
	behaviourswitch-forcetoc
	behaviourswitch-notoc
	behaviourswitch-noeditsection
	behaviourswitch-nogallery
behaviourswitch-toc ::=
	"__TOC__"
behaviourswitch-forcetoc ::=
	"__FORCETOC__"
behaviourswitch-notoc ::=
	"__NOTOC__"
behaviourswitch-noeditsection ::=
	"__NOEDITSECTION__"
behaviourswitch-nogallery ::=
	"__NOGALLERY__"
text ::=
	line+ (newline+ line+)*
text ::=
	harmless-character+
line ::=
	plain-text+ (spaces plain-text+)*
plain-text ::=
	unicode-wiki
	"<nowiki>" ("|" | "[" | "]" | "<" | ">" | "{" | "}")* "</nowiki>"
	unicode-wiki space* ("*" | "#" | ":" | ";")
	unicode-wiki space? "=" space? unicode-wiki
	unicode-wiki "'"
	"'" unicode-wiki
unicode-wiki ::=
	unicode-character &amp; ¬wiki-markup-characters
wiki-markup-characters ::=
	"|"
	"["
	"]"
	"*"
	"#"
	":"
	";"
	"<"
	">"
	"="
	"'"
	"{"
	"}"
harmless-character ::=
	"A"
	"B"
	"C"
	"D"
	"E"
	"F"
	"G"
	"H"
	"I"
	"J"
	"K"
	"L"
	"M"
	"N"
	"O"
	"P"
	"Q"
	"R"
	"S"
	"T"
	"U"
	"V"
	"W"
	"X"
	"Y"
	"Z"
	"a"
	"b"
	"c"
	"d"
	"e"
	"f"
	"g"
	"h"
	"i"
	"j"
	"k"
	"l"
	"m"
	"n"
	"o"
	"p"
	"q"
	"r"
	"s"
	"t"
	"u"
	"v"
	"w"
	"x"
	"y"
	"z"
	"0"
	"1"
	"2"
	"3"
	"4"
	"5"
	"6"
	"7"
	"8"
	"9"
random-character ::=
	α
heading ::=
	level-6-heading
	level-5-heading
	level-4-heading
	level-3-heading
	level-2-heading
	level-1-heading
level-6-heading ::=
	"======" inline-text "======" space-tabs newline
space-tabs ::=
	space-tab+
level-5-heading ::=
	"=====" inline-text "=====" space-tabs newline
level-4-heading ::=
	"====" inline-text "====" space-tabs newline
level-3-heading ::=
	"===" inline-text "===" space-tabs newline
level-2-heading ::=
	"==" inline-text "==" space-tabs newline
level-1-heading ::=
	"=" inline-text "=" space-tabs newline
list-item ::=
	indent-item
	enumerated-item
	bullet-item
indent-item ::=
	":" (list-item | item-body)?
item-body ::=
	defined-term
	whitespace? inline-text
defined-term ::=
	";" text definition?
definition ::=
	":" inline-text
enumerated-item ::=
	"#" (list-item | item-body)?
bullet-item ::=
	"*" (list-item | item-body)?
table ::=
	"{|" (space table-parameters)? newline table-first-row "|}"
table-parameters ::=
	CSS
	html-table-attributes
table-first-row ::=
	table-column-line newline
	table-column-multiline
	table-row
table-column-line ::=
	"|" inline-text ("|" table-column-line)?
table-column-multiline ::=
	"|" (table-cell-parameters "|")? any-text newline table-column-multiline?
table-cell-parameters ::=
	CSS
	html-cell-attributes
table-row ::=
	"|-" CSS? newline table-column table-row?
table-column ::=
	table-column-line
	table-column-multiline
space-block ::=
	space inline-text newline space-block-2*
space-block-2 ::=
	space inline-text? newline
paragraph-and-more ::=
	paragraph (EOF | newline? special-block-and-more | newline paragraph-and-more)
paragraph ::=
	newline lines-of-text?
	lines-of-text
lines-of-text ::=
	line-of-text lines-of-text?
line-of-text ::=
	inline-text newline

GrammarLabMaintained by Dr. Vadim Zaytsev a.k.a. @grammarware. Last updated in September 2015. []