2 个不稳定版本

0.4.0 2020年11月1日
0.3.0 2019年12月26日

#7 in #restructuredtext

Download history 139/week @ 2024-03-28 130/week @ 2024-04-04 130/week @ 2024-04-11 61/week @ 2024-04-18 51/week @ 2024-04-25 49/week @ 2024-05-02 47/week @ 2024-05-09 46/week @ 2024-05-16 48/week @ 2024-05-23 48/week @ 2024-05-30 49/week @ 2024-06-06 48/week @ 2024-06-13 151/week @ 2024-06-20 47/week @ 2024-06-27 67/week @ 2024-07-04 61/week @ 2024-07-11

330 每月下载量
10 个crate中使用 (5 直接)

MIT/Apache

33KB
692 行代码

document_tree

rst crate 家族的一部分。此crate包含与 Docutils的文档树模型 相对应的结构和特性。基本结构是一个元素树,其中一些元素 具有子元素 和/或 额外属性

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

查看家族中的其他crate,了解如何从rST标记创建一个或渲染它!

这种方法的优点是有便利的子元素接口,以及将元素映射到XML的简单性。缺点是“子元素向量”不是更结构化元素(如章节)的良好定义模型,例如,章节通常包含一个标题后跟一系列块。

依赖项

~3.5–5.5MB
~126K SLoC