မေႃႇၵျူး:template parser/doc
This is the documentation page for မေႃႇၵျူး:template parser
This module provides functions for parsing and finding template invocations found in wikitext.
parseTemplate(text, not_transcluded)- 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 parameters (such as subtemplates, arguments, tables etc), but if the string does not form a valid template in markup, then it will return
nil. findTemplates(text, not_transcluded)- 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:
- The template name.
- The template arguments (as in parseTemplate).
- The the full template invocation as it appears in the original text.
- The index the template appears at within the given text; as with Lua in general, the beginning of the text is index 1.
Note that the parser will respect <noinclude>, <includeonly> and <onlyinclude> tags. By default, text is treated as though it has been transcluded, which means that text between <noinclude> tags will be ignored, and <onlyinclude> tags will be respected if present. If the parameter not_transcluded is set to true, then text will be treated as though it has not been transcluded instead, which means text between <includeonly> tags will be ignored.
For ease of use, the parser will preprocess the template name (meaning that any templates ({{ }}) and arguments ({{{ }}}) it contains will be resolved). For performance reasons, this is not applied to the template arguments, so this should be applied (selectively) by the calling module.
Since the parser is not perfect, it should never be used to audit code.