Page MenuHomePhabricator

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

Description

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.

Expectations:

  • 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

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJul 17 2018, 11:45 PM
ssastry triaged this task as Normal 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

https://gerrit.wikimedia.org/r/448598

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

https://gerrit.wikimedia.org/r/448598

Arlolra added a subscriber: Arlolra.Aug 6 2018, 9:34 PM

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,

Testing{{...

and

Testing
{{...

remain as is after editing.

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

...}}
Testing

remains as is.

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

...}}Testing

which gets forced to,

...}}

Testing

Hello,

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

1 
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)

cscott added a subscriber: cscott.Mar 7 2019, 3:18 PM

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 project: VisualEditor. · View Herald TranscriptMar 12 2019, 3:21 PM
Restricted Application added a subscriber: Liuxinyu970226. · View Herald Transcript
Restricted Application added a project: VisualEditor. · View Herald TranscriptMar 12 2019, 3:21 PM