A Rust library for parsing org-mode files. https://poiscript.github.io/orgize/
Find a file
2023-11-21 18:44:55 +08:00
.cargo chore: prepare for v0.10.0-alpha.1 2023-11-13 16:33:04 +08:00
.github ci: fix ci 2023-11-13 17:21:33 +08:00
benches fix: single \r will be consider as blank line 2023-11-14 14:12:05 +08:00
docs chore: remove outdated SYNTAX.md 2023-11-21 18:44:55 +08:00
examples feat: support subscript and superscript 2023-11-21 18:42:55 +08:00
fuzz fix: single \r will be consider as blank line 2023-11-14 14:12:05 +08:00
src feat: support subscript and superscript 2023-11-21 18:42:55 +08:00
tests feat: support line breaks 2023-11-21 16:35:25 +08:00
wasm feat: support subscript and superscript 2023-11-21 18:42:55 +08:00
.gitignore chore: remove orgize-sync package 2019-10-10 10:44:59 +08:00
Cargo.toml release: bump version to 0.10.0-alpha.4 2023-11-20 01:47:23 +08:00
development.md docs: add development.md 2023-11-17 16:47:15 +08:00
LICENSE chore: bump license year 2023-11-13 17:25:20 +08:00
README.md feat: introduce Token struct 2023-11-20 15:30:33 +08:00

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.