Expand description
A 100% CommonMark and GFM compatible Markdown parser.
Source repository and detailed README
is at
github.com/kivikakk/comrak.
You can use comrak::markdown_to_html
directly:
use comrak::{markdown_to_html, Options};
assert_eq!(
markdown_to_html("Olá, **世界**!", &Options::default()),
"<p>Olá, <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::{NodeValue};
let arena = Arena::new();
let root = parse_document(
&arena,
"Hello, pretty world!\n\n1. Do you like [pretty](#) paintings?\n2. Or *pretty* music?\n",
&Options::default());
for node in root.descendants() {
if let NodeValue::Text(ref mut text) = node.data.borrow_mut().value {
*text = text.to_mut().replace("pretty", "beautiful").into()
}
}
let mut html = String::new();
format_html(root, &Options::default(), &mut html).unwrap();
assert_eq!(
&html,
"<p>Hello, beautiful world!</p>\n\
<ol>\n\
<li>Do you like <a href=\"#\">beautiful</a> paintings?</li>\n\
<li>Or <em>beautiful</em> music?</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 - A DOM-like tree data structure based on
&Node
references. - html
- HTML renderering infrastructure for the CommonMark AST, as well as helper functions.
- nodes
- The CommonMark AST.
- options
- Configuration for the parser and renderer. Extensions affect both.
- plugins
- Plugin definitions.
Macros§
- create_
formatter - Create a formatter with specialised rules for certain node types.
- node_
matches - Shorthand for checking if a node’s value matches the given expression.
Structs§
- Anchorizer
- Converts header strings to canonical, unique, but still human-readable, anchors.
- Arena
- An arena of objects of type
T
. - Options
- Umbrella options struct.
- Resolved
Reference - A reference link’s resolved details.
Functions§
- escape_
commonmark_ inline - Escapes the input, rendering it suitable for inclusion in a CommonMark document in a place where regular inline parsing is occurring. Note that this is not minimal — there will be more escaping backslashes in the output than is strictly necessary. The rendering will not be affected, however.
- escape_
commonmark_ link_ destination - Escapes the input URL, rendering it suitable for inclusion as a link destination per the CommonMark spec.
- 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.
- markdown_
to_ commonmark_ xml_ with_ plugins - Render Markdown to CommonMark XML using plugins.
- 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.
- version
- Return the version of the crate.
Type Aliases§
- Broken
Link Reference Deprecated - Deprecated alias: use
options::BrokenLinkReference
instead ofBrokenLinkReference
. - Extension
Options Deprecated - Deprecated alias: use
options::Extension
instead ofExtensionOptions
. - Extension
Options Builder Deprecated bon
- Deprecated alias: use
options::ExtensionBuilder
instead ofExtensionOptionsBuilder
. - List
Style Type Deprecated - Deprecated alias: use
options::ListStyleType
instead of [ListStyleType ]
. - Parse
Options Deprecated - Deprecated alias: use
options::Parse
instead ofParseOptions
. - Parse
Options Builder Deprecated bon
- Deprecated alias: use
options::ParseBuilder
instead ofParseOptionsBuilder
. - Plugins
Deprecated - Deprecated alias: use
options::Plugins
instead ofPlugins
. - Plugins
Builder Deprecated bon
- Deprecated alias: use
options::PluginsBuilder
instead ofPluginsBuilder
. - Render
Options Deprecated - Deprecated alias: use
options::Render
instead of [RenderOptions ]
. - Render
Options Builder Deprecated bon
- Deprecated alias: use
options::RenderBuilder
instead of [RenderOptionsBuilder ]
. - Render
Plugins Deprecated - Deprecated alias: use
options::RenderPlugins
instead ofRenderPlugins
. - Render
Plugins Builder Deprecated bon
- Deprecated alias: use
options::RenderPluginsBuilder
instead ofRenderPluginsBuilder
. - Wiki
Links Mode Deprecated - Deprecated alias: use
options::WikiLinksMode
instead of [WikiLinksMode ]
.