extras Package

extras Package

This package contains objects used by Nodes, but that are not nodes themselves. This includes template parameters and HTML tag attributes.

class mwparserfromhell.nodes.extras.Attribute(name: Any, value: Any = None, quotes: str | None = '"', pad_first: str = ' ', pad_before_eq: str = '', pad_after_eq: str = '')[source]

Bases: StringMixIn

Represents an attribute of an HTML tag.

This is used by Tag objects. For example, the tag <ref name="foo"> contains an Attribute whose name is "name" and whose value is "foo".

static coerce_quotes(quotes: Any) str | None[source]

Coerce a quote type into an acceptable value, or raise an error.

property name: Wikicode

The name of the attribute as a Wikicode object.

property pad_after_eq: str

Spacing to insert right after the equal sign.

property pad_before_eq: str

Spacing to insert right before the equal sign.

property pad_first: str

Spacing to insert right before the attribute.

property quotes: str | None

How to enclose the attribute value. ", ', or None.

property value: Wikicode | None

The value of the attribute as a Wikicode object.

class mwparserfromhell.nodes.extras.Parameter(name: Any, value: Any, showkey: bool = True)[source]

Bases: StringMixIn

Represents a parameter of a template.

For example, the template {{foo|bar|spam=eggs}} contains two Parameters: one whose name is "1", value is "bar", and showkey is False, and one whose name is "spam", value is "eggs", and showkey is True.

static can_hide_key(key: Any) Match | None[source]

Return whether or not the given key can be hidden.

property name: Wikicode

The name of the parameter as a Wikicode object.

property showkey: bool

Whether to show the parameter’s key (i.e., its “name”).

property value: Wikicode

The value of the parameter as a Wikicode object.