### Install Parsoid Node.js Dependencies Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/docs/setup.md After cloning the repository, execute this command from the main Parsoid directory to install all required Node.js packages and dependencies using npm. ```Shell $ npm install ``` -------------------------------- ### Install Parsoid Dependencies and Run Tests Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/README.md Instructions to navigate to the project root, install Node.js dependencies, and execute the test suite for the Parsoid project. ```Shell cd .. npm test ``` -------------------------------- ### Run Parsoid API Server Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/docs/setup.md This command starts the Parsoid API server, which is primarily used by VisualEditor for backend operations. Users can customize settings by copying and modifying `config.example.yaml`. ```Shell $ node bin/server ``` -------------------------------- ### MediaWiki Parser Configuration Example Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/sectionWrappingParserTests.txt An example of a JSON configuration setting, likely related to how sections are handled during parsing, indicating that sections should be wrapped. ```JSON { "wrapSections": true } ``` -------------------------------- ### Test Case 2: Basic Content Rendering with Generic HTML Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/phpunit/Parsoid/ParserTests/data/basicTests.txt This second test case illustrates the rendering of 'Hello 2' content, showing both the original wikitext input and its corresponding generic HTML output. It serves as a straightforward example of content transformation from wikitext to standard HTML. ```wikitext Hello 2 ``` ```html
Hello 2
``` -------------------------------- ### Clone Parsoid Git Repository Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/docs/setup.md This command clones the Parsoid source code repository from Gerrit, making the project files available locally for setup and development. ```Shell $ git clone https://gerrit.wikimedia.org/r/p/mediawiki/services/parsoid ``` -------------------------------- ### Launch Parsoid HTTP API Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/docs/devsetup.md Starts Parsoid's HTTP API server, allowing developers to verify appropriate responses directly in a web browser. This is useful for interactive testing of the API's behavior. ```Bash npm start ``` -------------------------------- ### Wikitext Test Setup: Template and Article Definition Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/separatorTests.txt This section defines a simple template `Template:1x` that expands its first parameter, and an `article` block that uses this template. This setup is foundational for subsequent tests demonstrating separator handling. ```Wikitext Template:1x !! text {{{1}}} ``` -------------------------------- ### Convert Inline Dummyanno Tags Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/annotationParserTests.txt This test verifies the conversion of inline 'dummyanno' tags in wikitext to HTML, ensuring the correct placement of start and end meta tags for the annotation. ```wikitext Some textSome text with some annotated content inline.
``` -------------------------------- ### Example: Get Parsoid Daemon Version using cURL Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/docs/apiuse.md Demonstrates how to use the `curl` command-line tool to query the `/_version` endpoint and retrieve the Parsoid daemon's version information. The expected response is a JSON object containing `name`, `version`, and `sha`. ```Shell curl http://localhost:8000/_version ``` -------------------------------- ### Running Parsoid API Server for Testing Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/docs/devsetup.md Instructions for testing the Parsoid API server by running `npm start` and verifying its response by loading a specific page, such as French Wikipedia's page on Obama, to ensure accurate and semantically consistent output. ```Shell npm start ``` -------------------------------- ### Handling Multiple Spaces at Start-of-Line Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/indentPre.txt Examines how multiple leading spaces at the start of a line in wikitext are interpreted, distinguishing between preformatted text, HTML tags, and table syntax. ```Wikitextfoo
\n foo\n\t{|\n|foo\n|} ``` ```HTMLfoo
\nfoo\n\n
| foo\n |
hi``` ```PHP HTML
hi\n``` -------------------------------- ### Converting a Simple Wikitext Table to HTML Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/tables.txt This example illustrates the basic conversion of a two-row, two-column MediaWiki wikitext table into its standard HTML representation, showing how rows and cells are structured. ```wikitext {| |1||2 |- |3||4 |} ``` ```html
| 1 | 2 |
| 3 | 4 |
Hello legacy
``` ```html/parsoidHello parsoid
``` -------------------------------- ### Wikitext Redirect Syntax Not at Start of Line Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/redirects.txt Confirms that `#redirect` syntax is only recognized as a page redirect if it appears at the very beginning of the wikitext content. If preceded by other text, it's rendered as a regular list item, not a redirect. ```Wikitext some text #redirect [[Main Page]] ``` ```HTMLsome text
plop
Let's have some text.
``` -------------------------------- ### Parsoid Test Configuration and Article Setup Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/interwikiLinks.txt Defines initial options for Parsoid parser tests and sets up standard articles ('Main Page', 'Foo', 'Template:Foo') that are assumed to exist for the subsequent tests. The 'parsoid-compatible' option is relevant when running parser tests in integrated mode with Parsoid. ```Configuration parsoid-compatible=wt2html,wt2wt version=2 ``` ```Wikitext (Article Definition) Main Page !! text blah blah ``` ```Wikitext (Article Definition) Foo !!text FOO ``` ```Wikitext (Article Definition) Template:Foo !!text FOO ``` -------------------------------- ### Generic Wikitext to HTML Conversion Test Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/phpunit/Parsoid/ParserTests/data/testsWithKnownFailures.txt This snippet provides a second example of wikitext to HTML conversion, using 'Hello 2' as input. It illustrates a general HTML output, useful for verifying basic rendering functionality and consistency across different conversion scenarios. ```wikitext Hello 2 ``` ```htmlHello 2
``` -------------------------------- ### Timing Metrics for HTML to Wikitext Conversion in Parsoid Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/docs/metrics.md Documents performance metrics for converting edited HTML back to wikitext, including initialization, selser setup, preprocessing, DOM diff computation, and total serialization time. ```APIDOC Metric: html2wt.init Description: Covers time to parse edited HTML and original HTML, including pagebundles. Location: Rest/Handler/ParsoidHandler.php Metric: html2wt.setup Description: Covers time to set up selser (selective serialization). Location: Wikitext/ContentHandler.php Metric: html2wt.preprocess Description: Covers time to run any extension preprocessors (currently none as of March 2022). Location: Wikitext/ContentHandler.php Metric: html2wt.selser.domDiff Description: Covers time to compute DOM diff between original and edited DOMs. Location: Html2Wt/SelectiveSerializer.php Metric: html2wt.selser.serialize Description: Covers total time to convert HTML to wikitext after selser setup, including html2wt.selser.domDiff. Location: Html2Wt/SelectiveSerializer.php Metric: html2wt.total Description: Covers the total request time within Parsoid, including all html2wt components. Location: Rest/Handler/ParsoidHandler.php ``` -------------------------------- ### Demonstrate f3_uc Parser Function for Uppercase Conversion Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/pFragmentHandlerTests.txt This snippet shows the basic usage of the `#f3_uc` parser function to convert input text to uppercase. It includes examples with simple strings and nested parser functions. ```MediaWiki Wikitext {{#f3_uc:lower UPPER}} {{#f3_uc:{{1x|foo}}}} ``` ```HTMLLOWER UPPER
FOO
``` -------------------------------- ### Parsoid Wikitext to HTML Conversion Test: Hello Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/phpunit/Parsoid/ParserTests/data/testNoEndTag.txt This test case demonstrates the conversion of the wikitext 'test 1' into its corresponding HTML output 'test 1
'. It serves as a basic example of Parsoid's rendering capabilities for simple text. ```wikitext test 1 ``` ```htmltest 1
``` -------------------------------- ### Indent-Pre started by table-line syntax Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/indentPre.txt This test explores how a preformatted block is initiated when a line of text is followed by lines that resemble table-line syntax but are indented, showing the different interpretations by PHP and Parsoid HTML renderers. ```wikitext a | b | c ``` ```html/phpa
| b | c``` ```html/parsoid
a
| b | c``` -------------------------------- ### Extend dummyanno Range to Nested Italic Tag Start Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/annotationParserTests.txt Demonstrates how a `dummyanno` tag starting at the beginning of a paragraph and ending inside an italicized section (``) extends its range to cover the entire italicized content, rather than the whole paragraph. Parsoid options include `wt2html`, `selser`, and `wt2wt` modes with annotations enabled. ```Wikitext
This should fail miserably ... let's fix it
``` -------------------------------- ### Get Full Page Name: {{FULLPAGENAME}} Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/magicWords.txt Demonstrates the {{FULLPAGENAME}} magic word, which returns the full name of the current page, including its namespace. This example uses a page title with special characters to show its unencoded output. ```Wikitext {{FULLPAGENAME}} ``` ```HTML/PHPUser:Ævar Arnfjörð Bjarmason
``` ```HTML/ParsoidUser:Ævar Arnfjörð Bjarmason
``` -------------------------------- ### Selser: Insert lists before dummyanno tags, ensuring correct newlines Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/annotationParserTests.txt This test checks the Selser's ability to insert a new list *before* `dummyanno` tags, ensuring that the wikitext output includes the appropriate number of newlines for list formatting. ```JSON { "modes": ["selser"], "changes": [ ["meta", "before", "Let's have some text.
``` -------------------------------- ### External Links: No Preceding Word Characters Allowed (T67278) Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/extLinks.txt This test case illustrates the rule that free external links are only recognized if they are preceded by non-word characters or start a new line. It shows examples where a URL is not linked if immediately preceded by letters or numbers, but is linked if preceded by punctuation. ```wikitext NOPEhttp://example.com N0http://example.com ok:http://example.com ok-http://example.com ``` -------------------------------- ### Parsoid Wikitext to HTML Conversion Test: Hello 2 Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/phpunit/Parsoid/ParserTests/data/testNoEndTag.txt This test case illustrates the conversion of the wikitext 'test 2' into its corresponding HTML output 'test 2
'. It provides another simple example of how Parsoid processes wikitext into HTML. ```wikitext test 2 ``` ```htmltest 2
``` -------------------------------- ### Selser: Insert content before and after dummyanno tags, preserving paragraphs Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/annotationParserTests.txt This test confirms that the Selser can insert new paragraph content both before and after `dummyanno` tags, maintaining proper paragraph structure and annotation integrity in the edited wikitext. ```JSON { "modes": ["selser"], "changes": [ ["meta", "before", "plop
"], ["meta", "after", "plop2
"] ] } ``` ```WikitextThis should fail miserably ... let's fix it
``` -------------------------------- ### Selser: Insert content before dummyanno tags, preserving paragraphs Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/annotationParserTests.txt This test verifies the Selser's ability to insert new paragraph content *before* `dummyanno` tags, ensuring the original annotation and surrounding paragraphs are correctly handled in the edited wikitext. ```JSON { "modes": ["selser"], "changes": [ ["meta", "before", "plop
"] ] } ``` ```Wikitextplop2
"] ] } ``` ```Wikitext` tag is involved. The test ensures that Parsoid automatically inserts start and end tags to create a valid HTML structure while preserving the content and annotation metadata.
```wikitext
hello
```
```html/parsoid
hello
a
b
``` -------------------------------- ### Selser: T295330 - DSR computation with dummyanno and category Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/annotationParserTests.txt This test case, related to task T295330, ensures that the DSR (Document Structure Representation) computation correctly handles `dummyanno` annotations and categories, allowing for proper Selser operations. It demonstrates the HTML output generated by Parsoid. ```JSON { "annotations": 1 } ``` ```WikitextThe quick brown fox jumps over the lazy dog.
``` -------------------------------- ### Selser: Insert headings after dummyanno tags, ensuring correct newlines Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/annotationParserTests.txt This test examines how the Selser handles the insertion of a new heading *after* `dummyanno` tags, specifically checking for the correct number of newlines to maintain proper wikitext formatting. ```JSON { "modes": ["selser"], "changes": [ ["meta", "after", "a | b | c``` -------------------------------- ### MediaWiki Wikitext Input for Template Continuity Test Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/annotationParserTests.txt The MediaWiki wikitext input demonstrating a template `{{1x|...}}` containing text, a table, and a `dummyanno` annotation. This wikitext is designed to test how annotations interact with transcluded table content. ```Wikitext {{1x|Some text!
| table |
| stuff |
http://www.example.com/?title=AT%26T
``` -------------------------------- ### Table with Empty Line After Start Tag Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/tables.txt Illustrates Parsoid's parsing of tables that include an empty line directly after the table start tag ({|) but before the first row definition. This tests whitespace handling at the table's beginning. ```wikitext {| |- |foo |} ``` ```html/*| foo |
baz y
``` ```HTML/Parsoidbaz y
Let's have some text.
``` -------------------------------- ### Table Test: Stray Table End Tags on Start Line Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/tables.txt Examines how Parsoid and PHP handle tables with stray `|}` (table end) tags on the same line as the table start tag (`{|`), and with or without additional attributes like `id`. This test covers multiple variations of this syntax. ```Wikitext {|style="color: red;"|} {|style ``` -------------------------------- ### RFC 2373 IPv6 Address Type URL Examples Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/extLinks.txt Illustrates different types of IPv6 addresses (unicast, multicast, loopback, unspecified, and IPv4-compatible) when used as literals in URLs, based on RFC 2373, section 2.2. These examples highlight the specific syntax for each address type. ```URL Syntax http://[1080::8:800:200C:417A]/unicast ``` ```URL Syntax http://[FF01::101]/multicast ``` ```URL Syntax http://[::1]/loopback ``` ```URL Syntax http://[::]/unspecified ``` ```URL Syntax http://[::13.1.68.3]/ipv4compat ``` ```URL Syntax http://[::FFFF:129.144.52.38]/ipv4compat ``` -------------------------------- ### Handling Ready Asynchronous Content with f6_async_return Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/pFragmentHandlerTests.txt This test demonstrates the `f6_async_return` parser function when the content is immediately available ('ready' case). It shows how the function processes the 'ready' state and outputs the specified content without any fallback. ```wikitext Content is ready: {{#f6_async_return:ready|Ready!}} ``` ```htmlContent is ready: Ready!
``` -------------------------------- ### T265737: 2. Relax section start requirements to reduce unnecessary conflicts between template and section boundaries Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/sectionWrappingParserTests.txt This test further explores section wrapping and template interactions, specifically when a section starts after a template that includes comments and page properties. It compares the HTML output from the PHP parser and Parsoid, with 'wrapSections' enabled. ```Wikitext = x = {{Foobar2}} y ``` ```HTML/PHP
baz y
``` ```HTML/Parsoidbaz y
Default fallback content:
Specified fallback content: My own fallback
``` -------------------------------- ### Get Talk Namespace Name: {{TALKSPACE}} in Main Namespace Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/magicWords.txt Illustrates the behavior of {{TALKSPACE}} when the current page is in the main (article) namespace. In this scenario, it returns 'Talk', which is the default talk namespace. ```Wikitext {{TALKSPACE}} ``` ```HTML/PHPTalk
``` ```HTML/ParsoidTalk
``` -------------------------------- ### Display ParserTests Command-Line Options Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/README.md Command to view the available command-line options and help information for the `parserTests.js` utility. ```Shell node bin/parserTests.js --help ``` -------------------------------- ### Simple Key-Value Return with f7_kv Parser Function Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/pFragmentHandlerTests.txt This test case verifies the basic functionality of the `f7_kv` parser function. It demonstrates its ability to process and return key-value pair arguments in a straightforward manner, showing the direct output of the function. ```wikitext {{#f7_kv:foo=bar|bat=baz}} ``` ```html(arguments)
``` -------------------------------- ### Run Parsoid Parser Tests Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/README.md Command to execute the `parserTests.js` script, which requires MediaWiki's `parserTests.txt` file. This script is used for running parser-specific tests. ```Shell node bin/parserTests.js ``` -------------------------------- ### MediaWiki Test Environment Configuration Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/pFragmentHandlerTests.txt Sets up the necessary MediaWiki environment for Parsoid tests, including global options, a simple template, and two articles (one with a redirect) to be used as test data. ```MediaWiki Options parsoid-compatible=wt2html version=2 ``` ```MediaWiki Template Template:1x !! text {{{1}}} ``` ```MediaWiki Article Foo !! text Define [[Foo]] to avoid a red link ``` ```MediaWiki Redirect FOO !! text #REDIRECT [[Foo]] ``` -------------------------------- ### Converting Multi-line Wikitext Table Captions to HTML Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/tables.txt This example demonstrates how multi-line captions in MediaWiki wikitext tables are rendered in HTML, preserving the line breaks within the caption element. ```wikitext {| |+line 1 of caption line 2 of caption |data |} ``` ```html| data |
| a
b||c |
User talk
``` ```HTML/ParsoidUser talk
``` -------------------------------- ### Timing Metrics for Language Conversion in Parsoid Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/docs/metrics.md Documents performance metrics for the language converter, including initialization times (general and variant-specific) and total conversion times. ```APIDOC Metric: langconv.init Description: Covers initialization time for the language converter. Location: LanguageConverter.php Metric: langconv.$HTMLVARIANT.init Description: Covers initialization time, split by HTML variants. Location: LanguageConverter.php Metric: langconv.total Description: Covers time to convert to the requested HTML variant. Location: LanguageConverter.php Metric: langconv.$HTMLVARIANT.total Description: Covers time to convert to the requested HTML variant, split by variants. Location: LanguageConverter.php Metric: langconv.totalWithInit Description: Includes both langconv.init and langconv.total. Location: LanguageConverter.php ``` -------------------------------- ### Parsoid HTML Output for Section Parsing Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/sectionWrappingParserTests.txt Displays the HTML structure generated by Parsoid for the wikitext examples. This output includes Parsoid-specific metadata attributes like `data-parsoid` and `data-mw-section-id`, which are used for round-tripping and semantic preservation. ```HTMLNot a section
Hello legacy
``` ```HTML/ParsoidHello parsoid
``` -------------------------------- ### Basic Wikitext to HTML Conversion Test (Parsoid) Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/phpunit/Parsoid/ParserTests/data/testsWithKnownFailures.txt This test case demonstrates the conversion of a simple 'Hello' wikitext input into HTML. It shows the output from both a legacy PHP rendering engine and the Parsoid service, highlighting potential differences in HTML structure and rendering. ```wikitext Hello ``` ```html/phpHello legacy
``` ```html/parsoidHello parsoid
``` -------------------------------- ### Get Encoded Talk Namespace Name: {{TALKSPACEE}} Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/magicWords.txt Shows the {{TALKSPACEE}} magic word, which returns the URL-encoded name of the talk namespace corresponding to the current page's namespace. For a 'User:' page, it returns 'User_talk'. ```Wikitext {{TALKSPACEE}} ``` ```HTML/PHPUser_talk
``` ```HTML/ParsoidUser_talk
``` -------------------------------- ### Wikitext Preformatting with Inline Content Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/indentPre.txt Demonstrates how preformatted text interacts with inline formatting. The example shows that inline formatting like italics (`''b''`) is correctly preserved and rendered within the `` block. ```wikitext a ''b'' ``` ```htmla b``` -------------------------------- ### MediaWiki Article: Main Page Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/tables.txt Defines the standard 'Main Page' article content assumed to exist for testing purposes. ```Wikitext blah blah ``` -------------------------------- ### CSS for Resetting MediaWiki Reference Back-link Counter Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tools/cite_css/generated.parsoid.cite.css.output.txt Defines the CSS rule to reset the 'mw-ref-linkback' counter for elements that serve as containers for reference back-links. This ensures that the numbering or lettering for back-links starts correctly. ```CSS span[ rel="mw:referencedBy" ] { counter-reset: mw-ref-linkback 0; } ``` -------------------------------- ### Resetting MediaWiki Reference Linkback Counter Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tools/cite_css/generated.parsoid.cite.css.output.txt This CSS rule initializes the 'mw-ref-linkback' counter to 0 for elements that serve as containers for referenced content. This ensures that reference numbering starts correctly within each context. ```CSS span[ rel="mw:referencedBy" ] { counter-reset: mw-ref-linkback 0; } ``` -------------------------------- ### Parsoid Test Configuration Options Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/definitionLists.txt Defines the parsoid-compatible modes and version for integrated parser tests, specifying how wikitext should be converted to HTML and back, and the version of the test suite. ```Configuration parsoid-compatible=wt2html,wt2wt version=2 ``` -------------------------------- ### Render Simple Video Element Source: https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/tests/parser/timedMediaHandlerParserTests.txt Demonstrates how a basic `[[File:Video.ogv]]` wikitext link is rendered into HTML by both MediaWiki's PHP parser and Parsoid, producing a standard HTML5 `