This package contains Wikicode “nodes”, which represent a single unit of wikitext, such as a Template, an HTML tag, a Heading, or plain text. The node “tree” is far from flat, as most types can contain additional Wikicode types within them - and with that, more nodes. For example, the name of a Template is a Wikicode object that can contain text or more templates.
Represents the base Node type, demonstrating the methods to override.
__unicode__() must be overridden. It should return a unicode or (str in py3k) representation of the node. If the node contains Wikicode objects inside of it, __iternodes__() should be overridden to yield tuples of (wikicode, node_in_wikicode) for each node in each wikicode, as well as the node itself (None, self). If the node is printable, __strip__() should be overridden to return the printable version of the node - it does not have to be a string, but something that can be converted to a string with str(). Finally, __showtree__() can be overridden to build a nice tree representation of the node, if desired, for get_tree().
Bases: mwparserfromhell.nodes.Node
Represents a template argument substitution, like {{{foo}}}.
The default value to substitute if none is passed.
This will be None if the argument wasn’t defined with one. The MediaWiki parser handles this by rendering the argument itself in the result, complete braces. To have the argument render as nothing, set default to "" ({{{arg}}} vs. {{{arg|}}}).
Bases: mwparserfromhell.nodes.Node
Represents a hidden HTML comment, like <!-- foobar -->.
Bases: mwparserfromhell.nodes.Node
Represents an HTML entity, like , either named or unnamed.
If the value is hexadecimal, this is the letter denoting that.
For example, the hex_char of "ሴ" is "x", whereas the hex_char of "ሴ" is "X". Lowercase and uppercase x are the only values supported.
Bases: mwparserfromhell.nodes.Node
Represents an HTML-style tag in wikicode, like <ref>.
Bases: mwparserfromhell.nodes.Node
Represents a template in wikicode, like {{foo}}.
Add a parameter to the template with a given name and value.
name and value can be anything parasable by utils.parse_anything(); pipes (and equal signs, if appropriate) are automatically escaped from value where applicable. If showkey is given, this will determine whether or not to show the parameter’s name (e.g., {{foo|bar}}‘s parameter has a name of "1" but it is hidden); otherwise, we’ll make a safe and intelligent guess. If name is already a parameter, we’ll replace its value while keeping the same spacing rules unless force_nonconformity is True. We will also try to guess the dominant spacing convention when adding a new parameter using _get_spacing_conventions() unless force_nonconformity is True.
Get the parameter whose name is name.
The returned object is a Parameter instance. Raises ValueError if no parameter has this name. Since multiple parameters can have the same name, we’ll return the last match, since the last parameter is the only one read by the MediaWiki parser.
Return True if any parameter in the template is named name.
With ignore_empty, False will be returned even if the template contains a parameter with the name name, if the parameter’s value is empty. Note that a template may have multiple parameters with the same name.
Remove a parameter from the template whose name is name.
If keep_field is True, we will keep the parameter’s name, but blank its value. Otherwise, we will remove the parameter completely unless other parameters are dependent on it (e.g. removing bar from {{foo|bar|baz}} is unsafe because {{foo|baz}} is not what we expected, so {{foo||baz}} will be produced instead), unless force_no_field is also True. If the parameter shows up multiple times in the template, we will remove all instances of it (and keep one if keep_field is True - that being the first instance if none of the instances have dependents, otherwise that instance will be kept).
Bases: mwparserfromhell.nodes.Node
Represents ordinary, unformatted text with no special properties.