//(This proposal was originally called "hygenic arguments"; easily confusable with a mostly-unrelated hygenic **templates** proposal. The latter are now ["balanced" templates](https://phabricator.wikimedia.org/T114445) and we're now calling this proposal "heredoc arguments".)//
As described in my [Wikimania 2015 talk](https://wikimania2015.wikimedia.org/wiki/Submissions/Templates_are_dead!_Long_live_templates!) ([starting at slide 31](https://wikimania2015.wikimedia.org/w/index.php?title=File:Templates_are_dead!_Long_live_templates!.pdf&page=31)), the existing template argument syntax offers a number of traps for the unwary (for example, with the characters `=`, `|`, etc). As a result, it is difficult to easily move large blocks of text into templates.
As a result, we often have constructs such as:
```
{{tablestart|class="shiny"}}
| Hello || wiki = world
{{tableend}}
```
which pose a number of issues:
# There is no mechanism to ensure `{{tablestart}}` and `{{tableend}}` are properly matched
# Both `{{tablestart}}` and `{{tableend}}` emit unbalanced HTML, which complicates work on efficiently updating the parser cache after template changes.
# Due to the tag matching issues, this whole block is uneditable by Visual Editor.
If we were to try to write a `{{table}}` template which accepted the contents as an argument, it would have to look like:
```
{{table|class="shiny"|
{{!}} Hello {{!}}{{!}} wiki = world
}}
```
Our arguments needed to be transformed in two different ways to prevent `|` and `=` from being mangled when we shoehorned them into a template argument. (You could also use `{{=}}`... but not `{{|}}`.)
This would also create dirty diffs inside the argument if all you wanted to do was wrap existing wikitext into a template parameter.
Consider also:
```
{{sectionstart}}
==heading==
{{sectionend}}
```
You can't just use `<nowiki>=</nowiki>` around `=` characters, if you want that to work.
**Heredoc arguments** provide a new form of template invocation which avoids these issues.
The above examples would be written as:
```
{{table|class="shiny"|<<<
| Hello || wiki = world
>>>}}
{{section|<<<
==heading==
>>>}}
```
Named arguments (like `class` in this example) can be passed using `name=<<<...>>>`. The new `Template:Table` can now emit properly balanced HTML, with both `<table>` and `</table>` generated by the same template (instead of by two separate templates). Visual Editor can now edit this block as a single template invocation, invoking itself recursively to edit the template arguments as it does now.
The only special character in the argument when expressed this way is `>>>`. We'll support nesting `<<<....>>>`, since that's the common case where `>>>` would appear, and you could also use `<nowiki>>>></nowiki>`. However, we'll also provide a "tag" mechanism to ensure that *any* wikitext can be wrapped into a template argument with *zero dirty diffs inside the template argument*:
```
{{{wrapper|arg=123<<<
This test can contain >>> it's fine!
>>>123}}}
```
The tag before the `<<<` can be any number. (WLOG it could be an alphanumeric tag, but latin alphabetic characters can play havoc in RTL contexts; if we restrict to numeric tags we are guaranteed that RTL will look good.) It is always possible to choose a number `N` such that `>>>N` never appears in the argument (for example, N could have more digits than the argument has characters), which means it is always possible to wrap arbitrary wikitext without making any internal changes to the wikitext.
There are no special characters or odd escape rules in the argument when expressed this way. We don't need special `{{!}}`, `{{=}}`, etc escapes; we won't have dirty diffs or require careful search-and-replace when wrapping wikitext.
Another example, from @brion's talk on [citations](https://wikimania2015.wikimedia.org/wiki/Submissions/Future_of_structured_documents:_VisualEditor,_Citations_and_Wikidata,_oh_my!):
```
{{cite|id=“32412”|<<<
First person plural pronouns in Isthmus-Mecayapan Nahuat:
:''nejamēn'' ({{IPA|[nehameːn]}}) "We, but not you" (= me & them)
:''tejamēn'' ({{IPA|[tehameːn]}}) "We along with you" (= me & you & them)
>>>}}
```
Note that it was easy to surround the entire text covered by the citation into the `{{cite}}` template, since I didn't need to worry about the fact that the text included the special character `=`.
**Visual Editor use**
When escaping template parameters, Visual Editor would wrap the parameter with `<<<...>>>` if the input wikitext contained `|` or `=` (instead of encoding `|` as `{{!}}`, etc). If the parameter also contained `>>>`, it would generate `N<<<...>>>N`, picking some `N` such that `>>>N` doesn't appear in the input. That would ensure clean diffs when the only change was wrapping existing wikitext into a template.
We might also need to eventually add a flag to the data maintained by `Extension:TemplateData` to indicate that a given parameter should always be escaped with `<<<`, if that becomes the editors' preference for certain parameters.
**More general use**
In the initial implementation, `<<<` will be recognized as a quote character only for template arguments; that is, only immediately after `=` or `|` inside double braces. We could eventually allow `<<<` as a general mechanism, for example:
```
* a <<<
multi
line
>>> list item
```
We'll treat that as a separate task iff it proves interesting.
**Strict start-of-line constraints**
For ease of parsing (and reading) we can enforce start-of-line context on the result to avoid the T14974/T2529 hacks and make behavior consistent. There might be other restrictions that would prove useful. (More thought welcome here.)
Mailing list discussion: https://lists.wikimedia.org/pipermail/wikitech-l/2015-October/083448.html
//Note: task description has been edited per parsing team meeting notes [[https://phabricator.wikimedia.org/T114432#1726161|below]]; the original syntax proposal was {{>Foo}}...{{<Foo}}//
// Note: task description further edited to adopt @Alsee's syntax proposal [below](https://phabricator.wikimedia.org/T114432#3096863), with a few tweaks.