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, __children__() should be a generator that iterates over them. If the node is printable (shown when the page is rendered), __strip__() should return its printable version, stripping out any formatting marks. It does not have to return 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 external link, like [http://example.com/ Example].
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>.
Add an attribute with the given name and value.
name and value can be anything parasable by utils.parse_anything(); value can be omitted if the attribute is valueless. quoted is a bool telling whether to wrap the value in double quotes (this is recommended). pad_first, pad_before_eq, and pad_after_eq are whitespace used as padding before the name, before the equal sign (or after the name if no value), and after the equal sign (ignored if no value), respectively.
The list of attributes affecting the tag.
Each attribute is an instance of Attribute.
The closing tag, as a Wikicode object.
This will usually equal tag, unless there is additional spacing, comments, or the like.
Get the attribute with the given name.
The returned object is a Attribute instance. Raises ValueError if no attribute has this name. Since multiple attributes can have the same name, we’ll return the last match, since all but the last are ignored by the MediaWiki parser.
Return whether any attribute in the tag has the given name.
Note that a tag may have multiple attributes with the same name, but only the last one is read by the MediaWiki parser.
Whether the tag is implicitly self-closing, with no ending slash.
This is only possible for specific “single” tags like <br> and <li>. See definitions.is_single(). This field only has an effect if self_closing is also True.
Whether the tag starts with a backslash after the opening bracket.
This makes the tag look like a lone close tag. It is technically invalid and is only parsable Wikicode when the tag itself is single-only, like <br> and <img>. See definitions.is_single_only().
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 are automatically escaped from value when appropriate.
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 in the template, we’ll replace its value while keeping the same whitespace around it. We will also try to guess the dominant spacing convention when adding a new parameter using _get_spacing_conventions().
If before is given (either a Parameter object or a name), then we will place the parameter immediately before this one. Otherwise, it will be added at the end. If before is a name and exists multiple times in the template, we will place it before the last occurance. If before is not in the template, ValueError is raised. The argument is ignored if the new parameter already exists.
If preserve_spacing is False, we will avoid preserving spacing conventions when changing the value of an existing parameter or when adding a new one.
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, but only the last one is read by the MediaWiki parser.
Remove a parameter from the template, identified by param.
If param is a Parameter object, it will be matched exactly, otherwise it will be treated like the name argument to has() and get().
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).
If the parameter shows up multiple times in the template and param is not a Parameter object, we will remove all instances of it (and keep only one if keep_field is True - the first instance if none have dependents, otherwise the one with dependents will be kept).
Bases: mwparserfromhell.nodes.Node
Represents ordinary, unformatted text with no special properties.