Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Orgize
A Rust library for parsing orgmode files.
Live demo: https://orgize.herokuapp.com/
Parse
To parse a orgmode string, simply invoking the Org::parse
function:
use Org;
parse;
or Org::parse_with_config
:
use ;
parse_with_config;
Iter
Org::iter
function will returns an iteractor of Event
s, which is
a simple wrapper of Element
.
use Org;
for event in parse.iter
Note: whether an element is container or not, it will appears twice in one loop.
One as Event::Start(element)
, one as Event::End(element)
.
Render html
You can call the Org::html
function to generate html directly, which
uses the DefaultHtmlHandler
internally:
use Org;
let mut writer = Vec new;
parse.html.unwrap;
assert_eq!;
Render html with custom HtmlHandler
To customize html rendering, simply implementing HtmlHandler
trait and passing
it to the Org::html_with_handler
function.
The following code demonstrates how to add a id for every headline and return own error type while rendering.
use From;
use ;
use FromUtf8Error;
use ;
use ;
use slugify;
// From<std::io::Error> trait is required for custom error type
;
Note: as I mentioned above, each element will appears two times while iterating. And handler will silently ignores all end events from non-container elements.
So if you want to change how a non-container element renders, just redefine the start
function and leave the end
function unchanged.
Serde
Org
struct have already implemented serde's Serialize
trait. It means you can
serialize it into any format supported by serde, such as json:
use Org;
use ;
let org = parse;
println!;
// {
// "type": "document",
// "children": [{
// "type": "section",
// "children": [{
// "type": "paragraph",
// "children":[{
// "type": "text",
// "value":"I 'm "
// }, {
// "type": "bold",
// "children":[{
// "type": "text",
// "value": "bold"
// }]
// }, {
// "type":"text",
// "value":"."
// }]
// }]
// }]
// }
Features
By now, orgize provides two features:
-
ser
: adds the ability to serializeOrg
and other elements usingserde
, enabled by default. -
chrono
: adds the ability to convertDatetime
intochrono
structs, disabled by default. -
syntect
: providesSyntectHtmlHandler
for highlighting code block, disabled by default.
License
MIT