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

{{#balance}}

{{#balance}}

Here’s a short fragment of wikitext.  Is “bar” going to be in boldface, or not?

''' foo {{tpl}} bar ''' baz

This is a trick question! The answer depends on the contents of the template tpl:

Yes it will be bold if {{tpl}} expands to a or '''a''' or <b>
No it will not be bold if {{tpl}} expands to '''a or '''''a'' or </b>

We can address this unpredictability with a mechanism called “balance”.  Broadly, it ensures that any contexts opened in a fragment are closed at the end of the fragment.   In addition to providing more predictable behavior for editors and ensure that the dreaded “boldface spilling out all over the rest of the article” bug doesn’t occur, it also enables some key performance updates by allowing incremental update of parsed content.  And of course, it ensures good behavior of a large number of wikitext features, not just boldface. To get technical, {{#balance}} enables a principled and strongly-typed composition semantics for wikitext.

Returning to our example:

''' foo {{tpl}} bar ''' baz

If the template tpl opts-in to balance, we can be assured that bar will always be bolded; nothing will “leak out” of tpl into the outer context.

Next section: Long arguments

C. Scott Ananian [[User:cscott]]