Browsable MediaWiki Grammar

CC-BY

Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: doc/wiki/mediawiki/bnf/extracted
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

BlockHTML ::=
	Pre
	Blockquote
	TableHTML
	Div
	HeaderHTML
WikiMarkupCharacters ::=
	"|"
	"["
	"]"
	"*"
	"#"
	":"
	";"
	"<"
	">"
	"="
	"'"
	"{"
	"}"
UnicodeCharacter ::=
	?_all_supported_Unicode_characters_?_-_Whitespaces
UnicodeWiki ::=
	UnicodeCharacter_-_WikiMarkupCharacters
PlainText ::=
	UnicodeWiki
	"<nowiki>" ("|" | "[" | "]" | "<" | ">" | "{" | "}")* "</nowiki>"
	UnicodeWiki " "* ("*" | "#" | ":" | ";")
	UnicodeWiki " "? "=" " "? UnicodeWiki
	UnicodeWiki "'"
	"'" UnicodeWiki
WhiteSpaces ::=
	" "
	NewLine
	?_carriage_return_?
	?_line_feed_?
	?_tab_?
	?_variants_of_spaces_?
NewLine ::=
	?_carriage_return_and_line_feed_?
Line ::=
	PlainText PlainText* (" " " "* PlainText PlainText*)*
Text ::=
	Line Line* (NewLine NewLine* Line Line*)*
PageName ::=
	TitleCharacter "," (" "? TitleCharacter)*
PageNameLink ::=
	TitleCharacter "," ((" " | "_")? TitleCharacter)*
SectionTitle ::=
	(SectionLinkCharacter_- "=") (" "? (SectionLinkCharacter_- "="))*
SectionLink ::=
	SectionLinkCharacter ("_"? SectionLinkCharacter)*
LinkTitle ::=
	(UnicodeCharacter " "*)* (UnicodeCharacter_- "]")
TitleCharacter ::=
	UnicodeCharacter_-_BadTitleCharacters
BadTitleCharacters ::=
	"["
	"]"
	"{"
	"}"
	"<"
	">"
	"_"
	"|"
	"#"
SectionLinkCharacter ::=
	UnicodeCharacter_-_BadSectionLinkCharacters
BadSectionLinkCharacters ::=
	"["
	"]"
	"|"
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 ::=
	"&lt;nowiki" (whitespace characters?)? "&gt;"
nowiki-closing-tag ::=
	"&lt;/nowiki" whitespace? "&gt;"
nowiki-body ::=
	characters
pre-block ::=
	pre-opening-tag whitespace? pre-body whitespace? (pre-closing-tag | ε)
pre-opening-tag ::=
	"&lt;pre" (whitespace characters?)? "&gt;"
pre-closing-tag ::=
	"&lt;/pre" whitespace? "&gt;"
pre-body ::=
	characters
html-block ::=
	html-opening-tag whitespace? html-body whitespace? (html-closing-tag | ε)
html-opening-tag ::=
	"&lt;html" (whitespace characters?)? "&gt;"
html-closing-tag ::=
	"&lt;/html" whitespace? "&gt;"
html-body ::=
	characters
html-comment ::=
	"&lt;!--" characters*? "-->"
Table ::=
	"{|" (" " TableParameters)? NewLine TableFirstRow "|}"
TableFirstRow ::=
	TableColumnLine NewLine
	TableColumnMultiLine
	TableRow
TableRow ::=
	"|-" CSS? NewLine TableColumn TableRow?
TableColumn ::=
	TableColumnLine
	TableColumnMultiLine
TableColumnLine ::=
	"|" InlineText ("|" TableColumnLine)?
TableColumnMultiLine ::=
	"|" (TableCellParameters "|")? AnyText NewLine TableColumnMultiLine?
TableParameters ::=
	CSS
	? HTML table attributes ?
TableCellParameter ::=
	CSS
	? HTML cell attributes ?
ImageInline ::=
	"[[" "Image:" PageName "." ImageExtension (Pipe ImageOption)* "]]"
ImageName ::=
	PageName "." ImageExtension
ImageExtension ::=
	"jpg"
	"jpeg"
	"png"
	"svg"
	"gif"
	"bmp"
ImageOption ::=
	ImageModeParameter
	ImageSizeParameter
	ImageAlignParameter
	ImageVAlignParameter
	Caption
ImageModeParameter ::=
	ImageModeManualThumb
	ImageModeThumb
	ImageModeFrame
	ImageModeFrameless
ImageModeManualThumb ::=
	"thumbnail=" ImageName
	"thumb=" ImageName
ImageModeAutoThumb ::=
	"thumbnail"
	"thumb"
ImageModeFrame ::=
	"framed"
	"enframed"
	"frame"
ImageModeFrameless ::=
	"frameless"
ImageOtherParameter ::=
	ImageParamPage
	ImageParamUpright
	ImageParamBorder
ImageParamPage ::=
	"page=$1"
	"page $1"
ImageParamUpgright ::=
	"upright" ("="? PositiveInteger)?
ImageParamBorder ::=
	"border"
ImageSizeParameter ::=
	PositiveNumber "px"
ImageAlignParameter ::=
	ImageAlignLeft
	ImageAlign
	Center
	ImageAlignRight
	ImageAlignNone
ImageAlignLeft ::=
	"left"
ImageAlignCenter ::=
	"center"
	"centre"
ImageAlignRight ::=
	"right"
ImageAlignNone ::=
	"none"
ImageValignParameter ::=
	ImageValignBaseline
	ImageValignSub
	ImageValignSuper
	ImageValignTop
	ImageValignTextTop
	ImageValignMiddle
	ImageValignBottom
	ImageValignTextBottom
ImageValignBaseline ::=
	"baseline"
ImageValignSub ::=
	"sub"
ImageValignSuper ::=
	"super"
	"sup"
ImageValignTop ::=
	"top"
ImageValignTextTop ::=
	"text-top"
ImageValignMiddle ::=
	"middle"
ImageValignBottom ::=
	"bottom"
ImageValignTextBottom ::=
	"text-bottom"
Caption ::=
	inline-text
MediaInline ::=
	"[[" "Media:" PageName "." MediaExtension "]]"
MediaExtension ::=
	"ogg"
	"wav"
GalleryBlock ::=
	"<gallery>" NewLine? GalleryImage (NewLine? GalleryImage)* NewLine? "</gallery>"
GalleryImage ::=
	to_be_defined_ ":" __essentially___foo_ "." _jpg (ε | caption)?
canonical-article-title ::=
	canonical-page canonical-sub-pages?
canonical-sub-pages ::=
	canonical-sub-page canonical-sub-pages?
canonical-sub-page ::=
	sub-page-separator canonical-page-chars
canonical-page ::=
	canonical-page-first-char canonical-page-chars?
canonical-page-chars ::=
	canonical-page-char canonical-page-chars?
canonical-page-first-char ::=
	ucase-letter
	digit
	underscore
	"." "." "." "?"
canonical-page-char ::=
	letter
	digit
	underscore
	"." "." "." "?"
sub-page-separator ::=
	"/"
article-title ::=
	page sub-pages?
sub-pages ::=
	sub-page sub-pages?
sub-page ::=
	sub-page-separator page-chars
page ::=
	page-first-char page-chars?
page-chars ::=
	page-char page-chars?
page-first-char ::=
	canonical-page-first-char
	lcase-letter
	"." "." "." "?"
page-char ::=
	canonical-page-char
	space
	"." "." "." "?"
wiki-page ::=
	redirect article?
	article?
redirect ::=
	redirect-tag characters internal-link-start article-link (internal-link-end | pipe | EOL)
redirect-tag ::=
	FROM_LANGUAGE_FILE
article ::=
	special-block-and-more
	paragraph-and-more
special-block-and-more ::=
	special-block (EOF | newline? special-block-and-more | (newline | ε) paragraph-and-more)
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
link ::=
	internal-link
	external-link
internal-link ::=
	internal-link-start article-link ("#" section-id)? (pipe link-description?)? internal-link-end extra-description?
article-link ::=
	(interwiki-prefix | ":")? namespace-prefix? article-title
article-link ::=
	(interwiki-prefix | ":")? namespace-prefix? article-title
	"/" article-title
	"../"* article-title?
article-title ::=
	(title-legal-chars | "%")?+
title-legal-chars ::=
	" "
	"%"
	"!"
	"""
	"$"
	"&"
	"'"
	"("
	")"
	"*"
	","
	"-"
	"."
	"/"
	"0"
	"1"
	"2"
	"3"
	"4"
	"5"
	"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"ø"
	"ù"
	"ú"
	"û"
	"ü"
	"ý"
	"þ"
	"ÿ"
	"+"
interwiki-prefix ::=
	interwiki ":"
interwiki ::=
	STRING_FROM_DB
namespace-prefix ::=
	namespace? ":"
namespace ::=
	STRING_FROM_CONFIG
link-description ::=
	LEGAL_ARTICLE_ENTITY
extra-description ::=
	letter extra-description?
internal-link-start ::=
	"[["
internal-link-end ::=
	"]]"
pipe ::=
	"|"
section-id ::=
	(title-legal-chars | "%" | "#")?+
category ::=
	internal-link-start category-namespace ":" article-title (pipe sort-key)? internal-link-end
category-namespace ::=
	NS_CATEGORY
external-link ::=
	external-link-start url whitespace? link-description? external-link-end
	url
url ::=
	protocol url-path
protocol ::=
	ALLOWED_PROTOCOL_FROM_CONFIG (e "." g "." "http://" "," "mailto:")
url-path ::=
	url-char url-path?
url-char ::=
	LEGAL_URL_ENTITY
external-link-start ::=
	"["
external-link-end ::=
	"]"
magic-link ::=
	isbn
	rfc-number
	pmid-number
isbn ::=
	"ISBN" (" " "+") isbn-number "?" (non-word-character "/" "\" b "/")
isbn-number ::=
	("97" ("8" | "9") (" " | "-") "?") (DIGIT (" " | "-") "?") "9"* (DIGIT | "X" | "x")
rfc-number ::=
	"RFC" spaces digits
pmid-number ::=
	"PMID" spaces digits
special-block ::=
	horizontal-rule
	heading
	list-item
	nowiki table / nowiki
	space-block
	"." "." "."
horizontal-rule ::=
	"----" dashes? inline-text? newline
dashes ::=
	"-" dashes?
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
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)?
enumerated-item ::=
	"#" (list-item | item-body)?
bullet-item ::=
	"*" (list-item | item-body)?
item-body ::=
	defined-term
	whitespace? inline-text
defined-term ::=
	";" text definition?
definition ::=
	":" inline-text
space-block ::=
	" " inline-text newline space-block-2*?
space-block-2 ::=
	" " inline-text? newline
inline-text ::=
	inline-element inline-text?
inline-element ::=
	category-link
	internal-link
	external-link
	magic-link
	image-inline
	gallery-block
	media-inline
	text-with-formatting
text-with-formatting ::=
	formatting
	inline-html
	noparseblock
	behaviour-switch
	open-guillemet
	close-guillemet
	html-entity
	html-unsafe-symbol
	text
	random-character
	(more missing "?") "." "." "."
text ::=
	harmless-character+
html-entity ::=
	"&" html-entity-name ";"
	"&#" decimal-number ";"
	"&#x" hex-number ";"
html-entity-name ::=
	Sanitizer ":" ":" "$" wgHtmlEntities (case sensitive) ("*" "Aacute" | "aacute" | "." "." "." "*")
html-unsafe-symbol ::=
	unescaped-ampersand
	unespaced-less-than
	unescaped-greater-than
unescaped-ampersand ::=
	"&"
unescaped-less-than ::=
	"<"
unescaped-greater-than ::=
	">"
harmless-characters ::=
	"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 ::=
	"?" any character "." "." "." "?"
character ::=
	whitespace-char
	non-whitespace-char
	html-entity
whitespace ::=
	whitespace-char whitespace?
	EOF
newlines ::=
	newline newlines?
space-tabs ::=
	space-tab space-tabs?
whitespace-char ::=
	space-tab
	newline
space-tab ::=
	space
	TAB
spaces ::=
	space spaces?
space ::=
	" "
newline ::=
	CR LF
	LF CR
	CR
	LF
BOL ::=
	newline
	BOF
EOL ::=
	newline
	EOF
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"
symbol ::=
	html-unsafe-symbol
	underscore
	"."
	","
	"." "." "."
underscore ::=
	"_"
decimal-number ::=
	decimal-digit decimal-number?
decimal-digit ::=
	"0"
	"1"
	"2"
	"3"
	"4"
	"5"
	"6"
	"7"
	"8"
	"9"
hex-number ::=
	hex-digit hex-number?
hex-digit ::=
	decimal-digit
	"A"
	"B"
	"C"
	"D"
	"E"
	"F"
	"a"
	"b"
	"c"
	"d"
	"e"
	"f"
formatting ::=
	bold-italic-toggle
	bold-toggle
	italic-toggle
bold-italic-toggle ::=
	"'''''"
bold-toggle ::=
	"'''"
italic-toggle ::=
	"''"
formatting ::=
	apostrophe-jungle
apostrophe-jungle ::=
	"''" "'"*
behaviour-switch ::=
	behaviourswitch-toc
	behaviourswitch-forcetoc
	behaviourswitch-notoc
	behaviourswitch-noeditsection
	behaviourswitch-nogallery
behaviourswitch-toc ::=
	"__TOC__" i
behaviourswitch-forcetoc ::=
	"__FORCETOC__" i
behaviourswitch-notoc ::=
	"__NOTOC__" i
behaviourswitch-noeditsection ::=
	"__NOEDITSECTION__" i
behaviourswitch-nogallery ::=
	"__NOGALLERY__" i

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