Module:template parser/documentation

This module provides functions for parsing and finding template invocations found in wikitext.


 * lua
 * Parses text as a template invocation and returns a pair of values, the template name and the arguments (containing anonymous, numbered and named arguments). If the text could not be parsed as a template invocation, the function returns nil. The parser will correctly parse any wikitext given as template arguments (such as subtemplates, arguments, tables etc), but if the string does not form a valid template in markup, then it will return.


 * lua
 * Finds all template invocations in the text. This is designed to be used as an iterator in for statements, and returns four values for each invocation:


 * 1) The template name.
 * 2) The template arguments.
 * 3) The the full template invocation as it appears in the original text.
 * 4) The index the template appears at within the given text; as with Lua in general, the beginning of the text is index 1.

For convenience, template names will be normalized in two ways: Note that any templates with invalid names (after preprocessing) will be skipped over. For performance reasons, preprocessing is only applied to the keys in a template's table of arguments, so it should be applied (selectively) to the values by the calling module when needed.
 * 1) They are preprocessed, which means that any templates  and arguments  they contain will be resolved.
 * 2) Any redirects will be converted to their canonical equivalents (e.g. l is treated as link).

Note that the parser will respect,   and   tags. By default, text is treated as though it has been transcluded, which means that text between  tags will be ignored, and   tags will be respected if present. If the parameter not_transcluded is set to lua, then text will be treated as though it has not been transcluded, which means text between  tags will be ignored instead.

Although the parser is very accurate, some discrepancies may still exist between it and the native parser in certain cases.