Jump to: navigation, search

Parsoid is an application which can translate back and forth, at runtime, between MediaWiki's wikitext syntax and an equivalent HTML/RDFa document model with enhanced support for automated processing and rich editing. It has been under development by a team at the Wikimedia Foundation since 2012. It is currently used extensively by VisualEditor and Flow, as well as a growing list of other applications.

Parsoid is structured as a web service, and is written in JavaScript, making use of Node.js. It is intended to provide flawless back-and-forth conversion, i.e. to avoid both "dirty diffs" and any information loss. On Wikimedia wikis, for several applications, Parsoid is currently proxied behind RESTBase, which stores the HTML translated by Parsoid.

For more on the overall project, see this blog post from March 2013. To read about the HTML model being used, see MediaWiki DOM spec.

Artist's impression of the Parsoid HTML5 + RDFa wiki runtime

Getting started

Parsoid is a web-service implemented using node.js, often referred to simply as node. For a quick overview, you can test drive Parsoid using a node web service. Development happens in the Parsoid service in Git (see tree). If you need help, you can contact us in #mediawiki-parsoid or the wikitext-l mailing list.

If you use the MediaWiki-Vagrant development environment using a virtual machine, you can simply add the role visualeditor to it and it will set up a working Parsoid along with Extension:VisualEditor.

Parsoid setup

See Parsoid/Setup for detailed instructions.


See the troubleshooting page.

The Parsoid web API

See Parsoid/API

Converting simple wikitext

You can convert simple wikitext snippets from the command line using the parse.js script:

echo '[[Foo]]' | node tests/parse

The parse script has a lot of options. node parse --help gives you information about this.

In Ubuntu 13 and 14, node has been renamed to nodejs. There, either create a symbolic link (or equivalent) or type:

echo '[[Foo]]' | nodejs tests/parse


Code review happens in Gerrit. See Gerrit/Getting started and ping us in #mediawiki-parsoid.

Running the tests

To run all parser tests:

npm test

parserTests has quite a few options now which can be listed using node ./parserTests.js --help.

Debugging Parsoid (for developers)

See Parsoid/Debugging for debugging tips.


Our plans for Q4 2014 are spelled out in Task T92643. All pending tasks and bugs are tracked in our bug list.

If you have questions, try to ping the team on #mediawiki-parsoidconnect, or send a mail to the wikitext-l mailinglist. If all that fails, you can also contact us by email at parser-team at the domain.


The broad architecture looks like this:

 PEG wiki/HTML tokenizer         (or other tokenizers / SAX-like parsers)
     | Chunks of tokens
 Token stream transformations 
     | Chunks of tokens
 HTML5 tree builder 
     | HTML 5 DOM tree
 DOM Postprocessors 
     | HTML5 DOM tree
 (X)HTML serialization
     +------------------> Browser

So basically a HTML parser pipeline, with the regular HTML tokenizer replaced by a combined Wiki/HTML tokenizer with additional functionality implemented as (mostly syntax-independent) token stream transformations.

  1. The PEG-based wiki tokenizer produces a combined token stream from wiki and html syntax. The PEG grammar is a context-free grammar that can be ported to different parser generators, mostly by adapting the parser actions to the target language. Currently we use pegjs to build the actual JavaScript tokenizer for us. We try to do as much work as possible in the grammar-based tokenizer, so that the emitted tokens are already mostly syntax-independent.
  2. Token stream transformations are used to implement context-sensitive wiki-specific functionality (wiki lists, quotes for italic/bold etc). Templates are also expanded at this stage, which makes it possible to still render unbalanced templates like table start / row / end combinations.
  3. The resulting tokens are then fed to a HTML5-spec compatible DOM tree builder (currently the 'html5' node.js module), which builds a HTML5 DOM tree from the token soup. This step already sanitizes nesting and enforces some content-model restrictions according to the rules of the HTML5 parsing spec.
  4. The resulting DOM is further manipulated using postprocessors. Currently, any remaining top-level inline content is wrapped into paragraphs in such a postprocessor. For output for viewing, further document model sanitation can be added here to get very close to what tidy does in the production parser.
  5. Finally, the DOM tree can be serialized as XML or HTML.

Technical documents

Useful links for Parsoid developers

See also