pub fn parse_md_docblock(md: &str) -> Result<DocBlock, ParseError>
Expand description
Parse documentation and extract data
§Parameters
md
: Markdown string, needs to be parseable bypulldown-cmark
§Returns
A Result
, which is either
Ok(DocBlock)
: A type that contains all extracted information (including all unknown sections asCustom
sections).Err(ParseError)
: The first encountered error while parsing the documentation string.
§Examples
Please excuse the weird way the input is formatted in this example.
Embedding Markdown strings in Rust code examples, which are just code blocks
in Markdown documentation strings inside a Rust program is hard!
(Rustdoc treads #
at the beginning of code example line as a sign it
should omit the line from output. Sadly, this means I can’t write Markdown
headlines as usual.)
assert_eq!(parse_md_docblock(
"Lorem ipsum\n\nDolor sit amet.\n\n# Parameters\n\n- `param1`: Foo\n- `param2`: Bar\n"
).unwrap(),
DocBlock {
teaser: "Lorem ipsum".into(),
description: Some("Dolor sit amet.".into()),
sections: vec![
DocSection::Parameters(vec![
("param1".into(), "Foo".into()),
("param2".into(), "Bar".into())
])
]
}
);