Struct rcmark::Node [] [src]

pub struct Node { /* fields omitted */ }

An element of a CommonMark document. This includes headers, paragraphs, links, and various other types. Nodes have a variety of properties depending on their type, all of which are exposed here. However, attempting to access a property that does not apply to the node's type will result in a panic. Setters return true or false to indicate whether the node was updated successfully.

Methods

impl Node
[src]

Wrap a raw cmark_node in a Node instance. Since libcmark uses cmark_node pointers for both owned and unowned references, ownership must be manually specified. This is to ensure that, for example, the return value of node.parent() is not freed but the return value of Node::new is.

Examples

extern crate libcmark_sys as raw;
extern crate rcmark;

unsafe {
    let raw_node = raw::cmark_node_new(raw::CMARK_NODE_LIST);
    let my_node = rcmark::Node::from_raw(raw_node, false);
}

Create a new node of type node_type. Other type-specific properties will not be initialized.

Examples

use rcmark::{Node, NodeType};

let my_node = Node::new(NodeType::Paragraph);

Get the next node in sequence after this one, or None if there is not a subsequent node.

Examples

use rcmark::{Node, parse_document, DEFAULT};

let my_doc = parse_document("*Hello*", DEFAULT);
match my_doc.next() {
    Some(node) => panic!("Should not be an adjacent node"),
    None       => (),
}

Get the previous node in the sequence from this one, or None if there is no prior node.

Get the parent node that contains this node, or None if this node does not have a parent.

Get the first child of this node, or None if this node has no children.

Get the last child of this node, or None if this node has no children.

Create a new iterator over this node and its children.

Get the type of this node.

Examples

use rcmark::{Node, NodeType};

let my_node = Node::new(NodeType::Strong);
assert_eq!(NodeType::Strong, my_node.node_type());

Trait Implementations

impl Drop for Node
[src]

A method called when the value goes out of scope. Read more

impl Debug for Node
[src]

Formats the value using the given formatter.