docs: update serde examples

This commit is contained in:
PoiScript 2019-06-28 00:50:15 +08:00
parent 5a9e085b61
commit 727c9f14f7
2 changed files with 53 additions and 11 deletions

View file

@ -143,7 +143,34 @@ function and leave the end function untouched.
freely serialize it into any format that serde supports such as json: freely serialize it into any format that serde supports such as json:
```rust ```rust
use orgize::Org;
use serde_json::{json, to_string};
let org = Org::parse("I 'm *bold*.");
println!("{}", to_string(&org).unwrap()); println!("{}", to_string(&org).unwrap());
// {
// "type": "document",
// "children": [{
// "type": "section",
// "children": [{
// "type": "paragraph",
// "children":[{
// "type": "text",
// "value":"I 'm "
// }, {
// "type": "bold",
// "children":[{
// "type": "text",
// "value": "bold"
// }]
// }, {
// "type":"text",
// "value":"."
// }]
// }]
// }]
// }
``` ```
## License ## License

View file

@ -186,19 +186,34 @@
//! freely serialize it into any format that serde supports such as json: //! freely serialize it into any format that serde supports such as json:
//! //!
//! ```rust //! ```rust
//! use serde_json::to_string; //! use orgize::Org;
//! # use orgize::Org; //! use serde_json::{json, to_string};
//! #
//! # let org = Org::parse(r#"* Title 1
//! # *Section 1*
//! # ** Title 2
//! # _Section 2_
//! # * Title 3
//! # /Section 3/
//! # * Title 4
//! # =Section 4="#);
//! //!
//! let org = Org::parse("I 'm *bold*.");
//! println!("{}", to_string(&org).unwrap()); //! println!("{}", to_string(&org).unwrap());
//!
//! // {
//! // "type": "document",
//! // "children": [{
//! // "type": "section",
//! // "children": [{
//! // "type": "paragraph",
//! // "children":[{
//! // "type": "text",
//! // "value":"I 'm "
//! // }, {
//! // "type": "bold",
//! // "children":[{
//! // "type": "text",
//! // "value": "bold"
//! // }]
//! // }, {
//! // "type":"text",
//! // "value":"."
//! // }]
//! // }]
//! // }]
//! // }
//! ``` //! ```
pub mod elements; pub mod elements;