Skip to content

PolySync/doogie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Doogie

Overview

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.

Getting Started

Dependencies

Building

Doogie can be built using cargo.

  • From the root of the project
    $ cargo build
    

Installation

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"}
    

Usage

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());

Examples

  • 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 nodes
    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() {
        let prune = match node {
            Node::Heading(ref heading) => heading.get_level() == 6,
            _ => false
        };
    
        if prune {
            node.unlink();
        }
    }

Tests

The tests are located inline with the module code in src/lib.rs.

Building

To build jsut the tests run $ cargo build --tests.

Running Tests

The tests are run by invoking $ cargo test. This will build them automatically if necessary.

License

© 2018, PolySync Technologies, Inc.

Please see the LICENSE file for more details