(source) C. Scott Ananian: Ideas/A Dozen Visions for Wikitext/Long arguments

Long arguments

Long arguments

Let's look at an example from a Wikimania 2015 talk, "Future of structured documents: VisualEditor, Citations and Wikidata, oh my!", which shows a reference in the article Nahuatl. This is a template to create a citation region using Wikidata: this region of the text is supposed to be supported by reference 32412 stored with WikiCite. Here's the syntax:

{{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)
}}

But this doesn’t work: instead of displaying its first argument it displays nothing! why?

It’s these equal signs here:

Problematic characters
{{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)

}}

It turns out that there are a number of “special” characters you can’t naively include in a template argument, and equals sign is one of them. Everything here to the left of the first equal sign is treated as the name of the first argument, and thus there is in fact no argument “1” defined here.[1]

There are a number of such “gotchas” when trying to pass arguments to templates or parser functions.  I gave a talk at Wikimania 2015 (updated in 2024) going through a lot of them.  Long argument syntax is an effort to provide a “quote” syntax to make it easier to pass arguments without having to “properly escape” them, if you can figure out what “properly escape” means.

Here’s what it looks like, just triple angle brackets on either side of the argument:

Now With long arguments
{{Largethumb|
Foo.jpg|
caption}}
{{Largethumb|Foo.jpg|<<<
caption
>>>}}

Here’s an example that is difficult or confusing to write currently:

Now With long arguments
{{tablestart}}

| Hello || world
{{tableend}}

{{Table|<<<

| Hello || world
>>>}}

The workaround to date has been to have two separate “start” and “end” templates (tablestart and tableend here), in order to avoid the need to figure out how to properly escape the body.  But those two templates aren’t balanced (remember {{#balance}}?) and make it slower to reparse, hard to edit this table using VisualEditor, etc.  But with long arguments we can easily create a balanced “table” template and put the table cells in the argument.

Like extension tag syntax, long arguments allow anything to be passed except the magic >>> close sequence.  But if you need to pass that particular character, for example to nest quoted arguments, you can do that as well using the same mechanism we introduced for extension tag fragments.

Extension tag fragments Long arguments fragments
<ref>

Blah blah
<ref#inner>
Inner!
</ref#inner>
</ref>

{{#tag:ref|<<<

Blah blah
{{#tag:ref|<<<#inner
Inner!
>>>#inner}}
>>>}}

At the risk of inconsistency with extension tag fragments, we might consider flipping this and making nesting of <<< >>> work by default, which would reserve fragments for the case where we explicitly want to pass an unbalanced <<< or >>>:

Long argument with embedded angle bracket sequence
{{#tag:ref|<<<#outer

I want to talk about <<< sequences.

>>>#outer}}

The goal is not to invent special escape syntax but instead to interpret characters literally and just allow changing the delimiters if necessary.[2]

Going back to our first example, it makes it easy to pass arbitrary content to our citation template, without having to watch our for equals signs and other bad characters:

Citation region with long argument
{{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)

>>>}}

Next section: Variable-length/structured arguments

  1. A listener asked if the vertical bar characters here were also a problem, but the preprocessor actually handles vertical bars nested inside curly braces "correctly" in this case.
  2. See also the discussion in phab:T402087#11091733 about prefix-stripping at the start of each quoted line, which would allow indenting the argument for readability.
C. Scott Ananian [[User:cscott]]