comrak - Rust (original) (raw)
Expand description
A 100% CommonMark and GFMcompatible 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");
pub use html::[format_document](html/fn.format%5Fdocument.html "fn comrak::html::format_document") as format_html;
pub use html::[format_document_with_plugins](html/fn.format%5Fdocument%5Fwith%5Fplugins.html "fn comrak::html::format_document_with_plugins") as format_html_with_plugins;
Adapter traits for plugins.
Included from https://github.com/SimonSapin/rust-forest/blob/5783c8be8680b84c0438638bdee07d4e4aca40ac/arena-tree/lib.rs. MIT license (per Cargo.toml).
HTML renderering infrastructure for the CommonMark AST, as well as helper functions. format_document and format_document_with_pluginsuse the standard formatter. Thecreate_formatter! macro allows specialisation of formatting for specific node types.
The CommonMark AST.
Plugins for enhancing the default implementation of comrak can be defined in this module.
Create a formatter with specialised rules for certain node types.
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.
Use builder syntax to set the inputs and finish with build().
Umbrella options struct.
Options for parser functions.
Use builder syntax to set the inputs and finish with build().
Umbrella plugins struct.
Use builder syntax to set the inputs and finish with build().
Options for formatter functions.
Use builder syntax to set the inputs and finish with build().
Plugins for alternative rendering.
Use builder syntax to set the inputs and finish with build().
A reference link’s resolved details.
Options for bulleted list redering in markdown. See link_style
in RenderOptions for more details.
Selects between wikilinks with the title first or the URL first.
The type of the callback used when a reference link is encountered with no matching reference.
Trait for link and image URL rewrite extensions.
Formats an AST as CommonMark, modified by the given options.
format_commonmark_with_plugins
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.
markdown_to_commonmark_xml_with_plugins
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_callbackDeprecated
Parse a Markdown document to an AST, specifyingParseOptions::broken_link_callback.
Return the version of the crate.
Legacy naming of ExtensionOptions
Legacy naming of Options
Legacy naming of ParseOptions
Legacy naming of Plugins
Legacy naming of RenderOptions
Legacy naming of RenderPlugins