Expand description
A 100% CommonMark and GFM compatible Markdown parser.
Source repository and detailed README
is at https://github.com/kivikakk/comrak.
You can use comrak::markdown_to_html
directly:
use comrak::{markdown_to_html, Options};
assert_eq!(markdown_to_html("Hello, **世界**!", &Options::default()),
"<p>Hello, <strong>世界</strong>!</p>\n");
Or you can parse the input into an AST yourself, manipulate it, and then use your desired formatter:
use comrak::{Arena, parse_document, format_html, Options};
use comrak::nodes::{AstNode, NodeValue};
let arena = Arena::new();
let root = parse_document(
&arena,
"This is my input.\n\n1. Also [my](#) input.\n2. Certainly *my* input.\n",
&Options::default());
for node in root.descendants() {
if let NodeValue::Text(ref mut text) = node.data.borrow_mut().value {
*text = text.replace("my", "your");
}
}
let mut html = vec![];
format_html(root, &Options::default(), &mut html).unwrap();
assert_eq!(
String::from_utf8(html).unwrap(),
"<p>This is your input.</p>\n\
<ol>\n\
<li>Also <a href=\"#\">your</a> input.</li>\n\
<li>Certainly <em>your</em> input.</li>\n\
</ol>\n");
Re-exports§
pub use html::format_document as format_html;
pub use html::format_document_with_plugins as format_html_with_plugins;
Modules§
- Adapter traits for plugins.
- Included from https://github.com/SimonSapin/rust-forest/blob/5783c8be8680b84c0438638bdee07d4e4aca40ac/arena-tree/lib.rs. MIT license (per Cargo.toml).
- The HTML renderer for the CommonMark AST, as well as helper functions.
- The CommonMark AST.
- Plugins for enhancing the default implementation of comrak can be defined in this module.
Structs§
- Converts header strings to canonical, unique, but still human-readable, anchors.
- An arena of objects of type
T
. - Struct to the broken link callback, containing details on the link reference which failed to find a match.
- Options to select extensions.
- Builder for
ExtensionOptions
. - Umbrella options struct.
'c
represents the lifetime of any callback closure options may take. - Options for parser functions.
- Builder for
ParseOptions
. - Umbrella plugins struct.
- Builder for
Plugins
. - Options for formatter functions.
- Builder for
RenderOptions
. - Plugins for alternative rendering.
- Builder for
RenderPlugins
. - A reference link’s resolved details.
Enums§
- Options for bulleted list redering in markdown. See
link_style
inRenderOptions
for more details.
Functions§
- Formats an AST as CommonMark, modified by the given options.
- Formats an AST as CommonMark, modified by the given options. Accepts custom plugins.
- Formats an AST as HTML, modified by the given options.
- Formats an AST as HTML, modified by the given options. Accepts custom plugins.
- Render Markdown back to CommonMark.
- Render Markdown to CommonMark XML. See https://github.com/commonmark/commonmark-spec/blob/master/CommonMark.dtd.
- Render Markdown to CommonMark XML using plugins. See https://github.com/commonmark/commonmark-spec/blob/master/CommonMark.dtd.
- Render Markdown to HTML.
- Render Markdown to HTML using plugins.
- Parse a Markdown document to an AST.
- parse_
document_ with_ broken_ link_ callback Deprecated Parse a Markdown document to an AST, specifyingParseOptions::broken_link_callback
. - Return the version of the crate.
Type Aliases§
- The type of the callback used when a reference link is encountered with no matching reference.
- Legacy naming of
ExtensionOptions
- Legacy naming of
Options
- Legacy naming of
ParseOptions
- Legacy naming of
Plugins
- Legacy naming of
RenderOptions
- Legacy naming of
RenderPlugins