Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a function to parse pulldown-mark Events #2

Merged
merged 1 commit into from
May 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern crate pulldown_cmark;
#[macro_use] extern crate quick_error;

use pulldown_cmark::Parser;
use pulldown_cmark::Event;

mod types;
mod errors;
Expand All @@ -19,6 +20,8 @@ mod extractors;
pub use errors::ParseError;
pub use types::*;

use ::std::iter::Peekable;

/// Parse documentation and extract data
///
/// # Parameters
Expand Down Expand Up @@ -62,10 +65,29 @@ pub use types::*;
/// ```
pub fn parse_md_docblock(md: &str) -> Result<DocBlock, ParseError> {
let mut md_events = Parser::new(md).peekable();
parse_md_docblock_events(&mut md_events)
}

/// Parse documentation and extract data
///
/// # Parameters
///
/// - `md`: Markdown
///
/// # Returns
///
/// A `Result`, which is either
///
/// - `Ok(DocBlock)`: A type that contains all extracted information (including
/// all unknown sections as `Custom` sections).
/// - `Err(ParseError)`: The first encountered error while parsing the
/// documentation string.
pub fn parse_md_docblock_events<'a, I>(events: &mut Peekable<I>) -> Result<DocBlock, ParseError> where
I: Iterator<Item=Event<'a>>,
{
Ok(DocBlock {
teaser: try!(extractors::teaser(&mut md_events)),
description: try!(extractors::description(&mut md_events)),
sections: try!(extractors::sections(&mut md_events)),
teaser: try!(extractors::teaser(events)),
description: try!(extractors::description(events)),
sections: try!(extractors::sections(events)),
})
}