Struct parsoid::Template[][src]

pub struct Template { /* fields omitted */ }
Expand description

Represents a MediaWiki template ({{foo}})

How to access values from an existing template:

let code = client.transform_to_html("{{1x|test}}").await?;
// Get the `Template` instance
let template = code.filter_templates()?[0].clone();
assert_eq!(template.name(), "Template:1x".to_string());
assert_eq!(template.raw_name(), "./Template:1x".to_string());
assert_eq!(template.name_in_wikitext(), "1x".to_string());
assert_eq!(template.get_param("1"), Some("test".to_string()));

How to create and insert a new template:

let mut params = map::IndexMap::new();
params.insert("1".to_string(), "test".to_string());
let template = Template::new("1x", &params)?;
let code = Wikicode::new("");
template.append_on(&code);
let wikitext = client.transform_to_wikitext(&code).await?;
assert_eq!(wikitext, "{{1x|test}}".to_string());

You can also use Template::new_simple() if there are no parameters to pass.

Implementations

Create a new template with no parameters

Create a new template

Remove this template from the document

Prepend this template into a node. Effectively calling node.prepend(template)

Append this template into a node. Effectively calling node.append(template)

Insert this template after the node Effectively calling node.insert_after(template)

Insert this template before the node Effectively calling node.insert_before(template)

Get the name of the template as it appears in wikitext

Get the full name of the template, e.g. ./Template:Foo_bar or the parser function, e.g. ifeq.

Get a pretty normalized name of a template, e.g. Template:Foo bar or the parser function, e.g. ifeq

Get a map of all parameters, named and unnamed

Get the wikitext value of a specific parameter if it exists

Get the name of the parameter as it appears in the wikitext. For example given {{1x|param<!--comment-->name=value}} looking up paramname would return Some("param<!--comment->name").

Whether it’s a template (as opposed to a parser function)

Whether it’s a parser function (as opposed to a template)

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more