Module comrak
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 ;
let markdown = "# Hello\n\nThis is **bold** and *italic*.";
let html = markdown_to_html;
assert!;
assert!;
assert!;
Enabling GitHub Flavored Markdown extensions:
use ;
let mut 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;
assert!;
assert!;
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.
- plugins Plugin definitions.
Functions
- 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.
- version Return the version of the crate.
Type Aliases
- Arena Convenience type alias for arena used to hold nodes.
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.