Page MenuHomePhabricator

VisualEditor manipulation based on TemplateData source code formatting does not handle newlines before and after correctly
Open, MediumPublic


Imagine following customized format: TemplateData specification:

"\n{{_\n| _ = _\n}}\n"

This is a typical block formatting as used for an info box with many parameters.


  • The tranclusion code will begin on a new line. If inserted after line break, this is fine, else insert line break before.
  • The terminating brackets will terminate the last tranclusion line. Wikitext will be continued on the next line.

This is taken from TemplateData Specification, section 3.7, which reads as:

  • If StartFormat begins with a newline and template is already at the start of a line (the character preceding this template invocation is a newline or the template is at the start of the output), delete the initial newline from the output string.
  • if EndFormat begins with a newline and the last character in the output string is a newline, then delete the last character in the output string. Append the EndFormat to the output string.

First strange thing is that on insertion at top of page an empty line is inserted by VisualEditor before transclusion. That is not what is intended by begin transclusion on a new line.

Second, the wikitext is expected like:

A sentence before.
{{Infobox foo
| title = ... 
| image = ... 
| location = ... 
A sentence following afterwards.

However, after manipulating such transclusion, it looks like

A sentence before.

{{Infobox foo
| title = ... 
| image = ... 
| location = ... 

A sentence following afterwards.

If transclusion is already beginning on a new line there is no need to insert an additional one, nor is it desired to insert an empty line when brackets already terminating the last line.

If heading and trailing \n are omitted in format: specification like

"{{_\n| _ = _\n}}"

insertion into the following text

A sentence before. A sentence following afterwards.

would result in:

A sentence before.{{Infobox foo
| title = ... 
| image = ... 
| location = ... 
}} A sentence following afterwards.

All that does not hold the expectations from specification.

If there is already a whitespace-only line before or after or at top of page, those shall be shrinked and no additional newline shall be inserted.

Event Timeline

ssastry triaged this task as Medium priority.Jul 27 2018, 11:56 AM

Change 448598 had a related patch set uploaded (by Subramanya Sastry; owner: Subramanya Sastry):
[mediawiki/services/parsoid@master] WIP: Follow templatedata spec correctly wrt leading newlines

Change 448598 merged by jenkins-bot:
[mediawiki/services/parsoid@master] Improve templatedata spec compliance wrt leading and trailing newlines

After deploying, I did some tests with Template:Taxobox, which has the format {{_\n| __________________ = _\n}}\n

As desired, a newline is no longer stripped at the beginning, so that,




remain as is after editing.

Also, two new lines as not forced if one is already present, so,


remains as is.

The only thing that doesn't seem as desired is,


which gets forced to,




There is another problem that the format \n{{_\n| __________ = _\n}}\n on a template located on the first line of page gives this:

2 {{Infobox example
3  | param1     = abc
4  | param2     = 123
5  | otherparam = xyz
6 }}

Instead of:

1 {{Infobox example
2  | param1     = abc
3  | param2     = 123
4  | otherparam = xyz
5 }}

An unwanted blank line is added to the first line of page before the template.

Example on friwiki with the inline template {{Cord}} (the newline before the template has since been removed from the TemplateData format because of this problem).

The case of a template located on the first line does not seem to be handled correctly.

Thank you.

(sorry for my bad English)

Looks like the implementation is missing the "or the template is at the start of the output" clause from the spec.

Restricted Application added a subscriber: Liuxinyu970226. · View Herald Transcript