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]
unsafe fn from_raw(raw: *mut cmark_node, owned: bool) -> Node
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); }
fn new(node_type: NodeType) -> Node
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);
fn next(&self) -> Option<Node>
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 => (), }
fn previous(&self) -> Option<Node>
Get the previous node in the sequence from this one, or None
if there
is no prior node.
fn parent(&self) -> Option<Node>
Get the parent node that contains this node, or None
if this node does
not have a parent.
fn first_child(&self) -> Option<Node>
Get the first child of this node, or None
if this node has no children.
fn last_child(&self) -> Option<Node>
Get the last child of this node, or None
if this node has no children.
fn iter(&self) -> NodeIterator
Create a new iterator over this node and its children.
fn node_type(&self) -> NodeType
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());