Doogie is a wrapper library around cmark,
the C
implementation of CommonMark. It provides
implicit memory safety around node allocation not present in the C
library.
Doogie can be built using cargo.
- From the root of the project
$ cargo build
Doogie can be integrated into your Rust project by adding it to your
Cargo.toml
file.
- Add Doogie to
Cargo.toml
[dependencies] doogie = { git="https://github.com/PolySync/doogie", branch="devel"}
The basic workflow is to use parse_document
to parse the textual content of
a Markdown document into the CommonMark AST. You will get a handle to the root
Document
node with which you can traverse and manipulate the AST. You can
export the document back into a textual form using any of the render methods
such as Node::render_commonmark()
.
use doogie::parse_document;
let document = "# My Great Document \
\
* Item 1 \
* Item 2 \
* Item 3";
let root = parse_document(document);
println!("{}", root.render_xml());
- Transform all text into uppercase
use doogie::{parse_document, Node}; let document = "# My Great Document \ \ * Item 1 \ * Item 2 \ * Item 3"; let root = parse_document(document); for (mut node, _) in root.iter() { if let Node::Text(ref mut node) = node { let content = node.get_content().unwrap(); node.set_content(&content.to_uppercase()).unwrap(); } }
- Remove all level 6
Heading
nodesuse doogie::{parse_document, Node}; let document = "# My Great Document \ \ * Item 1 \ * Item 2 \ * Item 3"; let root = parse_document(document); for (mut node, _) in root.iter() { let prune = match node { Node::Heading(ref heading) => heading.get_level() == 6, _ => false }; if prune { node.unlink(); } }
The tests are located inline with the module code in src/lib.rs
.
To build jsut the tests run $ cargo build --tests
.
The tests are run by invoking $ cargo test
. This will build them automatically
if necessary.
© 2018, PolySync Technologies, Inc.
- Devin Smith dsmith@polysync.io
Please see the LICENSE file for more details