3 releases
Uses old Rust 2015
0.1.2 | Jan 21, 2018 |
---|---|
0.1.1 | Jan 21, 2018 |
0.1.0 | Jan 21, 2018 |
#31 in #common-mark
21KB
440 lines
prettify-cmark
Pretty-printing for CommonMark documents.
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
.
use pulldown_cmark::Parser;
use prettify_cmark::PrettyPrinter;
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
~1MB
~17K SLoC