2019-02-06 12:50:18 +00:00
|
|
|
# Orgize
|
|
|
|
|
|
|
|
Orgize is a Emacs Org-mode parser written by pure Rust. It behaves like a pull
|
|
|
|
parser (returning an iterator of events) but not exactly.
|
|
|
|
|
|
|
|
Besides, orgize also provides some mechanism for exporting org-mode files to
|
|
|
|
various formats, e.g. HTML.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```toml
|
|
|
|
[dependencies]
|
|
|
|
orgize = "0.1.0"
|
|
|
|
```
|
|
|
|
|
|
|
|
```rust
|
|
|
|
// Rust 2015 only
|
|
|
|
extern crate orgize;
|
|
|
|
```
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
```rust
|
|
|
|
use orgize::Parser;
|
|
|
|
|
2019-02-14 05:38:48 +00:00
|
|
|
let parser = Parser::new(
|
|
|
|
r"* Title 1
|
2019-02-06 12:50:18 +00:00
|
|
|
*Section 1*
|
|
|
|
** Title 2
|
|
|
|
_Section 2_
|
|
|
|
* Title 3
|
|
|
|
/Section 3/
|
|
|
|
* Title 4
|
2019-02-14 05:38:48 +00:00
|
|
|
=Section 4=",
|
|
|
|
);
|
2019-02-06 12:50:18 +00:00
|
|
|
|
2019-02-14 05:38:48 +00:00
|
|
|
for event in parser {
|
|
|
|
// handling the event
|
2019-02-06 12:50:18 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively, you can use the built-in render.
|
|
|
|
|
2019-02-07 07:54:16 +00:00
|
|
|
```rust
|
2019-02-14 05:38:48 +00:00
|
|
|
use orgize::export::DefaultHtmlRender;
|
2019-02-07 07:54:16 +00:00
|
|
|
use std::io::Cursor;
|
|
|
|
|
2019-02-14 05:38:48 +00:00
|
|
|
let contents = r"* Title 1
|
2019-02-07 07:54:16 +00:00
|
|
|
*Section 1*
|
|
|
|
** Title 2
|
|
|
|
_Section 2_
|
|
|
|
* Title 3
|
|
|
|
/Section 3/
|
|
|
|
* Title 4
|
2019-02-14 05:38:48 +00:00
|
|
|
=Section 4=";
|
2019-02-07 07:54:16 +00:00
|
|
|
|
2019-02-14 05:38:48 +00:00
|
|
|
let cursor = Cursor::new(Vec::new());
|
|
|
|
let mut render = DefaultHtmlRender::new(cursor, &contents);
|
2019-02-07 07:54:16 +00:00
|
|
|
|
2019-02-14 05:38:48 +00:00
|
|
|
render
|
|
|
|
.render()
|
|
|
|
.expect("something went wrong rendering the file");
|
|
|
|
|
2019-02-14 06:02:29 +00:00
|
|
|
let result = String::from_utf8(render.into_writer().into_inner()).expect("invalid utf-8");
|
2019-02-07 07:54:16 +00:00
|
|
|
```
|
|
|
|
|
2019-02-06 12:50:18 +00:00
|
|
|
## License
|
|
|
|
|
|
|
|
MIT
|