Page MenuHomePhabricator

Wikitext Parser Bug when using template inside list
Closed, DuplicatePublic

Description

When using (1) a template that (2) has HTML (the allowed subset) (3) with nested elements (4) in lists then we have a problem. In plain wikitext the template usually works fine. But once the template is as a list item, it not only does not work but it is "ripped apart", meaning the inner elements are rendered not inside but AFTER their parents. This seems to happen due to mediawikis template parser and might be considered a bug.

-- TemplateTest
<span class="parent">
<span class="child">
Text
</span>
</span>

Is fine as usual wikitext, but leads to the buggy behavior if the template is deployed as a list item

-- Page
{{TemplateTest}} -- that's fine
* {{TemplateTest}} - span.child is rendered AFTER and NOT inside span.parent

Event Timeline

You can try to put the wikitext of the template into one line.

The wikitext after expand of template would be:

-- Page
<span class="parent"><span class="child">Text</span></span>
* <span class="parent"><span class="child">Text</span></span>

instead of

-- Page
<span class="parent">
<span class="child">
Text
</span>
</span>
* <span class="parent">
<span class="child">
Text
</span>
</span>

The wikitext parser does not preserve the semantic of html tags your template describes. It does not interpret html tags, so a newline can break it.

We tried writing everything into 1 line as you suggested but that didn't help. Rather it showed that the bug is even worse. We used:

TemplateTest:

<span class="parent"><span class="child">{{{1}}}</span></span>

Page:

{{TestTemplate|abc

def}}

This is rendered to:

<p><span class="parent"><span class="child">abc
</span></span></p>
<p>def </p>

This seems like an unpredictable and illogical behavior. Why would the semantic be ripped apart in a template wikitext while it stays intact and valid in non-template wikitext?

Also the requirement to write everything into 1 line seems like a bad solution since then the wiki markup is very difficult to read. Could this be considered a bug?

The wikitext parser does not preserve the semantic of html tags your template describes.

Or in other words, can we add this as a feature request please?

The {{{1}}} is replaced with the wikitext and

* <span class="parent"><span class="child">abc

def</span></span>

is also not working and rendered the same as with template. So the problem maybe is not the template, it is how the * is parsed. And * is parsed and define as one-line statement and does not preserve newlines.

Alternatives:

* <span class="parent"><span class="child">abc<br />def</span></span>
<ul><li><span class="parent"><span class="child">abc

def</span></span></li></ul>

Or in other words: The end-token/delimiter of * is the newline (\n). Together with templates or with html tags this could be problematic.

The benefit of the current behaviour is that the parser acts the same if the template is transcluded ({{template}}) or substituted ({{subst:template}}).

This task can stay open as feature request. My comment was to provide some workaround and try to explain the current behaviour, not saying it shouldnot or cannot implemented. Needs to find a way to not break compatibility with old wikitext.

Umherirrender, thank you. Your analysis seems spot on! We would also just for clarity add an even simpler example we found.

TemplateTest:

<span>{{{1}}}</span>

Page1:

* {{TemplateTest|abc

def}}

Page2:

* <span>abc

def</span>

Both Pages render to:

<ul>
  <li>
    <span>abc</span>
  </li>
</ul>
<p>def </p>

which we would say is unexpected and confusing behavior.