pub struct NoInclude { /* private fields */ }
Expand description
Represents a noinclude tag (<noinclude>
)
This tag is special as it spans multiple nodes, similar to templates. However, because of the way wikitext is written, it’s possible for noinclude tags to be unbalanced, crossing normal HTML tags.
There are a few gotchas to using this because of how the contents
are tracked. You can only go through the descendant nodes using
inclusive_descendants
. It’s not possible to use a tree structure
because there’s no guarantee the contents are balanced HTML nodes.
Mutating nodes inside the noinclude is straightforward, but trying to change the tag itself is complicated. Trying to detach and reattach the same NoInclude instance probably won’t work as expected. Instead it’s recommended to only attach NoInclude instances that you create.
let code = client.transform_to_html("foo<noinclude>bar</noinclude>baz").await?.into_mutable();
// Get the `NoInclude` instance
let noinclude = code.filter_noinclude()[0].clone();
assert_eq!(&noinclude.inclusive_descendants()[0].text_contents(), "bar");
A more sophisticated example:
let code = client.transform_to_html("foo<noinclude>[[bar]] baz</noinclude>!").await?.into_mutable();
// Get the `NoInclude` instance
let noinclude = code.filter_noinclude()[0].clone();
// Get the wikilink
let links: Vec<WikiLink> = noinclude
.inclusive_descendants()
.iter()
.filter_map(|node| node.as_wikilink())
.collect();
assert_eq!(&links[0].target(), "Bar");
See the spec for more details.