Parsoid
|
Parsoid
Ein bidirektionaler Runtime-Wikitext-Parser. Schaltet zwischen Wikitext und HTML/XML-DOM mit RDFa hin und her.
|

Parsoid ist eine PHP Bibliothek, die benutzt wird, um zwischen Wikitext und HTML hin und her zu konvertieren. Sie befindet sich seit 2012 in Entwicklung, ursprünglich implementiert in JavaScript und zur Unterstützung des VisualEditor. Parsoid ist seit Version 1.35. in MediaWiki enthalten. Es ist geplant, dass Parsoid in MediaWiki 1.47 der Standardparser wird und den bisherigen native parser ablöst. Das Projekt dazu heißt parser unification.
Technische Details
Parsoid ist eine Anwendung, die zwischen der Wikitext-Syntax von MediaWiki und einem äquivalenten HTML/RDFa-Dokumentenmodell mit erweiterter Unterstützung für automatisierte Verarbeitung und umfassende Bearbeitung hin und her übersetzen kann.
Seit 2012 wird es von einem Team der Wikimedia Foundation entwickelt. Es wird derzeit ausgiebig von VisualEditor, Inhaltsübersetzung und anderen Anwendungen verwendet.
Parsoid soll eine fehlerlose Umwandlung vor und zurück ermöglichen, d. h. um Informationsverlust zu vermeiden und auch "schmutzige Differenzen" zu verhindern.
Auf Wikimedia-Wikis wird Parsoid derzeit für mehrere Anwendungen hinter RESTBase proxyisiert, der das von Parsoid übersetzte HTML speichert. Es wird erwartet, dass RESTBase letztendlich durch einen Cache ersetzt wird, der enger in MediaWiki integriert ist.
Für weitere Informationen zum Gesamtprojekt, siehe diesen Blog-Beitrag vom März 2013. Um mehr über das verwendete HTML-Modell zu erfahren, sehen Sie sich die MediaWiki-DOM-Spezifikation an.
Ursprünglich wurde Parsoid als Webdienst strukturiert und in JavaScript geschrieben, wobei Node.js verwendet wurde.
Ein Technischer Vortrag aus Februar 2019 (Folien) und ein Blog-Beitrag beschreiben den Prozess der Portierung zu PHP.
Die Parsoid-Erweiterungs-API befindet sich derzeit in aktiver Entwicklung; eine technische Präsentation aus August 2020 beschreibt diese Arbeit.
GitHub-Repository: https://github.com/wikimedia/parsoid
Verwendung
- Parsoid/Releases – Liste der für Parsoid veröffentlichten Versionen:
- Parsoid/API – für die Web-API
- MediaWiki DOM spec – um den HTML-Code, den Sie von der API erhalten, sinnvoll zu verarbeiten und als zukünftiges Speicherformat nützlich zu sein
- Parsoid/LanguageConverter – Notizen zur Implementierung von Parsoid von LanguageConverter.
- Parsoid/Known differences with Core Parser output
Installation
Parsoid ist seit Version 1.35. in MediaWiki enthalten. Es ist keine Konfiguration erforderlich, um es zu aktivieren.
Parsoid exportiert eine interne REST API, die historisch von RESTBase verwendet wurde und außerhalb des internen Clusters der WMF nicht zugänglich war. Dies ist für Visual Editor oder Kernlesenansichten nicht mehr erforderlich, und die interne API wird veraltet und wird für die Entfernung in MW 1.43 geplant.
Parsoid ist eine Verfasserbibliothek, die von Mediawiki Core verwendet wird.
Wenn Sie aus irgendeinem Grund immer noch die interne API benötigen, können Sie Parsoid explizit "als Erweiterung" laden, indem Sie Folgendes zu LocalSettings.php hinzufügen:
wfLoadExtension( 'Parsoid', "$IP/vendor/wikimedia/parsoid/extension.json" );
Alle verbleibenden Drittanbieter der internen Parsoid API werden dringend ermutigt, auf den inneren REST HTML-Seitenendpunkt zu migrieren, der gleichwertige Funktionalität bietet.
Entwicklung
Die Entwicklung geschieht in Parsoid Git repository. Die Überprüfung des Codes geschieht in Gerrit. Schau in Gerrit/Getting started, um selbst einen Account zu erstellen.
Wenn du die Entwicklungsumgebung von MediaWiki-Vagrant mit einer virtuellen Maschine verwendest, kannst du einfach die Rolle visualeditor hinzufügen und es wird zusammen mit Extension:VisualEditor ein funktionierendes Parsoid eingerichtet.
Die folgenden Erläuterungen sind für MediaWiki 1.35 oder höher. Überprüfe Parsoid/JS, wenn du ältere Versionen von Parasoid nutzt, welche in JavaScript geschrieben wurden und für MW 1.35 oder früher verwendet werden
Verlinken eines Entwickler-Checkouts von Parsoid
In einer Standardinstallation von MediaWiki wird Parsoid von MediaWiki als Komponistenbibliothek aufgenommen, wikimedia/parsoid.
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 LocalSettings.php allow use of a git checkout of Parsoid (optionally), load the Parsoid REST API with wfLoadExtension (rather than using the version bundled in VisualEditor) and manually do the Parsoid configuration which is usually done by VisualEditor:
$parsoidInstallDir = 'vendor/wikimedia/parsoid'; # bundled copy
#$parsoidInstallDir = '/my/path/to/git/checkout/of/Parsoid';
// For developers: ensure Parsoid is executed from $parsoidInstallDir,
// (not the version included in mediawiki-core by default)
// Must occur *before* wfLoadExtension()
if ( $parsoidInstallDir !== 'vendor/wikimedia/parsoid' ) {
function wfInterceptParsoidLoading( $className ) {
// Only intercept Parsoid namespace classes
if ( preg_match( '/(MW|Wikimedia\\\\)Parsoid\\\\/', $className ) ) {
$fileName = Autoloader::find( $className );
if ( $fileName !== null ) {
require $fileName;
}
}
}
spl_autoload_register( 'wfInterceptParsoidLoading', true, true );
// AutoLoader::registerNamespaces was added in MW 1.39
AutoLoader::registerNamespaces( [
// Keep this in sync with the "autoload" clause in
// $parsoidInstallDir/composer.json
'Wikimedia\\Parsoid\\' => "$parsoidInstallDir/src/",
] );
}
wfLoadExtension( 'Parsoid', "$parsoidInstallDir/extension.json" );
unset( $parsoidInstallDir );
These lines are not necessary for most users of VisualEditor, who can use VisualEditor's auto-configuration and the bundled Parsoid code included in MediaWiki, 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 /w/):
location /w/rest.php/ {
try_files $uri $uri/ /w/rest.php?$query_string;
}
If you are running Mediawiki using Docker, and linking your local Parsoid repository to Mediawiki, you need to map additional volume to the docker container in docker-compose.override.yml file in media wiki project. To do so, the simplest way is to create docker-compose.override.yml in mediawiki project and put code bellow inside (with path modification). If you already have docker-compose.override.yml file, modify it accordingly.
services:
mediawiki:
volumes:
- ./:/var/www/html/w:cached
- /my/path/to/git/checkout/of/Parsoid:/my/path/to/git/checkout/of/Parsoid
To test proper configuration, visit {$wgScriptPath}/rest.php/{$domain}/v3/page/html/Main%20Page where $domain is the hostname in your $wgCanonicalServer.
(Note that production WMF servers do not expose the Parsoid REST API to the external network.)
Die Tests ausführen
To run all parser tests and mocha tests:
$ composer test
The parser tests have quite a few options now which can be listed using php bin/parserTests.php --help.
If you have the environment variable MW_INSTALL_DIR pointing to a configured MediaWiki installation, you can run some additional tests with:
$ composer phan-integrated
Einfachen Wikitext konvertieren
You can convert simple wikitext snippets from the command line using the parse.php script in the bin/ directory:
$ echo '[[Foo]]' | php bin/parse.php
The parse script has a lot of options.
php bin/parse.php --help gibt Ihnen Informationen dazu.
Parsoid debuggen (für Entwickler)
See Parsoid/Debugging for debugging tips.
Continuous Integration
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 mediawiki/services/parsoid.git has been cloned as part of the build.
In which case it:
- points the autoloader for
Wikimedia\Parsoidto the cloned code (effectively replacing the version installed by composer) - Laden Sie die Erweiterung
wfLoadExtension( 'Parsoid', '/path/to/cloned/repo' );
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 mediawiki/services/parsoid.git (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 MediaWiki\Parsoid namespace is available, but the service wiring part is not (it is extension/src in the Parsoid repository and exposed as the \MWParsoid namespace).
The ParsoidTestFileSuite.php 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 wfLoadExtension( 'VisualEditor' )).
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.
Technische Dokumente
- 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
Links für Parsoid-Entwickler
- 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 für Parsoid-Einsatzkräfte (zum 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
- Prometheus breakdown for the Parsoid cluster on eqiad
- Prometheus breakdown for the Parsoid cluster on codfw
- Jenkins Job Builder docs for updating jenkins jobs
Geschichte
Die ursprüngliche Anwendung ist in JavaScript geschrieben (unter Verwendung von Node.js) und war seit Dezember 2012 auf dem Wikimedia-Cluster in Betrieb. Im Jahr 2019 wurde Parsoid auf PHP portiert, und die PHP-Version ersetzte die JS-Version auf dem Wikimedia-Cluster im Dezember 2019. Parsoid wird gerade in den Core von MediaWiki integriert, mit dem Ziel, irgendwann den derzeitigen nativen Parser von MediaWiki zu ersetzen. In early 2024, Parsoid began to be used on some production wikis of the Wikimedia Foundation as the default parser for read views. You can see them in the production config list.
Parsoid (die PHP-Version) wurde seit Version 1.35, die im September 2020 veröffentlicht wurde, von Natur aus gebündelt mit MediaWiki. Für Installationen außerhalb von Wikimedia wurde Parsoid/JS bis zum Lebensende von MediaWiki 1.31 (LTS) im September 2021 unterstützt.
FAQ
- Wie kann ich sehen, ob eine Seite mit Parsoid gerendert wurde?
- The footer will say "Page was rendered with Parsoid".
- How do I set a page to temporarily render with Parsoid?
- Install Erweiterung:ParserMigration
- Add
?useparsoid=1to the URL
- How do I get an entire wiki to render with Parsoid?
- Install Erweiterung:ParserMigration
- Set
$wgParserMigrationEnableParsoidArticlePages = true; - Set
$wgParserMigrationEnableParsoidDiscussionTools = true;
- Which Wikimedia wikis render with Parsoid?
- The list is at parsoidrendered.dblist. As of August 2025, it is approximately 250 of the 1000 wikis. Rollout will continue until all wikis are using Parsoid.
Siehe auch
- API
- RESTBase – a caching / storing API proxy for page HTML translated by Parsoid
- Parser 2011/Parser plan – Early (now relatively old) design ideas and issues from 2011
- 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
Externe Links
- Source code (GitHub mirror)
- JS Documentation (old version of Parsoid)
- PHP Documentation
- Parsoid on the Wikimedia Commons
Kontakt
If you need help or have questions/feedback, you can contact us in #mediawiki-parsoid connect or the wikitext-l mailing list.
If all that fails, you can also contact us by email at content-transform-team at the wikimedia.org domain.
Parsoid wird betreut von Content Transform Team.
Hilfe erhalten:
|
