Rust port of github's cmark-gfm
.
Usage
A binary is included which does everything you typically want:
$ comrak --help
comrak 0.2.6
Ashe Connor <kivikakk@github.com>
A 100% CommonMark-compatible GitHub Flavored Markdown parser and formatter
USAGE:
comrak [FLAGS] [OPTIONS] [--] [FILE]...
FLAGS:
--footnotes Parse footnotes
--github-pre-lang Use GitHub-style <pre lang> for code blocks
--hardbreaks Treat newlines as hard line breaks
-h, --help Prints help information
--prepare-regexes Prepare regexes up front for benchmarking
-V, --version Prints version information
OPTIONS:
-e, --extension <EXTENSION>... Specify an extension name to use [values: strikethrough, tagfilter, table, autolink, tasklist, superscript, footnotes]
-t, --to <FORMAT> Specify output format [default: html] [values: html, commonmark]
--header-ids <PREFIX> Use the Comrak header IDs extension, with the given ID prefix
--width <WIDTH> Specify wrap width (0 = nowrap) [default: 0]
ARGS:
<FILE>... The CommonMark file to parse; or standard input if none passed
And there's a Rust interface. You can use comrak::markdown_to_html
directly:
use ;
assert_eq!;
Or you can parse the input into an AST yourself, manipulate it, and then use your desired formatter:
extern crate comrak;
extern crate typed_arena;
use Arena;
use ;
use ;
// The returned nodes are created in the supplied Arena, and are bound by its lifetime.
let arena = new;
let root = parse_document;
iter_nodes;
let mut html = vec!;
format_html.unwrap;
assert_eq!;
Extensions
Comrak supports the five extensions to CommonMark defined in the GitHub Flavored Markdown Spec:
as well as superscript and footnotes.
By default none are enabled; they are individually enabled with each parse by
setting the appropriate values in the
ComrakOptions
struct.
Legal
Copyright (c) 2017, Ashe Connor. Licensed under the 2-Clause BSD License.
cmark
itself is is copyright (c) 2014, John MacFarlane.
See COPYING for all the details.
Contributors
Thank you for PRs and issues opened!