Specs/wikitext/1.0.0

From mediawiki.org

MediaWiki's Wikitext flavor is primarily defined by its implementations in MediaWiki itself and Parsoid. These entry points should be helpful:

Changes to whitespace behavior as of RFC T157418[edit]

Leading and trailing whitespace is trimmed in table cells, table headings, table captions, list items (ordered, unordered, definition), section headers that are generated by native wikitext markup. Whitespace in HTML tags is left untouched.

Examples:

Table demonstrating the change in whitespace behavior
Wikitext Rendered HTML
*  a

#  b
<ul><li>a</li></ul>

<ol><li>b</li></ol>
<ul><li>  a  </li></ul>
<ol><li>  b  </li></ol>
<ul><li>  a  </li></ul>
<ol><li>  b  </li></ol>
;  Term :  definition
<dl><dt>Term</dt><dd>definition</dd></dl>
==   Section heading ==
<h2>Section heading</h2>
<h2>   Section heading  </h2>
<h2>   Section heading  </h2>
{|
|+   Caption 
|-
!  Heading 1 !!  Heading 2
|-
|  Cell 1  || Cell 2 
|}
<table>
<caption>Caption</caption>
<tr><th>Heading 1</th><th>Heading 2</th></tr>
<tr><td>Cell 1</td><td>Cell 2</td></tr>
</table>
<table>
<caption>  Caption  </caption>
<tr><th> Heading 1 </th><th>  Heading 2    </th>
<tr><td>   Cell 1 </td><td>   Cell 2 </td>
</table>
<table>
<caption>  Caption  </caption>
<tr><th> Heading 1 </th><th>  Heading 2    </th>
<tr><td>   Cell 1 </td><td>   Cell 2 </td>
</table>

Historical context[edit]

Till June 2018, HTML4-Tidy was being used to clean up the HTML generated by the PHP parser. Among other things, Tidy also did a whitespace cleanup of HTML. So, it removed leading and trailing whitespace from all HTML tags. So, wikis effectively came to rely upon this behavior as if it was part of the wikitext spec itself.

With the introduction of RemexHtml to replace Tidy, this changed because RemexHtml doesn't trim whitespace since whitespace is meaningful for rendering in HTML5 because of CSS properties like white-space: nowrap. However, since wikis relied on this whitespace trimming behavior (ironically because if untrimmed, the white-space would be rendered because of CSS properties that affected it), we chose to formally make this whitespace trimming behavior part of the official wikitext spec. But, we deliberately chose to not touch native HTML tags because it would lead to unintuitive and gratuitous differences from the HTML5 spec and HTML used elsewhere on the web.