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§
- adapters
- Adapter traits for plugins.
- arena_
tree - Included from https://github.com/SimonSapin/rust-forest/blob/5783c8be8680b84c0438638bdee07d4e4aca40ac/arena-tree/lib.rs. MIT license (per Cargo.toml).
- html
- HTML renderering infrastructure for the CommonMark AST, as well as helper
functions.
format_document
andformat_document_with_plugins
use the standard formatter. Thecreate_formatter!
macro allows specialisation of formatting for specific node types. - nodes
- The CommonMark AST.
- plugins
- Plugins for enhancing the default implementation of comrak can be defined in this module.
Macros§
- create_
formatter - Create a formatter with specialised rules for certain node types.
Structs§
- Anchorizer
- Converts header strings to canonical, unique, but still human-readable, anchors.
- Arena
- An arena of objects of type
T
. - Broken
Link Reference - Struct to the broken link callback, containing details on the link reference which failed to find a match.
- Extension
Options - Options to select extensions.
- Extension
Options Builder - Use builder syntax to set the inputs and finish with
build()
. - Options
- Umbrella options struct.
- Parse
Options - Options for parser functions.
- Parse
Options Builder - Use builder syntax to set the inputs and finish with
build()
. - Plugins
- Umbrella plugins struct.
- Plugins
Builder - Use builder syntax to set the inputs and finish with
build()
. - Render
Options - Options for formatter functions.
- Render
Options Builder - Use builder syntax to set the inputs and finish with
build()
. - Render
Plugins - Plugins for alternative rendering.
- Render
Plugins Builder - Use builder syntax to set the inputs and finish with
build()
. - Resolved
Reference - A reference link’s resolved details.
Enums§
- List
Style Type - Options for bulleted list redering in markdown. See
link_style
inRenderOptions
for more details. - Wiki
Links Mode - Selects between wikilinks with the title first or the URL first.
Traits§
- Broken
Link Callback - The type of the callback used when a reference link is encountered with no matching reference.
- URLRewriter
- Trait for link and image URL rewrite extensions.
Functions§
- format_
commonmark - 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.
- format_
xml - Formats an AST as HTML, modified by the given options.
- format_
xml_ with_ plugins - Formats an AST as HTML, modified by the given options. Accepts custom plugins.
- markdown_
to_ commonmark - Render Markdown back to CommonMark.
- markdown_
to_ commonmark_ xml - 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.
- markdown_
to_ html - Render Markdown to HTML.
- markdown_
to_ html_ with_ plugins - Render Markdown to HTML using plugins.
- parse_
document - Parse a Markdown document to an AST.
- parse_
document_ with_ broken_ link_ callback Deprecated - Parse a Markdown document to an AST, specifying
ParseOptions::broken_link_callback
. - version
- Return the version of the crate.
Type Aliases§
- Comrak
Extension Options - Legacy naming of
ExtensionOptions
- Comrak
Options - Legacy naming of
Options
- Comrak
Parse Options - Legacy naming of
ParseOptions
- Comrak
Plugins - Legacy naming of
Plugins
- Comrak
Render Options - Legacy naming of
RenderOptions
- Comrak
Render Plugins - Legacy naming of
RenderPlugins