Wikicode

Struct Wikicode 

Source
pub struct Wikicode { /* private fields */ }
Expand description

Container for HTML, usually represents the entire page

Implementations§

Source§

impl Wikicode

Source

pub fn new(body: &str) -> Self

Create a new Wikicode instance from raw Parsoid HTML.

Source

pub fn new_node(tag: &str) -> Self

Create a new HTML node with the given tag

let node = Wikicode::new_node("b");
// Append your list items
node.append(&Wikicode::new_text("bolded text"));
assert_eq!(&node.to_string(), "<b>bolded text</b>")
Source

pub fn new_text(text: &str) -> Self

Create a text node with the given contents

let node = Wikicode::new_text("foo bar");
assert_eq!(&node.to_string(), "foo bar");
// Tags will be escaped
let weird_node = Wikicode::new_text("foo <bar>");
assert_eq!(&weird_node.to_string(), "foo &lt;bar&gt;");
Source

pub fn spec_version(&self) -> Option<String>

Get the HTML spec version for this document, if it’s available

Source

pub fn revision_id(&self) -> Option<u64>

Get the revision id associated with the Parsoid HTML, if it has one.

Source

pub fn title(&self) -> Option<String>

Get the title associated with the Parsoid HTML, if it has one.

Source

pub fn redirect(&self) -> Option<Redirect>

Source

pub fn text_contents(&self) -> String

Get a plain text representation of the Parsoid HTML with all markup stripped.

Source

pub fn into_immutable(self) -> ImmutableWikicode

Source

pub fn remove_parsoid_data(&mut self)

Removes all data-parsoid attributes

It is purely Parsoid-internal information and may be changed without notice. It should not be used by bots because of its unstablity.

This can be useful when testing bots, because tests should not fail when data-parsoid is changed.

Source

pub fn without_parsoid_data(self) -> Self

Removes all data-parsoid attributes

See Self::remove_parsoid_data.

Methods from Deref<Target = NodeRef>§

Source

pub fn inclusive_ancestors(&self) -> Ancestors

Return an iterator of references to this node and its ancestors.

Source

pub fn ancestors(&self) -> Ancestors

Return an iterator of references to this node’s ancestors.

Source

pub fn inclusive_preceding_siblings(&self) -> Rev<Siblings>

Return an iterator of references to this node and the siblings before it.

Source

pub fn preceding_siblings(&self) -> Rev<Siblings>

Return an iterator of references to this node’s siblings before it.

Source

pub fn inclusive_following_siblings(&self) -> Siblings

Return an iterator of references to this node and the siblings after it.

Source

pub fn following_siblings(&self) -> Siblings

Return an iterator of references to this node’s siblings after it.

Source

pub fn children(&self) -> Siblings

Return an iterator of references to this node’s children.

Source

pub fn inclusive_descendants(&self) -> Descendants

Return an iterator of references to this node and its descendants, in tree order.

Parent nodes appear before the descendants.

Note: this is the NodeEdge::Start items from traverse().

Source

pub fn descendants(&self) -> Descendants

Return an iterator of references to this node’s descendants, in tree order.

Parent nodes appear before the descendants.

Note: this is the NodeEdge::Start items from traverse().

Source

pub fn traverse_inclusive(&self) -> Traverse

Return an iterator of the start and end edges of this node and its descendants, in tree order.

Source

pub fn traverse(&self) -> Traverse

Return an iterator of the start and end edges of this node’s descendants, in tree order.

Source

pub fn select( &self, selectors: &str, ) -> Result<Select<Elements<Descendants>>, ()>

Return an iterator of the inclusive descendants element that match the given selector list.

Source

pub fn select_first( &self, selectors: &str, ) -> Result<NodeDataRef<ElementData>, ()>

Return the first inclusive descendants element that match the given selector list.

Source

pub fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write,

Serialize this node and its descendants in HTML syntax to the given stream.

Source

pub fn serialize_to_file<P>(&self, path: P) -> Result<(), Error>
where P: AsRef<Path>,

Serialize this node and its descendants in HTML syntax to a new file at the given path.

Source

pub fn text_contents(&self) -> String

Return the concatenation of all text nodes in this subtree.

Source

pub fn append(&self, new_child: NodeRef)

Append a new child to this node, after existing children.

The new child is detached from its previous position.

Source

pub fn prepend(&self, new_child: NodeRef)

Prepend a new child to this node, before existing children.

The new child is detached from its previous position.

Source

pub fn insert_after(&self, new_sibling: NodeRef)

Insert a new sibling after this node.

The new sibling is detached from its previous position.

Source

pub fn insert_before(&self, new_sibling: NodeRef)

Insert a new sibling before this node.

The new sibling is detached from its previous position.

Methods from Deref<Target = Node>§

Source

pub fn data(&self) -> &NodeData

Return a reference to this node’s node-type-specific data.

Source

pub fn as_element(&self) -> Option<&ElementData>

If this node is an element, return a reference to element-specific data.

Source

pub fn as_text(&self) -> Option<&RefCell<String>>

If this node is a text node, return a reference to its contents.

Source

pub fn as_comment(&self) -> Option<&RefCell<String>>

If this node is a comment, return a reference to its contents.

Source

pub fn as_doctype(&self) -> Option<&Doctype>

If this node is a document, return a reference to doctype-specific data.

Source

pub fn as_document(&self) -> Option<&DocumentData>

If this node is a document, return a reference to document-specific data.

Source

pub fn parent(&self) -> Option<NodeRef>

Return a reference to the parent node, unless this node is the root of the tree.

Source

pub fn first_child(&self) -> Option<NodeRef>

Return a reference to the first child of this node, unless it has no child.

Source

pub fn last_child(&self) -> Option<NodeRef>

Return a reference to the last child of this node, unless it has no child.

Source

pub fn previous_sibling(&self) -> Option<NodeRef>

Return a reference to the previous sibling of this node, unless it is a first child.

Source

pub fn next_sibling(&self) -> Option<NodeRef>

Return a reference to the next sibling of this node, unless it is a last child.

Source

pub fn detach(&self)

Detach a node from its parent and siblings. Children are not affected.

To remove a node and its descendants, detach it and drop any strong reference to it.

Source

pub fn extended_eq(&self, other: &Node, flags: NodeEqFlags) -> bool

Compares if two nodes are equal.

Trait Implementations§

Source§

impl Clone for Wikicode

Source§

fn clone(&self) -> Wikicode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Wikicode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ImmutableWikicode> for Wikicode

Source§

fn from(immutable: ImmutableWikicode) -> Self

Converts to this type from the input type.
Source§

impl From<Wikicode> for ImmutableWikicode

Source§

fn from(code: Wikicode) -> Self

Converts to this type from the input type.
Source§

impl From<Wikinode> for Wikicode

Source§

fn from(node: Wikinode) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Wikicode

Source§

fn eq(&self, other: &Wikicode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl WikinodeIterator for Wikicode

Source§

fn as_node(&self) -> &NodeRef

Source§

fn filter_comments(&self) -> Vec<Comment>

Get a list of all comments (<!-- example -->)
Source§

fn append<N: WikiMultinode>(&self, code: &N)

Append a node as a child
Source§

fn prepend<N: WikiMultinode>(&self, code: &N)

Prepend a node as a child
Source§

fn insert_after<N: WikiMultinode>(&self, code: &N)

Insert a node after the current node, as a sibling
Source§

fn insert_before<N: WikiMultinode>(&self, code: &N)

Insert a node before the current node, as a sibling
Source§

fn select(&self, selector: &str) -> Vec<Wikinode>

Select some wiki nodes
Source§

fn select_first(&self, selector: &str) -> Option<Wikinode>

Get the first element that matches the selector, if possible
Get a list of all wikilinks ([[Foo|bar]])
Get a list of all external links ([https://example.org/ Example])
Source§

fn filter_categories(&self) -> Vec<Category>

Get a list of all categories
Source§

fn filter_images(&self) -> Vec<Image>

Get a list of all iamges
Source§

fn filter_templates(&self) -> Result<Vec<Template>>

Get a list of templates
Source§

fn filter_parser_functions(&self) -> Result<Vec<Template>>

Get a list of parser functions.
Get a list of all reference links on the page, e.g. [1]. Read more
Source§

fn filter_reference_lists(&self) -> Vec<ReferenceList>

Get a list of all reference lists on the page, e.g. <references>
Source§

fn filter_references(&self) -> Vec<Reference>

Get all references on the page. Read more
Source§

fn iter_sections(&self) -> Vec<Section>

Source§

fn filter_noinclude(&self) -> Vec<NoInclude>

Source§

fn filter_onlyinclude(&self) -> Vec<OnlyInclude>

Source§

fn parent(&self) -> Option<Wikinode>

Return the parent node, if it has one
Source§

fn next_sibling(&self) -> Option<Wikinode>

Return the next sibling node, if it has one
Source§

fn previous_sibling(&self) -> Option<Wikinode>

Return the previous sibling node, if it has one
Source§

fn inclusive_ancestors(&self) -> WikinodeMap<Ancestors>

Return an iterator of references to this node and its ancestors.
Source§

fn ancestors(&self) -> WikinodeMap<Ancestors>

Return an iterator of references to this node’s ancestors.
Source§

fn inclusive_preceding_siblings(&self) -> WikinodeMap<Rev<Siblings>>

Return an iterator of references to this node and the siblings before it.
Source§

fn preceding_siblings(&self) -> WikinodeMap<Rev<Siblings>>

Return an iterator of references to this node’s siblings before it.
Source§

fn inclusive_following_siblings(&self) -> WikinodeMap<Siblings>

Return an iterator of references to this node and the siblings after it.
Source§

fn following_siblings(&self) -> WikinodeMap<Siblings>

Return an iterator of references to this node’s siblings after it.
Source§

fn children(&self) -> WikinodeMap<Siblings>

Return an iterator of references to this node’s children.
Source§

fn inclusive_descendants(&self) -> WikinodeMap<Descendants>

Return an iterator of references to this node and its descendants, in tree order. Parent nodes appear before the descendants.
Source§

fn descendants(&self) -> WikinodeMap<Descendants>

Return an iterator of references to this node’s descendants, in tree order. Parent nodes appear before the descendants.
Source§

impl Deref for Wikicode

Source§

type Target = NodeRef

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Eq for Wikicode

Source§

impl StructuralPartialEq for Wikicode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WikiMultinode for T

Source§

fn as_nodes(&self) -> Vec<NodeRef>

Source§

fn as_wikinodes(&self) -> WikinodeMap<IntoIter<NodeRef>>

Source§

fn detach(&self)

Remove this from the document
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,