extern crate micromark; use micromark::{micromark, micromark_with_options, Options}; const DANGER: &Options = &Options { allow_dangerous_html: true, allow_dangerous_protocol: true, default_line_ending: None, }; #[test] fn attention() { // Rule 1. assert_eq!( micromark("*foo bar*"), "
foo bar
", "should support emphasis w/ `*`" ); assert_eq!( micromark("a * foo bar*"), "a * foo bar*
", "should not support emphasis if the opening is not left flanking (1)" ); assert_eq!( micromark("a*\"foo\"*"), "a*"foo"*
", "should not support emphasis if the opening is not left flanking (2b)" ); assert_eq!( micromark("* a *"), "* a *
", "should not support emphasis unicode whitespace either" ); assert_eq!( micromark("foo*bar*"), "foobar
", "should support intraword emphasis w/ `*` (1)" ); assert_eq!( micromark("5*6*78"), "5678
", "should support intraword emphasis w/ `*` (2)" ); // Rule 2. assert_eq!( micromark("_foo bar_"), "foo bar
", "should support emphasis w/ `_`" ); assert_eq!( micromark("_ foo bar_"), "_ foo bar_
", "should not support emphasis if the opening is followed by whitespace" ); assert_eq!( micromark("a_\"foo\"_"), "a_"foo"_
", "should not support emphasis if the opening is preceded by something else and followed by punctuation" ); assert_eq!( micromark("foo_bar_"), "foo_bar_
", "should not support intraword emphasis (1)" ); assert_eq!( micromark("5_6_78"), "5_6_78
", "should not support intraword emphasis (2)" ); assert_eq!( micromark("пристаням_стремятся_"), "пристаням_стремятся_
", "should not support intraword emphasis (3)" ); assert_eq!( micromark("aa_\"bb\"_cc"), "aa_"bb"_cc
", "should not support emphasis if the opening is right flanking and the closing is left flanking" ); assert_eq!( micromark("foo-_(bar)_"), "foo-(bar)
", "should support emphasis if the opening is both left and right flanking, if it’s preceded by punctuation" ); // Rule 3. assert_eq!( micromark("_foo*"), "_foo*
", "should not support emphasis if opening and closing markers don’t match" ); assert_eq!( micromark("*foo bar *"), "*foo bar *
", "should not support emphasis w/ `*` if the closing markers are preceded by whitespace" ); assert_eq!( micromark("*foo bar\n*"), "*foo bar\n*
", "should not support emphasis w/ `*` if the closing markers are preceded by a line break (also whitespace)" ); assert_eq!( micromark("*(*foo)"), "*(*foo)
", "should not support emphasis w/ `*` if the closing markers are not right flanking" ); assert_eq!( micromark("*(*foo*)*"), "(foo)
", "should support nested emphasis" ); // Rule 4. assert_eq!( micromark("_foo bar _"), "_foo bar _
", "should not support emphasis if the closing `_` is preceded by whitespace" ); assert_eq!( micromark("_(_foo)"), "_(_foo)
", "should not support emphasis w/ `_` if the closing markers are not right flanking" ); assert_eq!( micromark("_(_foo_)_"), "(foo)
", "should support nested emphasis w/ `_`" ); assert_eq!( micromark("_foo_bar"), "_foo_bar
", "should not support intraword emphasis w/ `_` (1)" ); assert_eq!( micromark("_пристаням_стремятся"), "_пристаням_стремятся
", "should not support intraword emphasis w/ `_` (2)" ); assert_eq!( micromark("_foo_bar_baz_"), "foo_bar_baz
", "should not support intraword emphasis w/ `_` (3)" ); assert_eq!( micromark("_(bar)_."), "(bar).
", "should support emphasis if the opening is both left and right flanking, if it’s followed by punctuation" ); // Rule 5. assert_eq!( micromark("**foo bar**"), "foo bar
", "should support strong emphasis" ); assert_eq!( micromark("** foo bar**"), "** foo bar**
", "should not support strong emphasis if the opening is followed by whitespace" ); assert_eq!( micromark("a**\"foo\"**"), "a**"foo"**
", "should not support strong emphasis if the opening is preceded by something else and followed by punctuation" ); assert_eq!( micromark("foo**bar**"), "foobar
", "should support strong intraword emphasis" ); // Rule 6. assert_eq!( micromark("__foo bar__"), "foo bar
", "should support strong emphasis w/ `_`" ); assert_eq!( micromark("__ foo bar__"), "__ foo bar__
", "should not support strong emphasis if the opening is followed by whitespace" ); assert_eq!( micromark("__\nfoo bar__"), "__\nfoo bar__
", "should not support strong emphasis if the opening is followed by a line ending (also whitespace)" ); assert_eq!( micromark("a__\"foo\"__"), "a__"foo"__
", "should not support strong emphasis if the opening is preceded by something else and followed by punctuation" ); assert_eq!( micromark("foo__bar__"), "foo__bar__
", "should not support strong intraword emphasis w/ `_` (1)" ); assert_eq!( micromark("5__6__78"), "5__6__78
", "should not support strong intraword emphasis w/ `_` (2)" ); assert_eq!( micromark("пристаням__стремятся__"), "пристаням__стремятся__
", "should not support strong intraword emphasis w/ `_` (3)" ); assert_eq!( micromark("__foo, __bar__, baz__"), "foo, bar, baz
", "should support nested strong emphasis" ); assert_eq!( micromark("foo-__(bar)__"), "foo-(bar)
", "should support strong emphasis if the opening is both left and right flanking, if it’s preceded by punctuation" ); // Rule 7. assert_eq!( micromark("**foo bar **"), "**foo bar **
", "should not support strong emphasis w/ `*` if the closing is preceded by whitespace" ); assert_eq!( micromark("**(**foo)"), "**(**foo)
", "should not support strong emphasis w/ `*` if the closing is preceded by punctuation and followed by something else" ); assert_eq!( micromark("*(**foo**)*"), "(foo)
", "should support strong emphasis in emphasis" ); assert_eq!( micromark( "**Gomphocarpus (*Gomphocarpus physocarpus*, syn.\n*Asclepias physocarpa*)**" ), "Gomphocarpus (Gomphocarpus physocarpus, syn.\nAsclepias physocarpa)
", "should support emphasis in strong emphasis (1)" ); assert_eq!( micromark("**foo \"*bar*\" foo**"), "foo "bar" foo
", "should support emphasis in strong emphasis (2)" ); assert_eq!( micromark("**foo**bar"), "foobar
", "should support strong intraword emphasis" ); // Rule 8. assert_eq!( micromark("__foo bar __"), "__foo bar __
", "should not support strong emphasis w/ `_` if the closing is preceded by whitespace" ); assert_eq!( micromark("__(__foo)"), "__(__foo)
", "should not support strong emphasis w/ `_` if the closing is preceded by punctuation and followed by something else" ); assert_eq!( micromark("_(__foo__)_"), "(foo)
", "should support strong emphasis w/ `_` in emphasis" ); assert_eq!( micromark("__foo__bar"), "__foo__bar
", "should not support strong intraword emphasis w/ `_` (1)" ); assert_eq!( micromark("__пристаням__стремятся"), "__пристаням__стремятся
", "should not support strong intraword emphasis w/ `_` (2)" ); assert_eq!( micromark("__foo__bar__baz__"), "foo__bar__baz
", "should not support strong intraword emphasis w/ `_` (3)" ); assert_eq!( micromark("__(bar)__."), "(bar).
", "should support strong emphasis if the opening is both left and right flanking, if it’s followed by punctuation" ); // Rule 9. assert_eq!( micromark("*foo [bar](/url)*"), "foo bar
", "should support content in emphasis" ); assert_eq!( micromark("*foo\nbar*"), "foo\nbar
", "should support line endings in emphasis" ); assert_eq!( micromark("_foo __bar__ baz_"), "foo bar baz
", "should support nesting emphasis and strong (1)" ); assert_eq!( micromark("_foo _bar_ baz_"), "foo bar baz
", "should support nesting emphasis and strong (2)" ); assert_eq!( micromark("__foo_ bar_"), "foo bar
", "should support nesting emphasis and strong (3)" ); assert_eq!( micromark("*foo *bar**"), "foo bar
", "should support nesting emphasis and strong (4)" ); assert_eq!( micromark("*foo **bar** baz*"), "foo bar baz
", "should support nesting emphasis and strong (5)" ); assert_eq!( micromark("*foo**bar**baz*"), "foobarbaz
", "should support nesting emphasis and strong (6)" ); assert_eq!( micromark("*foo**bar*"), "foo**bar
", "should not support adjacent emphasis in certain cases" ); assert_eq!( micromark("***foo** bar*"), "foo bar
", "complex (1)" ); assert_eq!( micromark("*foo **bar***"), "foo bar
", "complex (2)" ); assert_eq!( micromark("*foo**bar***"), "foobar
", "complex (3)" ); assert_eq!( micromark("foo***bar***baz"), "foobarbaz
", "complex (a)" ); assert_eq!( micromark("foo******bar*********baz"), "foobar***baz
", "complex (b)" ); assert_eq!( micromark("*foo **bar *baz* bim** bop*"), "foo bar baz bim bop
", "should support indefinite nesting of emphasis (1)" ); assert_eq!( micromark("*foo [*bar*](/url)*"), "foo bar
", "should support indefinite nesting of emphasis (2)" ); assert_eq!( micromark("** is not an empty emphasis"), "** is not an empty emphasis
", "should not support empty emphasis" ); assert_eq!( micromark("**** is not an empty emphasis"), "**** is not an empty emphasis
", "should not support empty strong emphasis" ); // Rule 10. assert_eq!( micromark("**foo [bar](/url)**"), "foo bar
", "should support content in strong emphasis" ); assert_eq!( micromark("**foo\nbar**"), "foo\nbar
", "should support line endings in emphasis" ); assert_eq!( micromark("__foo _bar_ baz__"), "foo bar baz
", "should support nesting emphasis and strong (1)" ); assert_eq!( micromark("__foo __bar__ baz__"), "foo bar baz
", "should support nesting emphasis and strong (2)" ); assert_eq!( micromark("____foo__ bar__"), "foo bar
", "should support nesting emphasis and strong (3)" ); assert_eq!( micromark("**foo **bar****"), "foo bar
", "should support nesting emphasis and strong (4)" ); assert_eq!( micromark("**foo *bar* baz**"), "foo bar baz
", "should support nesting emphasis and strong (5)" ); assert_eq!( micromark("**foo*bar*baz**"), "foobarbaz
", "should support nesting emphasis and strong (6)" ); assert_eq!( micromark("***foo* bar**"), "foo bar
", "should support nesting emphasis and strong (7)" ); assert_eq!( micromark("**foo *bar***"), "foo bar
", "should support nesting emphasis and strong (8)" ); assert_eq!( micromark("**foo *bar **baz**\nbim* bop**"), "foo bar baz\nbim bop
", "should support indefinite nesting of emphasis (1)" ); assert_eq!( micromark("**foo [*bar*](/url)**"), "foo bar
", "should support indefinite nesting of emphasis (2)" ); assert_eq!( micromark("__ is not an empty emphasis"), "__ is not an empty emphasis
", "should not support empty emphasis" ); assert_eq!( micromark("____ is not an empty emphasis"), "____ is not an empty emphasis
", "should not support empty strong emphasis" ); // Rule 11. assert_eq!( micromark("foo ***"), "foo ***
", "should not support emphasis around the same marker" ); assert_eq!( micromark("foo *\\**"), "foo *
", "should support emphasis around an escaped marker" ); assert_eq!( micromark("foo *_*"), "foo _
", "should support emphasis around the other marker" ); assert_eq!( micromark("foo *****"), "foo *****
", "should not support strong emphasis around the same marker" ); assert_eq!( micromark("foo **\\***"), "foo *
", "should support strong emphasis around an escaped marker" ); assert_eq!( micromark("foo **_**"), "foo _
", "should support strong emphasis around the other marker" ); assert_eq!( micromark("**foo*"), "*foo
", "should support a superfluous marker at the start of emphasis" ); assert_eq!( micromark("*foo**"), "foo*
", "should support a superfluous marker at the end of emphasis" ); assert_eq!( micromark("***foo**"), "*foo
", "should support a superfluous marker at the start of strong" ); assert_eq!( micromark("****foo*"), "***foo
", "should support multiple superfluous markers at the start of strong" ); assert_eq!( micromark("**foo***"), "foo*
", "should support a superfluous marker at the end of strong" ); assert_eq!( micromark("*foo****"), "foo***
", "should support multiple superfluous markers at the end of strong" ); // Rule 12. assert_eq!( micromark("foo ___"), "foo ___
", "should not support emphasis around the same marker" ); assert_eq!( micromark("foo _\\__"), "foo _
", "should support emphasis around an escaped marker" ); assert_eq!( micromark("foo _X_"), "foo X
", "should support emphasis around the other marker" ); assert_eq!( micromark("foo _____"), "foo _____
", "should not support strong emphasis around the same marker" ); assert_eq!( micromark("foo __\\___"), "foo _
", "should support strong emphasis around an escaped marker" ); assert_eq!( micromark("foo __X__"), "foo X
", "should support strong emphasis around the other marker" ); assert_eq!( micromark("__foo_"), "_foo
", "should support a superfluous marker at the start of emphasis" ); assert_eq!( micromark("_foo__"), "foo_
", "should support a superfluous marker at the end of emphasis" ); assert_eq!( micromark("___foo__"), "_foo
", "should support a superfluous marker at the start of strong" ); assert_eq!( micromark("____foo_"), "___foo
", "should support multiple superfluous markers at the start of strong" ); assert_eq!( micromark("__foo___"), "foo_
", "should support a superfluous marker at the end of strong" ); assert_eq!( micromark("_foo____"), "foo___
", "should support multiple superfluous markers at the end of strong" ); // Rule 13. assert_eq!( micromark("**foo**"), "foo
", "should support strong w/ `*`" ); assert_eq!( micromark("*_foo_*"), "foo
", "should support emphasis directly in emphasis w/ `_` in `*`" ); assert_eq!( micromark("__foo__"), "foo
", "should support strong w/ `_`" ); assert_eq!( micromark("_*foo*_"), "foo
", "should support emphasis directly in emphasis w/ `*` in `_`" ); assert_eq!( micromark("****foo****"), "foo
", "should support strong emphasis directly in strong emphasis w/ `*`" ); assert_eq!( micromark("____foo____"), "foo
", "should support strong emphasis directly in strong emphasis w/ `_`" ); assert_eq!( micromark("******foo******"), "foo
", "should support indefinite strong emphasis" ); // Rule 14. assert_eq!( micromark("***foo***"), "foo
", "should support strong directly in emphasis w/ `*`" ); assert_eq!( micromark("___foo___"), "foo
", "should support strong directly in emphasis w/ `_`" ); // Rule 15. // To do: interleaving attention. // assert_eq!( // micromark("*foo _bar* baz_"), // "foo _bar baz_
", // "should not support mismatched emphasis" // ); // To do: interleaving attention. // assert_eq!( // micromark("*foo __bar *baz bim__ bam*"), // "foo bar *baz bim bam
", // "should not support mismatched strong emphasis" // ); // Rule 16. assert_eq!( micromark("**foo **bar baz**"), "**foo bar baz
", "should not shortest strong possible" ); assert_eq!( micromark("*foo *bar baz*"), "*foo bar baz
", "should not shortest emphasis possible" ); // Rule 17. // To do: attention/link interplay. // assert_eq!( // micromark("*[bar*](/url)"), // "*bar*
", // "should not mismatch inside links (1)" // ); // To do: attention/link interplay. // assert_eq!( // micromark("_[bar_](/url)"), // "_bar_
", // "should not mismatch inside links (1)" // ); assert_eq!( micromark_with_options("*", DANGER), "*
", "should not end inside HTML" ); assert_eq!( micromark_with_options("*", DANGER), "*
", "should not end emphasis inside HTML" ); assert_eq!( micromark_with_options("**", DANGER), "", "should not end strong inside HTML (1)" ); assert_eq!( micromark_with_options("__", DANGER), "", "should not end strong inside HTML (2)" ); assert_eq!( micromark("*a `*`*"), "a *
a _
*a*
", // "should support turning off attention" // ); }