Parsoid/zh



Parsoid是一个允许在wikitext和HTML之间来回转换的库. 原始应用程序是用JavaScript编写的（借助Node.js），并自2012年12月起在维基媒体集群上运行. 在2019年，Parsoid移植到PHP，维基媒体集群于2019年12月以PHP版本取代了JS版本. Parsoid旨在集成到MediaWiki核心，其目标是最终取代MediaWiki当前的本地解析器.

Parsoid (the PHP version) has been natively bundled with MediaWiki since version 1.35, released in September 2020. For non-Wikimedia installations, Parsoid/JS was supported until the end-of-life of MediaWiki 1.31 (LTS) in September 2021.

技术细节
Parsoid is an application which can translate back and forth 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, Flow, Content Translation and other applications.

Parsoid is intended to provide flawless back-and-forth conversion, i.e. to avoid information loss and also prevent "dirty diffs".

On Wikimedia wikis, for several applications, Parsoid is currently proxied behind RESTBase, which stores the HTML translated by Parsoid. It is expected that RESTBase will eventually be replaced with a cache more tightly integrated with MediaWiki.

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.

Parsoid was originally structured as a web service and written in JavaScript, making use of Node.js. A tech talk from February 2019 and blog post describes the porting process. The Parsoid extension API is currently under active development; a tech talk from August 2020 describes this work.

GitHub Repository: https://github.com/wikimedia/parsoid

用法

 * /Releases/ - List of releases made for parsoid
 * /API - for the web API
 * MediaWiki DOM spec - to make sense of the HTML that you get from the API, designed to be useful as a future storage format
 * /LanguageConverter - notes on Parsoid's implementation of LanguageConverter
 * /Known differences with Core Parser output

安装
In MediaWiki 1.35 LTS Parsoid/PHP is included in the bundle and loaded automatically by Visual Editor. No configuration necessary if used on a single server.

If you are a developer working on 1.36, explicitly loading Parsoid is required since August 24, 2020 (the auto-load hack was removed in 1.36-wmf.6). Add to LocalSettings.php: wfLoadExtension( 'Parsoid', 'vendor/wikimedia/parsoid/extension.json' ); This is expected to change for the release of 1.36.

开发
Development happens in the. Code review happens in Gerrit. See Gerrit/Getting started to set up an account for yourself.

If you use the MediaWiki-Vagrant development environment using a virtual machine, you can simply add the role  to it and it will set up a working Parsoid along with Extension:VisualEditor. (This may have been broken by the switch to Parsoid/PHP: T258940)

Note that the most-recently released version of Parsoid is written in PHP, and installation of Parsoid/PHP is what is described below. This is what you should use if you are running MediaWiki 1.35 or later. Check Parsoid/JS if you are running the old version of Parsoid written in JavaScript, and used for MW 1.34 and earlier.

链接Parsoid的开发人员签出
In a standard MediaWiki installation, Parsoid code is bundled in two different ways: first, Parsoid is included from MediaWiki as a composer library,. This contains the main codebase, but does not contain the REST API used by VisualEditor and RESTBase. In order to enable the REST API, the extension code included in the Parsoid library can be loaded with a call to  in your.

For development purposes you usually want to use a git checkout of Parsoid, and not the version bundled in MediaWiki core as a composer library. The following lines added to  allow use of a git checkout of Parsoid (optionally), load the Parsoid REST API with   (rather than using the version bundled in VisualEditor) and manually do the Parsoid configuration which is usually done by VisualEditor: These lines are not necessary for most users of VisualEditor, who can use auto-configuration and the bundled Parsoid code included in MediaWiki 1.35 and VisualEditor, but they will be required for most developers.

If you're serving MediaWiki with Nginx, you'll need to also add something like this to your server conf: To test proper configuration, visit  where   is the hostname in your. (Note that production WMF servers do not expose the Parsoid REST api to the external network.)

运行测试
To run all parser tests and mocha tests: The parser tests have quite a few options now which can be listed using.

If you have the environment variable  pointing to a configured MediaWiki installation, you can run some additional tests with:

转换简单的wikitext
You can convert simple wikitext snippets from the command line using the  script in the   directory:

echo 'Foo' | php bin/parse.php

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

调试Parsoid（对于开发人员）
See Parsoid/Debugging for debugging tips.

技术文档

 * /Internals: documentation about Parsoid internals with links to other details.
 * PHP Porting notes and help-wanted tasks
 * Parsoid deployment agenda on Wikimedia cluster (code normally deployed every Monday and Wednesday between 1pm - 1:30pm PST)
 * /Round-trip testing: The round-trip testing setup we are using to test the wikitext -> HTML DOM -> wikitext round-trip on actual Wikipedia content.
 * /Visual Diffs Testing: Info about visual diff testing for comparing Parsoid's html rendering with php parser's html rendering + a testreduce setup for doing mass visual diff tests.
 * /limitations: Limitations in Parsoid, mainly contrived templating (ab)uses that don't matter in practice. Could be extended to be similar to the preprocessor upgrade notes (Might need updating)
 * /Bibliography: Bibliography of related literature

对于Parsoid开发者的链接

 * See Parsoid/Debugging for debugging tips.
 * Upgrading or adding packages to Parsoid
 * See these instructions for syncing Parsoid's copy of parser tests to/from core
 * Parsoid has a limited library interface for invoking it programatically.
 * Tech Talk about Retargeting extensions to work with Parsoid

对于Parsoid部署者的链接（到维基媒体集群）

 * Parsoid/Deployments
 * RT testing commits (useful to check regressions and fixes)
 * Deployment instructions for Parsoid
 * Kibana dashboard
 * Grafana dashboard for wt2html metrics
 * Grafana dashboard for html2wt metrics
 * Grafana dashboard for non-200 responses
 * Prometheus breakdown for the Parsoid cluster on eqiad
 * Prometheus breakdown for the Parsoid cluster on codfw
 * Jenkins Job Builder docs for updating jenkins jobs

参见

 * API
 * RESTBase: a caching / storing API proxy for page HTML translated by Parsoid
 * Quarterly review meetings of the Parsoid team: April 2015, January 2015 (earlier)
 * Future/Parser plan: Early (now relatively old) design ideas and issues
 * Special:PrefixIndex/Parsoid/: Parsoid-related pages on this wiki
 * Extension:ParsoidBatchAPI
 * parsoid-jsapi: a high-level interface for extraction and transformation of wikitext, similar to the mwparserfromhell API.
 * Alternative parsers

外部链接

 * Source code (GitHub mirror)
 * JS Documentation (old version of Parsoid)
 * PHP Documentation
 * Parsoid on the Wikimedia Commons

联络
If you need help or have questions/feedback, you can contact us in or the wikitext-l mailing list. If all that fails, you can also contact us by email at parsing-team at the wikimedia.org domain.