26 releases

0.10.0-alpha.7 Jan 9, 2024
0.10.0-alpha.6 Dec 5, 2023
0.10.0-alpha.5 Nov 21, 2023
0.9.0 Nov 8, 2021
0.1.3 Feb 8, 2019

#218 in Parser implementations

Download history 85/week @ 2023-11-01 56/week @ 2023-11-08 149/week @ 2023-11-15 107/week @ 2023-11-22 117/week @ 2023-11-29 57/week @ 2023-12-06 61/week @ 2023-12-13 116/week @ 2023-12-20 100/week @ 2023-12-27 66/week @ 2024-01-03 81/week @ 2024-01-10 93/week @ 2024-01-17 71/week @ 2024-01-24 59/week @ 2024-01-31 53/week @ 2024-02-07 255/week @ 2024-02-14

446 downloads per month
Used in 3 crates

MIT license

375KB
10K SLoC

Orgize

Crates.io Documentation Build status MIT licensed

A Rust library for parsing org-mode files.

Live Demo: https://poiscript.github.io/orgize/

Parse

To parse a org-mode string, simply invoking the Org::parse function:

use orgize::{Org, rowan::ast::AstNode};

let org = Org::parse("* DONE Title :tag:");
assert_eq!(
    format!("{:#?}", org.document().syntax()),
    r#"DOCUMENT@0..18
  HEADLINE@0..18
    HEADLINE_STARS@0..1 "*"
    WHITESPACE@1..2 " "
    HEADLINE_KEYWORD_DONE@2..6 "DONE"
    WHITESPACE@6..7 " "
    HEADLINE_TITLE@7..13
      TEXT@7..13 "Title "
    HEADLINE_TAGS@13..18
      COLON@13..14 ":"
      TEXT@14..17 "tag"
      COLON@17..18 ":"
"#);

use ParseConfig::parse to specific a custom parse config

use orgize::{Org, ParseConfig, ast::Headline};

let config = ParseConfig {
    // custom todo keywords
    todo_keywords: (vec!["TASK".to_string()], vec![]),
    ..Default::default()
};
let org = config.parse("* TASK Title 1");
let hdl = org.first_node::<Headline>().unwrap();
assert_eq!(hdl.todo_keyword().unwrap(), "TASK");

Render to html

Call the Org::to_html function to export org element tree to html:

use orgize::Org;

assert_eq!(
    Org::parse("* title\n*section*").to_html(),
    "<main><h1>title</h1><section><p><b>section</b></p></section></main>"
);

Checkout examples/html-slugify.rs on how to customizing html export process.

Features

  • chrono: adds the ability to convert Timestamp into chrono::NaiveDateTime, disabled by default.

  • indexmap: adds the ability to convert PropertyDrawer properties into IndexMap, disabled by default.

Dependencies

~2–2.7MB
~44K SLoC