What is paradigm of making list tight or loose?

Could anyone explain paradigm of making list tight or loose? Current spec describes cases, but i can’t understand full coverage.

For example, <hr> + text does not wrap text to paragraph and does not make list item loose. Why?

example

After reading in spec, that looseness must propagate to all list items, i thinked that it’s done for CSS styling consistensy. But then i don’t understand why pure text allowed after display:block elements. Seems wrapping rule is not CSS-related.

Does anyone know exactly, what is in background of spec for loose lists? I need to understand it for making correct fix in my parser. Wish to avoid hardcoding by node names, because that will not cover possible extensions.

The spec says:

A list is loose if it any of its constituent list items are separated by blank lines, or if any of its constituent list items directly contain two block-level elements with a blank line between them. Otherwise a list is tight.

So while your example is consistent with the spec, this one isn’t, right?

1 Like

Your example is beter in terms “how to break spec” :slight_smile: . My example depends on interpreting term “block”.

I think, spec means, that “block” = block container element. But i don’t understand why that should correlate with real world. IMHO, it’s better to interpred term “block” in CSS manner, as “element with display: block”. I this case HR will require wrapping next text to paragraph too.

Probably, @jgm did it, having in mind another output formats (doc, pdf, …). But spec refer to HTML only, and current rule looks strange for HTML. It’s not a good practice to place unwrapped inline element (text) near block elements.

The spec explains block and inlines a bit and also mentions that blocks can be either container blocks or leaf blocks (just looking at the TOC of the spec is quite instructive as well).

Regarding lists, I tend to agree. The spec would be more intuitive if it were changed to:

A list is loose if it any of its constituent list items are separated by blank lines, or if any of its constituent list items contains a block-level element. Otherwise a list is tight.

Though I guess, it currently approximates existing implementations closer.

May be. Do you agree that in current state in can conflict with “best practices” of HTML markup? That’s the reason why i created this topic.

There is also a question, if item looseness should be propagated to all list items. But that’s not as critical as leaving unwrapped text near block-displayed sibblings.

+++ Mb21 [Nov 10 14 14:46 ]:

A list is loose if it any of its constituent list items are separated by blank lines, or if any of its constituent list items contains a block-level element. Otherwise a list is tight.

But a list itself is a block-level element. So this rule would make any list containing a sublist into a loose list. Surely we want to preserve the ability to have tight lists with sublists.

+++ Mb21 [Nov 10 14 09:43 ]:

The spec says:

A list is loose if it any of its constituent list items are separated by blank lines, or if any of its constituent list items directly contain two block-level elements with a blank line between them. Otherwise a list is tight.

So while your example is consistent with the spec, this one isn’t, right?

This should be reported on the bug tracker, since it is inconsistent with the spec.

We can trigger looseness only if list item contains text child. Also we can disable looseness propagation from one leaf to all list items.

That will solve case of nested lists and will be consistent with good HTML markup.

While valid markup, I’ve always found it strange to have text-nodes in XML/HTML that aren’t wrapped in tags but kind of float around:

<ul>
  <li>
    <h1>header</h1>
    this should be a paragraph, because it is.
  <li>
</ul>

I actually think it’s a good thing that ‘tight/loose’ propagates to all list items. If one of the list items is a paragraph, for consistency’s sake all of them should be.

Good point, so maybe it should be:

A list is loose if it any of its constituent list items are separated by blank lines, or if any of its constituent list items contains some block-level element other than a nested list. Otherwise a list is tight.

P.S. I filed an issue.