Page MenuHomePhabricator

extraneous newlines caused by templates
Open, Needs TriagePublic

Description

Steps to replicate the issue (include links if applicable):

  1. Create a template.
  2. Add a newline before <noinclude> keyword.
  3. Include the template on a wiki page.

What happens?:

Extraneous newline. (Paragrah <p>)

What should have happened instead?

No extraneous newline.

Software version (skip for WMF-hosted wikis like Wikipedia):

1.38.2 but this is very most likely version independent.

Example:

For example, view the source on https://en.wikipedia.org/wiki/Template:Ambox

Currently:

{{#invoke:Message box|ambox}}{{#ifeq:{{{small}}};{{NAMESPACENUMBER}}|left;0|[[Category:Articles using small message boxes]]}}<noinclude>
{{documentation}}
<!-- Categories go on the /doc subpage, and interwikis go on Wikidata. -->
</noinclude>

After line {{#invoke:Message box|ambox}}{{#ifeq:{{{small}}};{{NAMESPACENUMBER}}|left;0|[[Category:Articles using small message boxes]]}} why isn't there a newline before <noinclude>? Because that would result in a extraneous newline.

Suggestion:

It would be a lot nicer if it could be written like the following but still not resulting on an extraneous newline on the wiki page that uses the template.

{{#invoke:Message box|ambox}}{{#ifeq:{{{small}}};{{NAMESPACENUMBER}}|left;0|[[Category:Articles using small message boxes]]}}
<noinclude>
{{documentation}}
<!-- Categories go on the /doc subpage, and interwikis go on Wikidata. -->
</noinclude>

That would look nicer but causes an extraneous newline in the mediawiki markup only. Of course, there should be no extraneous newline on the wiki page that visitors are actually reading.

Alternatives that I tested but also didn't work:

<noinclude>
[[Category:Test]]
</noinclude>
<onlyinclude>
test content in template
</onlyinclude>

It didn't work in a sense that even this produced extraneous newlines.

Why should there be a new line in the source?

Because that's closer to how any well written source code is written. New keywords are written in a new line in comparable cases. Whenever sensible, long lines are avoided and a newline is uses.

Why should there be a new line in the source but not in the wiki page that is using the template?

Because adding the <noinclude> keyword in a new line is just a very popular convention in other script and programming languages. The intent of the newline in the wiki source is just a logical separation for better readability. It is however not intended as a request to add an actual newline to the wiki page which uses the template.

What this is not:

This is not a bug report for Template:Ambox. This is a general issue on how the parser interprets newlines.

The same in other words:

Other people were running in this issue before me. Perhaps the way they explain it is better than may style of explaining it.

Alternative Implementation #1:

The MediaWiki editor for templates could be split into two different edit sections for include and noinclude.

Alternative Implementation #2:

If above Alternative Implementation #1 is considered to heavyweight and unrealistic to ever migrate too, here's a more migration friendly proposal. To avoid breaking too many wiki templates during migration, the current templates could be considered "wiki template version 1". With a new MediaWiki magic word __TEMPLATEV2__ (or better name or some tag), the parser could have an updated behavior. Example:

__TEMPLATEV2__
<noinclude>
[[Category:Test]]
</noinclude>
<onlyinclude>
test content in template
</onlyinclude>

The newline after <noinclude> (i.e. the "\n" in <noinclude>\n should not result in a newline in the resulting html.

How could one add an extraneous newline if they wanted so? By writing:

<onlyinclude>
test content in template

</onlyinclude>

Or alternatively by using <br />.

This makes probably most sense if there are any other parser or template breaking changes being considered.

Alternative Implementation #3:

A different magic word __NEWLINEALTSTYLE__ (could probably really use a better name) could change the behavior of the parser.

<noinclude>
__NEWLINEALTSTYLE__
[[Category:Test]]
</noinclude>
<onlyinclude>
test content in template
</onlyinclude>

As soon as the __NEWLINEALTSTYLE__ magic word is used the "\n" in <noinclude>\n should not result in a newline in the resulting html.