Parser 2011/Stage 3: Expansion

From mediawiki.org

Parser functions[edit]

Template expansion[edit]

very prelim :D

The page:

{{Hello|greet=Alice}}
[
  {
    type: 'template',
    name: 'Hello',
    params: {
      'greet': "Alice"
    }
  }
]

The Template:Hello page:


Howdy {{{greet|stranger}}}!
[
  'Howdy ',
  {
    type: 'param',
    name: 'greet',
    default: 'stranger'
  },
  '!'
]

Now we can expand the lot into something like:

[
  {
    type: 'expanded-template',
    name: 'Hello',
    params: {
      'greet': 'Alice'
    }
    content: [
      'Howdy ',
      {
        type: 'expanded-param'
        'content': [
          'Alice',
        ],
      },
      '!'
    ]
  }
]

(Or should the content nodes just include a reference to the template param? or?)

Rendering attachment[edit]

It's not uncommon to have structures in wikitext, especially when templates are involved, where separate 'start' and 'end' points cross some hierarchical lines. For instance:

{{start-fancy-table}}
{{a-table-row|some stuff}}
{{a-table-row|other stuff}}
|-
|extra stuff
|manually added
{{end-fancy-table}}

This gives us a structure something like:

template: start-fancy-table
  table
  tr, th, /th, th, /th, /tr
template: a-table-row
  tr, td, /td, td, /td, /tr
template: a-table-row
  tr, td, /td, td, /td, /tr
tr, td, td
template: end-fancy-table
  tr, td, /td, td, /td, /tr
  /table

Depending on the actual template structure, the various bits may all appear on different 'levels'. HTML would generally whinge at this sort of structure directly translated. :)

When rendering this to output or showing an editor, it's necessary to go through the output and pair up matching open/close pairs for these things so proper output nesting can be created.