Jump to content
MediaWiki

Help:Lint errors/pre-expansion

From mediawiki.org

Preamble

[edit ]

This lint identifies wikitext patterns where a template call is being expanded inside a <pre> extension call.

This lint category has been temporarily enabled to identify pages that use Template:Pre in some specific ways and might be broken by Parsoid. This lint will be removed around Oct 1, 2026 since this will no longer be useful after the pages are fixed or once Parsoid has been around for longer than 3 months on these wikis.

Background

[edit ]

On some wikis, the Template:Pre (ex: en:Template:Pre) contained a hack to bypass extension tag handling in MediaWiki's legacy parser. Specifically, the template used <pre<includeonly></includeonly>>''bar''</pre<includeonly></includeonly>> to force the contents to be treated as wikitext (for this example, the content is rendered as <i>bar</i>) instead of as plaintext as in this example <pre>''bar''</pre> (where the content is rendered as ''bar'').

Parsoid, however, does not support this hack. To support this use case, first-class support was added to the pre extension tag to interpret the contents as wikitext, using the format="wikitext" attribute and value.

Wikitext HTML output
<pre>''hi''</pre>
<pre>''hi''</pre>
<preformat="wikitext">''hi''</pre>
<pre><i>hi</i></pre>

What is this lint detecting?

[edit ]

Unlike the simple example above, there are wikitext uses where the simple switch to format="wikitext" doesn't work. This is almost always the case where a template is used in the argument to {{Pre|...}}

Wikitext HTML output
{{Pre|{{((}}1x{{!}}100{{))}}}}
<!-- 
where Template:Pre used to look like
<pre<includeonly></includeonly>>{{{1}}}</pre<includeonly></includeonly>>
which only the legacy parser supported
-->
<pre>{{1x|100}}</pre>
{{Pre|{{((}}1x{{!}}100{{))}}}}
<!-- 
where Template:Pre now looks like
{{#tag:pre|{{{1}}}|format="wikitext"}}
-->
<pre>100</pre>

We had to use the {{#tag:pre|...}} form so that Parsoid can expand {{{1}}} properly. But, as the HTML output shows, Parsoid also expanded the template call that was meant to be escaped. To avoid this, editors should switch from using {{((}} to escape template syntax to <nowiki>{{</nowiki>. So, the input wikitext should be changed to {{Pre|<nowiki>{{1x|100}}</nowiki>}} .

For an example of a replacement, see this edit (Caveat: For this particular case, an editor found a simpler solution with this edit, but that simplification might not be applicable always).

This lint is intended to only identify patterns like this where Parsoid expands a template inside <pre format="wikitext"> now where the editor didn't intend it to be expanded (by using the older hack). However, it isn't possible to detect editor intent in Parsoid which means there will be false positives where no fix is actually needed.

Detecting false positives

[edit ]

Currently, there are two false positive scenarios:

  • Parsoid renders the output correctly but flags the lint incorrectly (this will be fixed soon).
  • You may actually want the template expanded and not actually escape the template call, and so the lint is flagging a fix that would be incorrect to apply. For example, you want <pre format="wikitext">{{1x|100}}</pre> to be rendered as <pre>100</pre> and so even though the lint identifies this pattern, you don't need to fix anything.

AltStyle によって変換されたページ (->オリジナル) /