User:DanielRenfro/Parser Notes
Appearance
From mediawiki.org
The goal of these notes are to:
- understand parsing in general
- thoroughly understand and document the MediaWiki parser
Reading
[edit ]General
[edit ]Software
[edit ]
Mediawiki Parser
[edit ]See also: Parser
Requirements
[edit ]- UTF-8
Types of tokens
[edit ]See also: Markup spec
- syntax
- human-language
- namespaces
- magic words
- html-like tags
- templates (recursive)
- parser functions
- Call helper function
Parser::internalParse(), which in turns callsParser::replaceVariables, which replaces magic variables, templates, and template arguments with the appropriate text.- It calls
Parser::preprocessToDom, which preprocesses some wikitext and returns the document tree. - Next it creates a PPFrame_DOM object and calls its
expand()method to do the actual template magic.
- It calls
Sanitizer::removeHTMLtags(), which cleans up HTML, removes dangerous tags and attributes, and removes HTML comments.Parser::doTableStuff, which handles and renders the wikitext for tables.Parser::doDoubleUnderscore, which removes valid double-underscore items, like __NOTOC__, and records them in array$Parser->mDoubleUnderscores.Parser::doHeadings, which parses and renders section headers.Parser::replaceInternalLinks, which processes internal links ([[ ]]) and stores them in$Parser->mLinkHolders(a LinkHolderArray object),Parser::doAllQuotes, which replaces single quotes with HTML markup (<i>, <b>, etc).Parser::replaceExternalLinks, which replaces and renders external links.Parser::doMagicLinks, which replaces special strings like "ISBN xxx" and "RFC xxx" with magic external links.Parser::formatHeadings, which:- auto numbers headings if that options is enabled,
- adds an [edit] link to sections for users who have enabled the option and can edit the page,
- adds a Table of contents on the top for users who have enabled the option, and
- auto-anchors headings.
- Next,
parse()callsParser::doBlockLevels, which renders lists from lines starting with ':', '*', '#', etc. Parser::replaceLinkHoldersis called, which callsLinkHolderArray::replaceon$Parser->mLinkHoldersto replace link placeholders with actual links, in the buffer Placeholders created in Skin::makeLinkObj()- Next, the text is language converted (when applicable) using the
convertmethod of the appropriate Language object. Parser::replaceTransparentTagsis called, which replaces transparent tags with values which are provided by the callback functions in$Parser->mTransparentTagHooks. Transparent tag hooks are like regular XML-style tag hooks, except they operate late in the transformation sequence, on HTML instead of wikitext.Sanitizer::normalizeCharReferencesis called, which ensures that any entities and character references are legal for XML and XHTML specifically.- If HTML tidy is enabled,
MWTidy::tidyis called to do the tidying. - Finally the rendered HTML result of the parse process is stored in the ParserOutput object
$Parser->mOutput, which is returned to the caller ofParser::parse.