Expand description
CommonMark and GitHub Flavored Markdown parser.
comrak is a 100% CommonMark-compatible Markdown parser
that also supports GitHub Flavored Markdown (GFM) extensions.
It can render Markdown to HTML, CommonMark, or manipulate the AST directly.
The main entry point is markdown_to_html for simple conversions,
or parse_document for AST manipulation.
Options are configured via Options which controls
extensions like tables, strikethrough, and autolinks.
§Examples
Basic Markdown to HTML conversion:
use comrak::{markdown_to_html, Options};
let markdown = "# Hello\n\nThis is **bold** and *italic*.";
let html = markdown_to_html(markdown, &Options::default());
assert!(html.contains("<h1>"));
assert!(html.contains("<strong>bold</strong>"));
assert!(html.contains("<em>italic</em>"));Enabling GitHub Flavored Markdown extensions:
use comrak::{markdown_to_html, Options};
let mut options = Options::default();
options.extension.strikethrough = true;
options.extension.table = true;
options.extension.autolink = true;
let markdown = "~~deleted~~ and https://example.com";
let html = markdown_to_html(markdown, &options);
assert!(html.contains("<del>deleted</del>"));
assert!(html.contains("<a href="));Modules§
- adapters
- Adapter traits for plugins.
- arena_
tree - A DOM-like tree data structure based on
&Nodereferences. - html
- HTML rendering 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§
- 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_
html - Formats an AST as HTML, modified by the given options.
- format_
html_ with_ plugins - Formats an AST as HTML, 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.