#pretty #print #format #commonmark #markdown

prettify-cmark

Pretty-printing for CommonMark documents

3 releases

0.1.2 Jan 21, 2018
0.1.1 Jan 21, 2018
0.1.0 Jan 21, 2018

#64 in Value formatting

Download history 6/week @ 2019-11-27 3/week @ 2019-12-04 129/week @ 2019-12-11 3/week @ 2019-12-25 3/week @ 2020-01-08 15/week @ 2020-01-15 1/week @ 2020-01-29 4/week @ 2020-02-12 6/week @ 2020-02-19 19/week @ 2020-02-26 6/week @ 2020-03-04 3/week @ 2020-03-11

61 downloads per month

MIT license

21KB
440 lines

prettify-cmark

Pretty-printing for CommonMark documents.

Build Status crates

Documentation

Installation

Add this to your Cargo.toml:

[dependencies]
prettify-cmark = "0.1"

Examples

extern crate pulldown_cmark;
extern crate prettify_cmark;

use pulldown_cmark::Parser;
use prettify_cmark::PrettyPrinter;

fn main() {
    let events = Parser::new("Lorem _ipsum_ dolor `sit`.");
    let mut printer = PrettyPrinter::default();
    printer.push_events(events).unwrap();

    assert_eq!(printer.into_inner(), "Lorem *ipsum* dolor `sit`.")
}

lib.rs:

Pretty-printing for CommonMark documents.

Simple API

For simple use-cases, the prettify function can be used to parse and pretty-print a CommonMark document.

use prettify_cmark::prettify;

let output = prettify("Lorem __ipsum__ dolor `sit` amet!");

assert_eq!(output,  "Lorem **ipsum** dolor `sit` amet!")

Advanced API

For more advanced use-cases, this crate is designed to work well together with the pulldown-cmark crate.

It provides a PrettyPrinter which wraps around an output type (such as String), and into which events can be pushed that have been obtained from pulldown-cmark.

# extern crate pulldown_cmark;
# extern crate prettify_cmark;
use pulldown_cmark::Parser;
use prettify_cmark::PrettyPrinter;

# fn main() {
let events = Parser::new("Lorem _ipsum_ dolor `sit`.");
let mut printer = PrettyPrinter::default();
printer.push_events(events).unwrap();

assert_eq!(printer.into_inner(), "Lorem *ipsum* dolor `sit`.")
# }

Dependencies

~450KB
~11K SLoC