Closing a block-level element that contains a list at the end of the last list item generates invalid HTML
Closed, InvalidPublic

Description

On wikis without HTML Tidy installed/activated, when a div containing a list has the div's closing tag placed at the end of the last item in the list, the parser puts the </div> before the </[li|dt|dd]></[ul|ol|dl]> tags. For instance, the following markup:

<div>

  • This
  • is
  • a
  • list.</div>

results in the following HTML:

<div>
<ul><li> This
</li><li> is
</li><li> a
</li><li> list.</div>
</li></ul>

By comparison, closing the div on the line following the last list item results in valid markup being generated:

<div>

  • This
  • is
  • a
  • list.

</div>

results in:

<div>
<ul><li> This
</li><li> is
</li><li> a
</li><li> list.
</li></ul>
</div>

This is a problem e.g. on hlists in navboxes, where the list of links can easily be longer than the navbox is wide. In this case, it seems to prevent the list from wrapping, instead forcing the navbox to stretch to the length of the entire list.


Version: unspecified
Severity: normal
URL: http://yugioh.wikia.com/wiki/User:Dinoguy1000/sandbox?oldid=2041434
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=1581

bzimport added a project: MediaWiki-Parser.Via ConduitNov 22 2014, 12:58 AM
bzimport added a subscriber: Unknown Object (MLST).
bzimport set Reference to bz39066.
Dinoguy1000 created this task.Via LegacyAug 6 2012, 3:09 AM
Dinoguy1000 added a comment.Via ConduitAug 6 2012, 9:18 PM

In the specific case of navboxes, the closing markup for the list item (and the list overall) ends up following the markup generated to close the containing table cell and row and open the following row/cell. If the cell containing the list is the last one in the table, the closing list markup instead follows the closing table markup.

An example can be seen at http://yugioh.wikia.com/wiki/User:Dinoguy1000/sandbox?oldid=2041433

Dinoguy1000 added a comment.Via ConduitAug 6 2012, 9:26 PM

Per http://yugioh.wikia.com/wiki/User:Dinoguy1000/sandbox?oldid=2041434 this seems to be caused by any block-level element, not just divs.

Edokter added a comment.Via ConduitSep 16 2012, 9:02 AM

Probably related: Bug 40274 and Bug 39617.

Anomie added a comment.Via ConduitApr 9 2013, 4:02 PM

Why are you trying to close the block element inside the list item? When you give the parser poorly-formatted wikitext, don't be surprised when it gives you back invalid HTML.

I'm inclined to close this as INVALID.

Dinoguy1000 added a comment.Via ConduitApr 9 2013, 4:51 PM

It would be INVALID (maybe) if this bug were about closing the containing block-level element on any of the list items other than the last one. It is not, though; this bug pertains specifically to closing the block-level element at the end of the *last* list item, which should by all accounts result in valid markup. The fact that it doesn't is counter-intuitive and breaks several Wikipedia templates when imported to wikis without HTML Tidy enabled. While that could potentially be fixed by correcting the offending templates (and that's assuming they *can* be fixed; there's no guarantee it would be possible without a major overhaul in some cases), it is by no means reasonable to expect reusers to realize there's a problem, identify the cause, and either fix their local copy or (preferably) request a fix on Wikipedia's copy.

Anomie added a comment.Via ConduitApr 9 2013, 5:37 PM

What's special about the last one that you should be able to close outer block elements inside it? And what "accounts" tell you it should result in valid markup?

Consider what happens when you have a template containing your example, and then you start another list right after it:

{{comment1}}

  • Foo
  • Bar

Expands to

<div>

  • This
  • is
  • a
  • list.</div>
  • Foo
  • Bar

Suddenly your "last element" isn't the last element anymore. And this confuses Tidy too; see [[Template talk:Shortcut#Changing wiki-markup to pure HTML in lists]] on enwiki, for example.

Dinoguy1000 added a comment.Via ConduitApr 9 2013, 5:53 PM

What's special about the last one that you should be able to close outer block

elements inside it?
Nothing, actually, beyond that it's the last list item. Really, the ideal solution would be for the parser to end the list when it encounters the closing outer block element, and simply start a new list for any following list elements; this is certainly a better option than simply outputting broken markup (especially since the current solution requires breaking the list into two separate lists anyways).

Edokter added a comment.Via ConduitSep 1 2013, 10:24 AM

A wiki list item should always be contained within its own line.

If for whatever reason other element tags are contained within that (last) line, it is invalid wiki markup. The template example does not produce the error you expect, because a template with a list usually terminates with a linebreak (otherwise, the template is badly coded).

There is only so much invalid wiki markup the parser can fix, so this is unlikely to be addressed. Closing as INVALID.

Add Comment