pub struct Node {
pub node_type: NodeType,
pub kind: String,
pub form: Option<Form>,
pub attrs: Attrs,
pub children: Option<Vec<Node>>,
pub value: Option<StructuredValue>,
pub source: String,
pub range: Option<Range>,
pub instance: String,
/* private fields */
}Expand description
A node of the tree: a Markdown segment (its source) or a directive.
Fields§
§node_type: NodeType§kind: StringA directive’s kind (must, policy, charts:metric); empty for Markdown.
form: Option<Form>A directive’s form; None for Markdown.
attrs: Attrs§children: Option<Vec<Node>>A Markdown-bodied directive’s parsed body; a literal body (an example’s, a verbatim one) is one Markdown node.
None: the directive has no such body (a leaf, a structured body); empty: an empty one.
value: Option<StructuredValue>A structured or literal-format body (YAML, JSON, CSV, text, HTML, code).
source: StringA Markdown node’s text, or the full source of a directive this reader does not interpret.
range: Option<Range>§instance: StringA resolved node’s composition path (§2, §14.1): root, root/personal.
Implementations§
Source§impl Node
impl Node
pub fn is_markdown(&self) -> bool
pub fn is_directive(&self) -> bool
Sourcepub fn keyword(&self) -> Option<&str>
pub fn keyword(&self) -> Option<&str>
The keyword a keyword rule or an alert was written with (ALWAYS, AVOID, MUST NOT); the tree keeps its
normalized kind. Set by the reader.
Sourcepub fn reason_range(&self) -> Option<Range>
pub fn reason_range(&self) -> Option<Range>
The lines of a rule’s BECAUSE: reason, which the tree keeps as the rule’s because. Set by the reader.
Sourcepub fn is_prose(&self) -> bool
pub fn is_prose(&self) -> bool
Is this Markdown node parsed prose (not an example’s or a verbatim body’s quoted text)? Set by the reader.
Sourcepub fn body_source(&self) -> Option<&str>
pub fn body_source(&self) -> Option<&str>
The exact source text of a container’s body, as the reader read it: every line between the opening fence’s
line and the closing fence’s (each with its line ending, comments and all; empty for an empty body), or to the
end of the source when the container is not closed. None for any other node, and for a node not read from
source (built, or decoded from a tree’s JSON).
use instruction_md::{read, ReadOptions};
let r = read(":::skill{id=plan}\nPlan the day.\n<!-- kept -->\n:::\n", &ReadOptions::default());
assert_eq!(r.document.body[0].body_source(), Some("Plan the day.\n<!-- kept -->\n"));