Help:Extension:Linter/html5-misnesting

From MediaWiki.org
Jump to navigation Jump to search

Input Wikitext[edit]

<span>a

b</span>

Tidy output[edit]

Tidy cleans up the PHP parser output to generate

<p><span>a</span></p>
<p><span>b</span></p>

HTML5 output (ex: Parsoid, RemexHTML)[edit]

But, a HTML5 based tool cleans up the PHP parser output differently to generate

<p><span>a</span></p>
<p>b</p>

Recommended fix[edit]

Change the wikitext to:

<span>a</span>

<span>b</span>

Other tips[edit]

One of the main ways this affects wiki pages is when a span (or any other tag in the list of affected tags below) is used to wrap a list. Because of the interactions between a bug in the PHP parser (which is hard to fix and is the reason for the pwrap-bug-workaround linter category -- Parsoid does not have this bug) and the HTML5 parsing spec, when Tidy is removed, these wrappers will no longer apply to the list.

When a <span> tag is used to wrap a list, use a <div> tag instead. It is the correct way to do it since a list is a block structure and <div> is more appropriate instead of <span> which makes more sense in inline text contexts. This is the recommended fix. See this edit on the italian wikipedia for an example.

But, where appropriate, consider fixes like those in the table below.

Use case Alternative markup or suggested fix
<span> tag used for formatting (font-size, underline, etc.) Use the appropriate formatting tag (ex: <small> tag if reducing font-size Example from metawiki )
<del> tag wrapping a list to strike through elements of a list
  • Option 1: Use a <s> tag instead
  • Option 2: Wrap every individual item with a <del> tag
<span> tag with empty styles Get rid of the span tag
<span> tag wrapping block tags in all cases Use a <div> tag instead

Pay special attention to <sub>, <sup>[edit]

On pages with mathematical formulae, misnesting of a sub or sup tag might subtly change the meaning of the formula. It is important to fix these cases. See this example from enwiki.

Affected tags[edit]

The following tags are affected.

ABBR, BDI, BDO, CITE, DATA, DEL, DFN, INS, KBD, MARK,
Q, RB, RP, RT, RTC, RUBY, SAMP, SPAN, SUB, SUP, TIME, VAR

See more[edit]