2 unstable releases

0.4.0 Nov 1, 2020
0.3.0 Dec 26, 2019

#7 in #restructuredtext

Download history 170/week @ 2024-04-01 149/week @ 2024-04-08 55/week @ 2024-04-15 55/week @ 2024-04-22 47/week @ 2024-04-29 49/week @ 2024-05-06 54/week @ 2024-05-13 39/week @ 2024-05-20 46/week @ 2024-05-27 59/week @ 2024-06-03 34/week @ 2024-06-10 105/week @ 2024-06-17 114/week @ 2024-06-24 34/week @ 2024-07-01 65/week @ 2024-07-08 90/week @ 2024-07-15

306 downloads per month
Used in 10 crates (5 directly)

MIT/Apache

33KB
692 lines

document_tree

Part of the rst crate family. This crate contains structs and traits mirroring Docutils’ Document Tree model. The basic structure is a tree of elements, some of which have children and/or extra attributes.

use document_tree::*;
use document_tree::{extra_attributes as a, element_categories as c, attribute_types as t};

#[test]
fn imperative() {
    let mut doc = Document::default();
    let mut title = Title::default();
    let url = "https://example.com/image.jpg".parse().unwrap();
    let image = ImageInline::with_extra(a::ImageInline::new(url));
    title.append_child("Hi");
    title.append_child(image);
    doc.append_child(title);
    println!("{:?}", doc);
}

#[test]
fn descriptive() {
    let doc = Document::with_children(vec![
        Title::with_children(vec![
            "Hi".into(),
            ImageInline::with_extra(a::ImageInline::new(
                "https://example.com/image.jpg".parse().unwrap()
            )).into(),
        ]).into()
    ]);
    println!("{:?}", doc);
}

Check out the other crates in the family on how to create one from rST markup or render it!

The advantages of this approach are that it’s convenient to have the children interface, as well as to trivially map elements to XML. The disadvantage is that a “vector of children” is not a well-defined model for the more structured elements like e.g. a section, which always contains a title followed by blocks.

Dependencies

~3.5–5.5MB
~125K SLoC