Parsoid/ja



Parsoid はウィキテキストとHTMLを変換するライブラリです. 元々はJavaScript (Node.jsを使用)で記述され、ウィキメディアクラスターで2012年12月に運用開始しました. 2019年、PHPに移植され、12月にウィキメディアクラスターのParsoidもPHPバージョンに置き換えられました. Parsoidは現在 メディアウィキのコアに統合中であり、最終的に今のパーサーを置き換えることを目標としています.

Parsoid(PHP Ver.)は2020年9月のVer.1.35から標準で組み込まれています. ウィキメディア以外でのParsoid/JSの利用は、2021年9月のMediaWiki 1.31 (LTS)のサポート終了までサポートされていました.



技術的な詳細
Parsoidは自動処理と高性能な編集機能のサポートを強化した、メディアウィキのウィキテキスト構文と、それと同等のHTML/RDFaドキュメントモデルを相互に変換できるアプリケーションです.

これは2012年からウィキメディア財団のチームによって開発が続けられています. 現在、と、、他のアプリケーションで広く使われています.

Parsoidは完全な変換、つまり情報の損失を防ぎ、「汚い差分」を無くす事を目的としています.

ウィキメディアのウィキでは現在、いくつかのアプリケーションのためにのHTML変換をバックエンドで行っています. RESTBaseは最終的にメディアウィキと緊密に統合されたキャッシュと置き換えられる予定です.

プロジェクト全体の詳細については、2013年3月のブログの投稿を参照してください. 使用されているHTMLモデルについては、 MediaWiki DOM specを参照してください.

Parsoidは元々JavaScriptで書かれ、 を使用するWebサービスとして作られました. 2019年2月のテクニカルトーク (スライド)とブログ投稿ではPHPへ移植する工程を説明しています. Parsoid拡張APIは現在開発中で、2020年8月のテクニカルトークでこの活動について説明しています.

GitHub リポジトリ： https://github.com/wikimedia/parsoid

使用法

 * - Parsoidリリースノート
 * - web API向け
 * - to make sense of the HTML that you get from the API, designed to be useful as a future storage format
 * - notes on Parsoid's implementation of

インストール
MediaWiki 1.35 LTSではParsoid/PHPは標準でバンドルされており、Visual Editorにより自動的に読み込まれます. 単一のサーバーで使用する場合、設定は必要ありません.

1.36を使用する場合、2020年8月24日以降は明示的にParsoidを読み込む必要があります(自動読み込み機能は1.36-wmf.6で削除されました). 以下をLocalSettings.phpに追加します：

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 development environment using a virtual machine, you can simply add the role   to it and it will set up a working Parsoid along with. (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.

Linking a developer checkout of 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 in your server block (Assuming your MediaWiki setup has its files residing in ):

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 for debugging tips.

Continuous Integration
 As of October 2021 

Parsoid is always available as a library since it is a composer dependency of MediaWiki core. But two pieces are not enabled:


 * Parsoid ServiceWiring
 * Parsoid's external REST api

The test runner Quibble would enable it if it detects  has been cloned as part of the build. In which case it:


 * points the autoloader for  to the cloned code (effectively replacing the version installed by composer)
 * Load the extension

The ServiceWiring should be enabled in MediaWiki starting with 1.38.

The REST API would theorically never get merged in MediaWiki: a) it has never been exposed to the public in production, it is an internal API used by RESTBase which is going away; b) it never has been security audited and c) it is redundant with the enterprise MediaWiki API. The solution will be for VisualEditor to invoke Parsoid directly via the VisualEditor Action API which would save a round trip through the REST API.

Loading the extension is thus a hack which enables using interfaces subject to change and which we don't really want people to use yet.

For most purposes, parsoid should thus not be added as a CI dependency, the only exception as of October 2021 is the Disambiguator MediaWiki extension.

Loading parsoid as an extension let us run MediaWiki integration test jobs against  (such as Quibble, apitesting) and ensure Parsoid and MediaWiki work together.

An extension may be able to write tests with Parsoid even when the repository has not been cloned. Since it is a composer dependency of MediaWiki core the  namespace is available, but the service wiring part is not (it is   in the Parsoid repository and exposed as the   namespace). The  code would only run the parser tests if Parsoid has been loaded (which should be the default with MediaWiki 1.38).

For CI, Parsoid is tested against the tip of mediawiki, whereas mediawiki is tested with the composer dependency. In case of a breaking change, the Parsoid change get merged first (which breaks its CI but not MediaWiki one) and MediaWiki get adjusted when Parsoid is updated. It is thus a one way change.

Release build
For MediaWiki release builds, we have an integration of Parsoid ServiceWiring into VisualEditor in order to have VisualEditor work without further configuration (beside a ). The release build also enables the REST API and hook everything us so that parsoid works out of the box. This is done by copying a bit of parsoid code into VisualEditor which is not in the master branch of VisualEditor since that would be obsolete as soon as Parsoid is updated. Instead the code is maintained in two places.



技術的な説明文書

 * Parsoid/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)
 * Parsoid/Round-trip testing: The round-trip testing setup we are using to test the wikitext -> HTML DOM -> wikitext round-trip on actual Wikipedia content.
 * Parsoid/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.
 * Parsoid/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)
 * Parsoid/Bibliography: Bibliography of related literature



Proton 開発者向けリンク

 * 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
 * So you want your extension to work with Parsoid
 * Parsoid HTML Specification Versioning
 * So you are going to change Parsoid output

Links for Parsoid deployers (to the Wikimedia cluster)

 * 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 (archived)
 * parsoid-jsapi: a high-level interface for extraction and transformation of wikitext, similar to the mwparserfromhell API.
 * Alternative parsers
 * Parsoid/Parser Unification



外部リンク

 * 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.