extern crate markdown; use markdown::{ mdast::{Heading, Node, Root, Text}, to_html, to_html_with_options, to_mdast, unist::Position, Constructs, Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn heading_atx() -> Result<(), String> { assert_eq!( to_html("# foo"), "

foo

", "should support a heading w/ rank 1" ); assert_eq!( to_html("## foo"), "

foo

", "should support a heading w/ rank 2" ); assert_eq!( to_html("### foo"), "

foo

", "should support a heading w/ rank 3" ); assert_eq!( to_html("#### foo"), "

foo

", "should support a heading w/ rank 4" ); assert_eq!( to_html("##### foo"), "
foo
", "should support a heading w/ rank 5" ); assert_eq!( to_html("###### foo"), "
foo
", "should support a heading w/ rank 6" ); assert_eq!( to_html("####### foo"), "

####### foo

", "should not support a heading w/ rank 7" ); assert_eq!( to_html("#5 bolt"), "

#5 bolt

", "should not support a heading for a number sign not followed by whitespace (1)" ); assert_eq!( to_html("#hashtag"), "

#hashtag

", "should not support a heading for a number sign not followed by whitespace (2)" ); assert_eq!( to_html("\\## foo"), "

## foo

", "should not support a heading for an escaped number sign" ); assert_eq!( to_html("# foo *bar* \\*baz\\*"), "

foo bar *baz*

", "should support text content in headings" ); assert_eq!( to_html("# foo "), "

foo

", "should support arbitrary initial and final whitespace" ); assert_eq!( to_html(" ### foo"), "

foo

", "should support an initial space" ); assert_eq!( to_html(" ## foo"), "

foo

", "should support two initial spaces" ); assert_eq!( to_html(" # foo"), "

foo

", "should support three initial spaces" ); assert_eq!( to_html(" # foo"), "
# foo\n
", "should not support four initial spaces" ); assert_eq!( to_html("foo\n # bar"), "

foo\n# bar

", "should not support four initial spaces when interrupting" ); assert_eq!( to_html("## foo ##"), "

foo

", "should support a closing sequence (1)" ); assert_eq!( to_html(" ### bar ###"), "

bar

", "should support a closing sequence (2)" ); assert_eq!( to_html("# foo ##################################"), "

foo

", "should support a closing sequence w/ an arbitrary number of number signs (1)" ); assert_eq!( to_html("##### foo ##"), "
foo
", "should support a closing sequence w/ an arbitrary number of number signs (2)" ); assert_eq!( to_html("### foo ### "), "

foo

", "should support trailing whitespace after a closing sequence" ); assert_eq!( to_html("### foo ### b"), "

foo ### b

", "should not support other content after a closing sequence" ); assert_eq!( to_html("# foo#"), "

foo#

", "should not support a closing sequence w/o whitespace before it" ); assert_eq!( to_html("### foo \\###"), "

foo ###

", "should not support an “escaped” closing sequence (1)" ); assert_eq!( to_html("## foo #\\##"), "

foo ###

", "should not support an “escaped” closing sequence (2)" ); assert_eq!( to_html("# foo \\#"), "

foo #

", "should not support an “escaped” closing sequence (3)" ); assert_eq!( to_html("****\n## foo\n****"), "
\n

foo

\n
", "should support atx headings when not surrounded by blank lines" ); assert_eq!( to_html("Foo bar\n# baz\nBar foo"), "

Foo bar

\n

baz

\n

Bar foo

", "should support atx headings interrupting paragraphs" ); assert_eq!( to_html("## \n#\n### ###"), "

\n

\n

", "should support empty atx headings (1)" ); assert_eq!( to_html("#\na\n# b"), "

\n

a

\n

b

", "should support empty atx headings (2)" ); assert_eq!( to_html("> #\na"), "
\n

\n
\n

a

", "should not support lazyness (1)" ); assert_eq!( to_html("> a\n#"), "
\n

a

\n
\n

", "should not support lazyness (2)" ); assert_eq!( to_html_with_options( "# a", &Options { parse: ParseOptions { constructs: Constructs { heading_atx: false, ..Constructs::default() }, ..ParseOptions::default() }, ..Options::default() } )?, "

# a

", "should support turning off heading (atx)" ); assert_eq!( to_mdast("## alpha #", &ParseOptions::default())?, Node::Root(Root { children: vec![Node::Heading(Heading { depth: 2, children: vec![Node::Text(Text { value: "alpha".into(), position: Some(Position::new(1, 4, 3, 1, 9, 8)) }),], position: Some(Position::new(1, 1, 0, 1, 11, 10)) })], position: Some(Position::new(1, 1, 0, 1, 11, 10)) }), "should support heading (atx) as `Heading`s in mdast" ); Ok(()) }