extern crate pulldown_cmark; extern crate cmark_hamlet; use std::fmt::Write; use pulldown_cmark::Parser; use pulldown_cmark::Options; use cmark_hamlet::Adapter; fn to_html(md: &str) -> String { let ada = Adapter::new(Parser::new_ext(md, Options::all()), false); let mut res = String::from(""); for token in ada { write!(res, "{}", token).unwrap(); } res } #[test] fn simple() { assert_eq!(to_html("foo bar"), "
foo bar
"); assert_eq!(to_html("foo\nbar"), "foo\nbar
"); assert_eq!(to_html("foo\n\nbar"), "foo
bar
"); assert_eq!(to_html("foo\n\nbar"), "foo
bar
"); assert_eq!(to_html("foo\n- - -\nbar"), "foo
bar
"); assert_eq!(to_html("`foo bar`"), "foo bar
foo bar
"); assert_eq!(to_html("_foo bar_"), "foo bar
"); assert_eq!(to_html("> foo\n>\n> bar"), ""); } #[test] fn code_block() { assert_eq!( to_html("```\n\ code\n\n\ block\n\ ```"), "foo
bar
code\n\nblock\n
"
);
assert_eq!(
to_html("```sh\n\
code\n\n\
block\n\
```"),
"code\n\nblock\n
"
);
}
#[test]
fn image() {
assert_eq!(
to_html("![](/link/to/image)"),
""
);
assert_eq!(
to_html("![foo](/link/to/image)"),
""
);
assert_eq!(
to_html("![](/link/to/image \"bar\")"),
""
);
assert_eq!(
to_html("![foo](/link/to/image \"bar\")"),
""
);
assert_eq!(
to_html("![foo] bar\n\n[foo]: /link/to/image \"bar\""),
"bar
" ); } #[test] fn link() { assert_eq!( to_html("foo bar
" ); } #[test] fn list() { assert_eq!( to_html("- hello\n\ - world"), "let x;\n
hello
goo
world
head1 | head2 |
---|---|
foo | bar |