66 lines
1.7 KiB
Markdown
66 lines
1.7 KiB
Markdown
A Rust library for parsing org-mode files.
|
|
|
|
[](https://crates.io/crates/orgize)
|
|
[](https://docs.rs/orgize)
|
|

|
|
|
|
# Parse
|
|
|
|
To parse a org-mode string, simply invoking the `Org::parse` function:
|
|
|
|
```rust
|
|
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@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
|
|
|
|
```rust
|
|
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.keyword().unwrap().text(), "TASK");
|
|
```
|
|
|
|
# Render to html
|
|
|
|
Call the `Org::to_html` function to export org element tree to html:
|
|
|
|
```rust
|
|
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.
|