Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Aug 14, 2020
1 parent 71172c4 commit c615b21
Show file tree
Hide file tree
Showing 11 changed files with 742 additions and 573 deletions.
5 changes: 2 additions & 3 deletions benches/progit.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![feature(test)]

extern crate test;
extern crate comrak;
extern crate test;

use comrak::{parse_document, format_html, Arena, ComrakOptions};
use comrak::{format_html, parse_document, Arena, ComrakOptions};
use test::Bencher;

#[bench]
Expand All @@ -21,4 +21,3 @@ fn bench_progit(b: &mut Bencher) {
format_html(root, &ComrakOptions::default(), &mut output).unwrap()
});
}

34 changes: 21 additions & 13 deletions examples/readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,45 @@ extern crate comrak;
fn small() {
use comrak::{markdown_to_html, ComrakOptions};

assert_eq!(markdown_to_html("Hello, **世界**!", &ComrakOptions::default()),
"<p>Hello, <strong>世界</strong>!</p>\n");
assert_eq!(
markdown_to_html("Hello, **世界**!", &ComrakOptions::default()),
"<p>Hello, <strong>世界</strong>!</p>\n"
);
}

fn large() {
use comrak::{parse_document, format_html, Arena, ComrakOptions};
use comrak::nodes::{AstNode, NodeValue};
use comrak::{format_html, parse_document, Arena, ComrakOptions};

// The returned nodes are created in the supplied Arena, and are bound by its lifetime.
let arena = Arena::new();

let root = parse_document(
&arena,
"This is my input.\n\n1. Also my input.\n2. Certainly my input.\n",
&ComrakOptions::default());
&ComrakOptions::default(),
);

fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F)
where F : Fn(&'a AstNode<'a>) {
where
F: Fn(&'a AstNode<'a>),
{
f(node);
for c in node.children() {
iter_nodes(c, f);
}
}

iter_nodes(root, &|node| {
match &mut node.data.borrow_mut().value {
&mut NodeValue::Text(ref mut text) => {
let orig = std::mem::replace(text, vec![]);
*text = String::from_utf8(orig).unwrap().replace("my", "your").as_bytes().to_vec();
}
_ => (),
iter_nodes(root, &|node| match &mut node.data.borrow_mut().value {
&mut NodeValue::Text(ref mut text) => {
let orig = std::mem::replace(text, vec![]);
*text = String::from_utf8(orig)
.unwrap()
.replace("my", "your")
.as_bytes()
.to_vec();
}
_ => (),
});

let mut html = vec![];
Expand All @@ -46,7 +53,8 @@ fn large() {
<ol>\n\
<li>Also your input.</li>\n\
<li>Certainly your input.</li>\n\
</ol>\n");
</ol>\n"
);
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/s-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const INDENT: usize = 4;
const CLOSE_NEWLINE: bool = false;

use comrak::nodes::{AstNode, NodeValue};
use comrak::{parse_document, Arena, ComrakOptions, ComrakExtensionOptions};
use comrak::{parse_document, Arena, ComrakExtensionOptions, ComrakOptions};
use std::env;
use std::error::Error;
use std::fs::File;
Expand Down
2 changes: 0 additions & 2 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
format_strings = false
reorder_imports = true
error_on_line_overflow = false
Loading

0 comments on commit c615b21

Please sign in to comment.