feat(examples): add json example
This commit is contained in:
parent
0a876e2f2b
commit
05cfe17f6a
14
Cargo.toml
14
Cargo.toml
|
@ -7,7 +7,7 @@ repository = "https://github.com/PoiScript/orgize"
|
|||
readme = "README.md"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
keywords = ["orgmode","emacs","parser"]
|
||||
keywords = ["orgmode", "emacs", "parser"]
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "PoiScript/orgize" }
|
||||
|
@ -17,13 +17,13 @@ default = ["serde", "chrono"]
|
|||
extra-serde-info = []
|
||||
|
||||
[dependencies]
|
||||
bytecount = "0.5"
|
||||
chrono = { version = "0.4", optional = true }
|
||||
bytecount = "0.5.1"
|
||||
chrono = { version = "0.4.7", optional = true }
|
||||
indextree = "3.2.0"
|
||||
jetscii = "0.4"
|
||||
memchr = "2"
|
||||
serde = { version = "1.0.93", features = ["derive"], optional = true }
|
||||
serde_json = "1.0.39"
|
||||
jetscii = "0.4.4"
|
||||
memchr = "2.2.0"
|
||||
serde = { version = "1.0.93", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0.39"
|
||||
slugify = "0.1.0"
|
||||
|
|
19
examples/json.rs
Normal file
19
examples/json.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use orgize::Org;
|
||||
use serde_json::to_string;
|
||||
use std::env::args;
|
||||
use std::fs;
|
||||
use std::io::Result;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args: Vec<_> = args().collect();
|
||||
|
||||
if args.len() < 2 {
|
||||
eprintln!("Usage: {} <org-file>", args[0]);
|
||||
} else {
|
||||
let contents = String::from_utf8(fs::read(&args[1])?).unwrap();
|
||||
let mut org = Org::new(&contents);
|
||||
org.parse();
|
||||
println!("{}", to_string(&org).unwrap());
|
||||
}
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in a new issue