diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-10-14 10:49:28 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-10-14 10:49:28 +0200 |
commit | 246063fb7cd21a83beae5934f95b2795fb85df51 (patch) | |
tree | 5f82a11d17ea5468376693c7a0405ed71d7ae147 /tests | |
parent | 9cc1ad4a90616b7fb4ae7b425a5b9844887f4584 (diff) | |
download | markdown-rs-246063fb7cd21a83beae5934f95b2795fb85df51.tar.gz markdown-rs-246063fb7cd21a83beae5934f95b2795fb85df51.tar.bz2 markdown-rs-246063fb7cd21a83beae5934f95b2795fb85df51.zip |
Refactor to use default trait in tests
Diffstat (limited to 'tests')
42 files changed, 429 insertions, 543 deletions
diff --git a/tests/attention.rs b/tests/attention.rs index 1eef10d..d79432d 100644 --- a/tests/attention.rs +++ b/tests/attention.rs @@ -13,9 +13,9 @@ fn attention() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; // Rule 1. @@ -827,11 +827,11 @@ fn attention() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { attention: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>*a*</p>", @@ -839,7 +839,7 @@ fn attention() -> Result<(), String> { ); assert_eq!( - to_mdast("a *alpha* b **bravo** c.", &ParseOptions::default())?, + to_mdast("a *alpha* b **bravo** c.", &Default::default())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![ diff --git a/tests/autolink.rs b/tests/autolink.rs index 1b20e08..64f94e9 100644 --- a/tests/autolink.rs +++ b/tests/autolink.rs @@ -13,9 +13,9 @@ fn autolink() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -259,11 +259,11 @@ fn autolink() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { autolink: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p><a@b.co></p>", @@ -273,7 +273,7 @@ fn autolink() -> Result<(), String> { assert_eq!( to_mdast( "a <https://alpha.com> b <bravo@charlie.com> c.", - &ParseOptions::default() + &Default::default() )?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { diff --git a/tests/block_quote.rs b/tests/block_quote.rs index 970b82e..5d765e8 100644 --- a/tests/block_quote.rs +++ b/tests/block_quote.rs @@ -208,11 +208,11 @@ fn block_quote() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { block_quote: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>> # a\n> b\n> c</p>", @@ -220,7 +220,7 @@ fn block_quote() -> Result<(), String> { ); assert_eq!( - to_mdast("> a", &ParseOptions::default())?, + to_mdast("> a", &Default::default())?, Node::Root(Root { children: vec![Node::BlockQuote(BlockQuote { children: vec![Node::Paragraph(Paragraph { diff --git a/tests/character_escape.rs b/tests/character_escape.rs index 0546269..41cc68d 100644 --- a/tests/character_escape.rs +++ b/tests/character_escape.rs @@ -13,9 +13,9 @@ fn character_escape() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -93,11 +93,11 @@ fn character_escape() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { character_escape: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>\\> a</p>", @@ -105,7 +105,7 @@ fn character_escape() -> Result<(), String> { ); assert_eq!( - to_mdast("a \\* b", &ParseOptions::default())?, + to_mdast("a \\* b", &Default::default())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { diff --git a/tests/character_reference.rs b/tests/character_reference.rs index 0d72fff..ab253c4 100644 --- a/tests/character_reference.rs +++ b/tests/character_reference.rs @@ -55,9 +55,9 @@ fn character_reference() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<a href=\"öö.html\">", @@ -204,11 +204,11 @@ fn character_reference() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { character_reference: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>&amp;</p>", @@ -216,7 +216,7 @@ fn character_reference() -> Result<(), String> { ); assert_eq!( - to_mdast(" & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸\n# Ӓ Ϡ �\n" ആ ಫ", &ParseOptions::default())?, + to_mdast(" & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸\n# Ӓ Ϡ �\n" ആ ಫ", &Default::default())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { diff --git a/tests/code_fenced.rs b/tests/code_fenced.rs index e544ade..73bcb9a 100644 --- a/tests/code_fenced.rs +++ b/tests/code_fenced.rs @@ -269,11 +269,11 @@ fn code_fenced() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { code_fenced: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>```</p>", @@ -283,7 +283,7 @@ fn code_fenced() -> Result<(), String> { assert_eq!( to_mdast( "```js extra\nconsole.log(1)\nconsole.log(2)\n```", - &ParseOptions::default() + &Default::default() )?, Node::Root(Root { children: vec![Node::Code(Code { @@ -298,7 +298,7 @@ fn code_fenced() -> Result<(), String> { ); assert_eq!( - to_mdast("```\nasd", &ParseOptions::default())?, + to_mdast("```\nasd", &Default::default())?, Node::Root(Root { children: vec![Node::Code(Code { lang: None, @@ -312,7 +312,7 @@ fn code_fenced() -> Result<(), String> { ); assert_eq!( - to_mdast("```\rasd\r```", &ParseOptions::default())?, + to_mdast("```\rasd\r```", &Default::default())?, Node::Root(Root { children: vec![Node::Code(Code { lang: None, @@ -326,7 +326,7 @@ fn code_fenced() -> Result<(), String> { ); assert_eq!( - to_mdast("```\r\nasd\r\n```", &ParseOptions::default())?, + to_mdast("```\r\nasd\r\n```", &Default::default())?, Node::Root(Root { children: vec![Node::Code(Code { lang: None, diff --git a/tests/code_indented.rs b/tests/code_indented.rs index 6545ed6..66046c4 100644 --- a/tests/code_indented.rs +++ b/tests/code_indented.rs @@ -127,11 +127,11 @@ fn code_indented() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { code_indented: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -177,13 +177,13 @@ fn code_indented() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { code_indented: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, compile: CompileOptions { allow_dangerous_html: true, - ..CompileOptions::default() + ..Default::default() } } )?, @@ -206,7 +206,7 @@ fn code_indented() -> Result<(), String> { assert_eq!( to_mdast( "\tconsole.log(1)\n console.log(2)\n", - &ParseOptions::default() + &Default::default() )?, Node::Root(Root { children: vec![Node::Code(Code { diff --git a/tests/code_text.rs b/tests/code_text.rs index 2784398..482c46f 100644 --- a/tests/code_text.rs +++ b/tests/code_text.rs @@ -13,9 +13,9 @@ fn code_text() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -170,11 +170,11 @@ fn code_text() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { code_text: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>`a`</p>", @@ -182,7 +182,7 @@ fn code_text() -> Result<(), String> { ); assert_eq!( - to_mdast("a `alpha` b.", &ParseOptions::default())?, + to_mdast("a `alpha` b.", &Default::default())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![ diff --git a/tests/definition.rs b/tests/definition.rs index 5f9c286..46d9cf5 100644 --- a/tests/definition.rs +++ b/tests/definition.rs @@ -13,9 +13,9 @@ fn definition() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -497,11 +497,11 @@ fn definition() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { definition: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>[foo]: /url "title"</p>", @@ -509,7 +509,7 @@ fn definition() -> Result<(), String> { ); assert_eq!( - to_mdast("[a]: <b> 'c'", &ParseOptions::default())?, + to_mdast("[a]: <b> 'c'", &Default::default())?, Node::Root(Root { children: vec![Node::Definition(Definition { url: "b".into(), diff --git a/tests/frontmatter.rs b/tests/frontmatter.rs index b1380b6..7e647d9 100644 --- a/tests/frontmatter.rs +++ b/tests/frontmatter.rs @@ -13,11 +13,11 @@ fn frontmatter() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { frontmatter: true, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( diff --git a/tests/fuzz.rs b/tests/fuzz.rs index 819edf6..8d64ff2 100644 --- a/tests/fuzz.rs +++ b/tests/fuzz.rs @@ -1,5 +1,5 @@ extern crate markdown; -use markdown::{to_html, to_html_with_options, CompileOptions, Constructs, Options, ParseOptions}; +use markdown::{to_html, to_html_with_options, Options}; use pretty_assertions::assert_eq; #[test] @@ -13,19 +13,7 @@ fn fuzz() -> Result<(), String> { // The first link is stopped by the `+` (so it’s `a@b.c`), but the next // link overlaps it (`b.c+d@e.f`). assert_eq!( - to_html_with_options( - "a@b.c+d@e.f", - &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, - compile: CompileOptions { - gfm_tagfilter: true, - ..CompileOptions::default() - } - } - )?, + to_html_with_options("a@b.c+d@e.f", &Options::gfm())?, "<p><a href=\"mailto:a@b.c\">a@b.c</a><a href=\"mailto:+d@e.f\">+d@e.f</a></p>", "2: gfm: email autolink literals running into each other" ); diff --git a/tests/gfm_autolink_literal.rs b/tests/gfm_autolink_literal.rs index cdeecd3..cb38f29 100644 --- a/tests/gfm_autolink_literal.rs +++ b/tests/gfm_autolink_literal.rs @@ -3,20 +3,12 @@ use markdown::{ mdast::{Link, Node, Paragraph, Root, Text}, to_html, to_html_with_options, to_mdast, unist::Position, - Constructs, Options, ParseOptions, + Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn gfm_autolink_literal() -> Result<(), String> { - let gfm = Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, - ..Options::default() - }; - assert_eq!( to_html("https://example.com"), "<p>https://example.com</p>", @@ -34,165 +26,165 @@ fn gfm_autolink_literal() -> Result<(), String> { ); assert_eq!( - to_html_with_options("https://example.com", &gfm)?, + to_html_with_options("https://example.com", &Options::gfm())?, "<p><a href=\"https://example.com\">https://example.com</a></p>", "should support protocol urls if enabled" ); assert_eq!( - to_html_with_options("www.example.com", &gfm)?, + to_html_with_options("www.example.com", &Options::gfm())?, "<p><a href=\"http://www.example.com\">www.example.com</a></p>", "should support www urls if enabled" ); assert_eq!( - to_html_with_options("user@example.com", &gfm)?, + to_html_with_options("user@example.com", &Options::gfm())?, "<p><a href=\"mailto:user@example.com\">user@example.com</a></p>", "should support email urls if enabled" ); assert_eq!( - to_html_with_options("[https://example.com](xxx)", &gfm)?, + to_html_with_options("[https://example.com](xxx)", &Options::gfm())?, "<p><a href=\"xxx\">https://example.com</a></p>", "should not link protocol urls in links" ); assert_eq!( - to_html_with_options("[www.example.com](xxx)", &gfm)?, + to_html_with_options("[www.example.com](xxx)", &Options::gfm())?, "<p><a href=\"xxx\">www.example.com</a></p>", "should not link www urls in links" ); assert_eq!( - to_html_with_options("[user@example.com](xxx)", &gfm)?, + to_html_with_options("[user@example.com](xxx)", &Options::gfm())?, "<p><a href=\"xxx\">user@example.com</a></p>", "should not link email urls in links" ); assert_eq!( - to_html_with_options("user@example.com", &gfm)?, + to_html_with_options("user@example.com", &Options::gfm())?, "<p><a href=\"mailto:user@example.com\">user@example.com</a></p>", "should support a closing paren at TLD (email)" ); assert_eq!( - to_html_with_options("www.a.)", &gfm)?, + to_html_with_options("www.a.)", &Options::gfm())?, "<p><a href=\"http://www.a\">www.a</a>.)</p>", "should support a closing paren at TLD (www)" ); assert_eq!( - to_html_with_options("www.a b", &gfm)?, + to_html_with_options("www.a b", &Options::gfm())?, "<p><a href=\"http://www.a\">www.a</a> b</p>", "should support no TLD" ); assert_eq!( - to_html_with_options("www.a/b c", &gfm)?, + to_html_with_options("www.a/b c", &Options::gfm())?, "<p><a href=\"http://www.a/b\">www.a/b</a> c</p>", "should support a path instead of TLD" ); assert_eq!( - to_html_with_options("www.�a", &gfm)?, + to_html_with_options("www.�a", &Options::gfm())?, "<p><a href=\"http://www.%EF%BF%BDa\">www.�a</a></p>", "should support a replacement character in a domain" ); assert_eq!( - to_html_with_options("http://點看.com", &gfm)?, + to_html_with_options("http://點看.com", &Options::gfm())?, "<p><a href=\"http://%E9%BB%9E%E7%9C%8B.com\">http://點看.com</a></p>", "should support non-ascii characters in a domain (http)" ); assert_eq!( - to_html_with_options("www.點看.com", &gfm)?, + to_html_with_options("www.點看.com", &Options::gfm())?, "<p><a href=\"http://www.%E9%BB%9E%E7%9C%8B.com\">www.點看.com</a></p>", "should support non-ascii characters in a domain (www)" ); assert_eq!( - to_html_with_options("點看@example.com", &gfm)?, + to_html_with_options("點看@example.com", &Options::gfm())?, "<p>點看@example.com</p>", "should *not* support non-ascii characters in atext (email)" ); assert_eq!( - to_html_with_options("example@點看.com", &gfm)?, + to_html_with_options("example@點看.com", &Options::gfm())?, "<p>example@點看.com</p>", "should *not* support non-ascii characters in a domain (email)" ); assert_eq!( - to_html_with_options("www.a.com/點看", &gfm)?, + to_html_with_options("www.a.com/點看", &Options::gfm())?, "<p><a href=\"http://www.a.com/%E9%BB%9E%E7%9C%8B\">www.a.com/點看</a></p>", "should support non-ascii characters in a path" ); assert_eq!( - to_html_with_options("www.-a.b", &gfm)?, + to_html_with_options("www.-a.b", &Options::gfm())?, "<p><a href=\"http://www.-a.b\">www.-a.b</a></p>", "should support a dash to start a domain" ); assert_eq!( - to_html_with_options("www.$", &gfm)?, + to_html_with_options("www.$", &Options::gfm())?, "<p><a href=\"http://www.$\">www.$</a></p>", "should support a dollar as a domain name" ); assert_eq!( - to_html_with_options("www.a..b.c", &gfm)?, + to_html_with_options("www.a..b.c", &Options::gfm())?, "<p><a href=\"http://www.a..b.c\">www.a..b.c</a></p>", "should support adjacent dots in a domain name" ); assert_eq!( - to_html_with_options("www.a&a;", &gfm)?, + to_html_with_options("www.a&a;", &Options::gfm())?, "<p><a href=\"http://www.a\">www.a</a>&a;</p>", "should support named character references in domains" ); assert_eq!( - to_html_with_options("https://a.bc/d/e/).", &gfm)?, + to_html_with_options("https://a.bc/d/e/).", &Options::gfm())?, "<p><a href=\"https://a.bc/d/e/\">https://a.bc/d/e/</a>).</p>", "should support a closing paren and period after a path" ); assert_eq!( - to_html_with_options("https://a.bc/d/e/.)", &gfm)?, + to_html_with_options("https://a.bc/d/e/.)", &Options::gfm())?, "<p><a href=\"https://a.bc/d/e/\">https://a.bc/d/e/</a>.)</p>", "should support a period and closing paren after a path" ); assert_eq!( - to_html_with_options("https://a.bc).", &gfm)?, + to_html_with_options("https://a.bc).", &Options::gfm())?, "<p><a href=\"https://a.bc\">https://a.bc</a>).</p>", "should support a closing paren and period after a domain" ); assert_eq!( - to_html_with_options("https://a.bc.)", &gfm)?, + to_html_with_options("https://a.bc.)", &Options::gfm())?, "<p><a href=\"https://a.bc\">https://a.bc</a>.)</p>", "should support a period and closing paren after a domain" ); assert_eq!( - to_html_with_options("https://a.bc).d", &gfm)?, + to_html_with_options("https://a.bc).d", &Options::gfm())?, "<p><a href=\"https://a.bc).d\">https://a.bc).d</a></p>", "should support a closing paren and period in a path" ); assert_eq!( - to_html_with_options("https://a.bc.)d", &gfm)?, + to_html_with_options("https://a.bc.)d", &Options::gfm())?, "<p><a href=\"https://a.bc.)d\">https://a.bc.)d</a></p>", "should support a period and closing paren in a path" ); assert_eq!( - to_html_with_options("https://a.bc/))d", &gfm)?, + to_html_with_options("https://a.bc/))d", &Options::gfm())?, "<p><a href=\"https://a.bc/))d\">https://a.bc/))d</a></p>", "should support two closing parens in a path" ); assert_eq!( - to_html_with_options("ftp://a/b/c.txt", &gfm)?, + to_html_with_options("ftp://a/b/c.txt", &Options::gfm())?, "<p>ftp://a/b/c.txt</p>", "should not support ftp links" ); @@ -201,19 +193,19 @@ fn gfm_autolink_literal() -> Result<(), String> { // Fixing it would mean deviating from `cmark-gfm`: // Source: <https://github.com/github/cmark-gfm/blob/ef1cfcb/extensions/autolink.c#L156>. // assert_eq!( - // to_html_with_options(",www.example.com", &gfm)?, + // to_html_with_options(",www.example.com", &Options::gfm())?, // "<p>,<a href=\"http://www.example.com\">www.example.com</a></p>", // "should support www links after Unicode punctuation", // ); assert_eq!( - to_html_with_options(",https://example.com", &gfm)?, + to_html_with_options(",https://example.com", &Options::gfm())?, "<p>,<a href=\"https://example.com\">https://example.com</a></p>", "should support http links after Unicode punctuation" ); assert_eq!( - to_html_with_options(",example@example.com", &gfm)?, + to_html_with_options(",example@example.com", &Options::gfm())?, "<p>,<a href=\"mailto:example@example.com\">example@example.com</a></p>", "should support email links after Unicode punctuation" ); @@ -221,14 +213,14 @@ fn gfm_autolink_literal() -> Result<(), String> { assert_eq!( to_html_with_options( "http://user:password@host:port/path?key=value#fragment", - &gfm + &Options::gfm() )?, "<p>http://user:password@host:port/path?key=value#fragment</p>", "should not link character reference for `:`" ); assert_eq!( - to_html_with_options("http://example.com/ab<cd", &gfm)?, + to_html_with_options("http://example.com/ab<cd", &Options::gfm())?, "<p><a href=\"http://example.com/ab\">http://example.com/ab</a><cd</p>", "should stop domains/paths at `<`" ); @@ -259,7 +251,7 @@ xmpp:scyther@pokemon.com/message xmpp:scyther@pokemon.com/message. Email me at:scyther@pokemon.com"###, - &gfm + &Options::gfm() )?, r###"<p><a href="mailto:scyther@pokemon.com">mailto:scyther@pokemon.com</a></p> <p>This is a <a href="mailto:scyther@pokemon.com">mailto:scyther@pokemon.com</a></p> @@ -305,7 +297,7 @@ a www.example.com&. b a www.example.com& b "###, - &gfm + &Options::gfm() )?, r###"<p>a <a href="http://www.example.com&xxx;b">www.example.com&xxx;b</a> c</p> <p>a <a href="http://www.example.com">www.example.com</a>&xxx;. b</p> @@ -352,7 +344,7 @@ a www.example.com& b ![ contact@example.com ](#) "###, - &gfm + &Options::gfm() )?, r###"<p>[ <a href="http://www.example.com">www.example.com</a></p> <p>[ <a href="https://example.com">https://example.com</a></p> @@ -399,7 +391,7 @@ www.example.com/?q=a(business))) (www.example.com/?q=a(business)". "###, - &gfm + &Options::gfm() )?, r###"<p><a href="http://www.example.com/?=a(b)cccccc">www.example.com/?=a(b)cccccc</a></p> <p><a href="http://www.example.com/?=a(b(c)ccccc">www.example.com/?=a(b(c)ccccc</a></p> @@ -544,7 +536,7 @@ Can contain an underscore followed by a period: aaa@a.b_.c [link]() <http://autolink> should still be expanded. "###, - &gfm + &Options::gfm() )?, r###"<h1>Literal autolinks</h1> <h2>WWW autolinks</h2> @@ -648,7 +640,7 @@ H5. [[]]www.a.com©b "###, - &gfm + &Options::gfm() )?, r###"<p>H0.</p> <p>[<a href="https://a.com&copy;b">https://a.com&copy;b</a></p> @@ -724,7 +716,7 @@ Autolink literal after image. ![a]() www.a.com ![a]() a@b.c -"###, &gfm)?, +"###, &Options::gfm())?, r###"<p>Image start.</p> <p>![<a href="https://a.com">https://a.com</a></p> <p>![<a href="http://a.com">http://a.com</a></p> @@ -866,7 +858,7 @@ Autolink literal after link. [a]() www.a.com [a]() a@b.c -"###, &gfm)?, +"###, &Options::gfm())?, r###"<p>Link start.</p> <p>[<a href="https://a.com">https://a.com</a></p> <p>[<a href="http://a.com">http://a.com</a></p> @@ -998,7 +990,7 @@ www.a&b} www.a&b~ "###, - &gfm + &Options::gfm() )?, r###"<h1>“character reference”</h1> <p><a href="http://www.a&b">www.a&b</a> (space)</p> @@ -1109,7 +1101,7 @@ www.a#| www.a#} www.a#~ -"###, &gfm)?, +"###, &Options::gfm())?, r###"<h1>“character reference”</h1> <p><a href="http://www.a&#35">www.a&#35</a> (space)</p> <p><a href="http://www.a&#35">www.a&#35</a>!</p> @@ -1181,7 +1173,7 @@ react@0.0.0-experimental-aae83a4b9 [ react@0.0.0-experimental-aae83a4b9 "###, - &gfm + &Options::gfm() )?, r###"<p>a@0.0</p> <p><a href="mailto:a@0.b">a@0.b</a></p> @@ -1274,7 +1266,7 @@ http://a} http://a~ "###, - &gfm + &Options::gfm() )?, r###"<h1>httpshhh? (2)</h1> <p><a href="http://a">http://a</a> (space)</p> @@ -1387,7 +1379,7 @@ http://} http://~ "###, - &gfm + &Options::gfm() )?, r###"<h1>httpshhh? (1)</h1> <p>http:// (space)</p> @@ -1500,7 +1492,7 @@ http://a/b} http://a/b~ "###, - &gfm + &Options::gfm() )?, r###"<h1>httpshhh? (4)</h1> <p><a href="http://a/b">http://a/b</a> (space)</p> @@ -1613,7 +1605,7 @@ http://a/} http://a/~ "###, - &gfm + &Options::gfm() )?, r###"<h1>httpshhh? (3)</h1> <p><a href="http://a/">http://a/</a> (space)</p> @@ -1668,7 +1660,7 @@ www.example.com/a&bogus; www.example.com/a\. "###, - &gfm + &Options::gfm() )?, r###"<p><a href="#">www.example.com/a©</a></p> <p><a href="http://www.example.com/a">www.example.com/a</a>©</p> @@ -1752,7 +1744,7 @@ www.a/b&c} www.a/b&c~ "###, - &gfm + &Options::gfm() )?, r###"<h1>“character reference”</h1> <p><a href="http://www.a/b&c">www.a/b&c</a> (space)</p> @@ -1865,7 +1857,7 @@ www.a/b#} www.a/b#~ "###, - &gfm + &Options::gfm() )?, r###"<h1>“character reference”</h1> <p><a href="http://www.a/b&#35">www.a/b&#35</a> (space)</p> @@ -1950,7 +1942,7 @@ http://a.com#d]() www.a.com#d]() "###, - &gfm + &Options::gfm() )?, r###"<p>In autolink literal path or link end?</p> <p><a href="">https://a.com/d</a></p> @@ -2023,7 +2015,7 @@ Some non-ascii: 中noreply@example.com, 中http://example.com, 中https://exampl Some more non-ascii: 🤷noreply@example.com, 🤷http://example.com, 🤷https://example.com, 🤷www.example.com "###, - &gfm + &Options::gfm() )?, r###"<p>Last non-markdown ASCII whitespace (FF): <a href="mailto:noreply@example.com">noreply@example.com</a>, <a href="http://example.com">http://example.com</a>, <a href="https://example.com">https://example.com</a>, www.example.com</p> <p>Last non-whitespace ASCII control (US): <a href="mailto:noreply@example.com">noreply@example.com</a>, <a href="http://example.com">http://example.com</a>, <a href="https://example.com">https://example.com</a>, www.example.com</p> @@ -2130,7 +2122,7 @@ See `https://github.com/remarkjs/remark/discussions/678`. [asd] ,https://github.com "###, - &gfm + &Options::gfm() )?, r###"<h1>HTTP</h1> <p><a href="https://a.b">https://a.b</a> can start after EOF</p> @@ -2250,7 +2242,7 @@ www.a} www.a~ "###, - &gfm + &Options::gfm() )?, r###"<h1>wwwtf 2?</h1> <p><a href="http://www.a">www.a</a> (space)</p> @@ -2363,7 +2355,7 @@ www.a.} www.a.~ "###, - &gfm + &Options::gfm() )?, r###"<h1>wwwtf 5?</h1> <p><a href="http://www.a">www.a</a>. (space)</p> @@ -2476,7 +2468,7 @@ www.} www.~ "###, - &gfm + &Options::gfm() )?, r###"<h1>wwwtf?</h1> <p><a href="http://www">www</a>. (space)</p> @@ -2589,7 +2581,7 @@ www.a/b} www.a/b~ "###, - &gfm + &Options::gfm() )?, r###"<h1>wwwtf? (4)</h1> <p><a href="http://www.a/b">www.a/b</a> (space)</p> @@ -2702,7 +2694,7 @@ www.a/} www.a/~ "###, - &gfm + &Options::gfm() )?, r###"<h1>wwwtf? (3)</h1> <p><a href="http://www.a/">www.a/</a> (space)</p> @@ -2746,7 +2738,7 @@ www.a/~ assert_eq!( to_mdast( "a https://alpha.com b bravo@charlie.com c www.delta.com d xmpp:echo@foxtrot.com e mailto:golf@hotel.com f.", - &gfm.parse + &ParseOptions::gfm() )?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { diff --git a/tests/gfm_footnote.rs b/tests/gfm_footnote.rs index f5ae0cb..e036857 100644 --- a/tests/gfm_footnote.rs +++ b/tests/gfm_footnote.rs @@ -3,20 +3,12 @@ use markdown::{ mdast::{FootnoteDefinition, FootnoteReference, Node, Paragraph, Root, Text}, to_html, to_html_with_options, to_mdast, unist::Position, - CompileOptions, Constructs, Options, ParseOptions, + CompileOptions, Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn gfm_footnote() -> Result<(), String> { - let gfm = Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, - ..Options::default() - }; - assert_eq!( to_html("A call.[^a]\n\n[^a]: whatevs"), "<p>A call.<a href=\"whatevs\">^a</a></p>\n", @@ -24,7 +16,7 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("A call.[^a]\n\n[^a]: whatevs", &gfm)?, + to_html_with_options("A call.[^a]\n\n[^a]: whatevs", &Options::gfm())?, "<p>A call.<sup><a href=\"#user-content-fn-a\" id=\"user-content-fnref-a\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup></p> <section data-footnotes=\"\" class=\"footnotes\"><h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2> <ol> @@ -41,14 +33,11 @@ fn gfm_footnote() -> Result<(), String> { to_html_with_options( "Noot.[^a]\n\n[^a]: dingen", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, + parse: ParseOptions::gfm(), compile: CompileOptions { - gfm_footnote_label: Some("Voetnoten".into()), - gfm_footnote_back_label: Some("Terug naar de inhoud".into()), - ..CompileOptions::default() + gfm_footnote_label: Some("Voetnoten".into()), + gfm_footnote_back_label: Some("Terug naar de inhoud".into()), + ..CompileOptions::gfm() } } )?, @@ -68,13 +57,10 @@ fn gfm_footnote() -> Result<(), String> { to_html_with_options( "[^a]\n\n[^a]: b", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, + parse: ParseOptions::gfm(), compile: CompileOptions { - gfm_footnote_label_tag_name: Some("h1".into()), - ..CompileOptions::default() + gfm_footnote_label_tag_name: Some("h1".into()), + ..CompileOptions::gfm() } } )?, @@ -94,13 +80,10 @@ fn gfm_footnote() -> Result<(), String> { to_html_with_options( "[^a]\n\n[^a]: b", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, + parse: ParseOptions::gfm(), compile: CompileOptions { - gfm_footnote_label_attributes: Some("class=\"footnote-heading\"".into()), - ..CompileOptions::default() + gfm_footnote_label_attributes: Some("class=\"footnote-heading\"".into()), + ..CompileOptions::gfm() } } )?, @@ -120,13 +103,10 @@ fn gfm_footnote() -> Result<(), String> { to_html_with_options( "[^a]\n\n[^a]: b", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, + parse: ParseOptions::gfm(), compile: CompileOptions { gfm_footnote_clobber_prefix: Some("".into()), - ..CompileOptions::default() + ..CompileOptions::gfm() } } )?, @@ -143,19 +123,19 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("A paragraph.\n\n[^a]: whatevs", &gfm)?, + to_html_with_options("A paragraph.\n\n[^a]: whatevs", &Options::gfm())?, "<p>A paragraph.</p>\n", "should ignore definitions w/o calls" ); assert_eq!( - to_html_with_options("a[^b]", &gfm)?, + to_html_with_options("a[^b]", &Options::gfm())?, "<p>a[^b]</p>", "should ignore calls w/o definitions" ); assert_eq!( - to_html_with_options("a[^b]\n\n[^b]: c\n[^b]: d", &gfm)?, + to_html_with_options("a[^b]\n\n[^b]: c\n[^b]: d", &Options::gfm())?, "<p>a<sup><a href=\"#user-content-fn-b\" id=\"user-content-fnref-b\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup></p> <section data-footnotes=\"\" class=\"footnotes\"><h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2> <ol> @@ -169,7 +149,7 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("a[^b], c[^b]\n\n[^b]: d", &gfm)?, + to_html_with_options("a[^b], c[^b]\n\n[^b]: d", &Options::gfm())?, "<p>a<sup><a href=\"#user-content-fn-b\" id=\"user-content-fnref-b\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup>, c<sup><a href=\"#user-content-fn-b\" id=\"user-content-fnref-b-2\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup></p> <section data-footnotes=\"\" class=\"footnotes\"><h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2> <ol> @@ -183,32 +163,32 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("![^a](b)", &gfm)?, + to_html_with_options("![^a](b)", &Options::gfm())?, "<p>!<a href=\"b\">^a</a></p>", "should not support images starting w/ `^` (but see it as a link?!, 1)" ); assert_eq!( - to_html_with_options("![^a][b]\n\n[b]: c", &gfm)?, + to_html_with_options("![^a][b]\n\n[b]: c", &Options::gfm())?, "<p>!<a href=\"c\">^a</a></p>\n", "should not support images starting w/ `^` (but see it as a link?!, 2)" ); assert_eq!( - to_html_with_options("[^]()", &gfm)?, + to_html_with_options("[^]()", &Options::gfm())?, "<p><a href=\"\">^</a></p>", "should support an empty link with caret" ); assert_eq!( - to_html_with_options("![^]()", &gfm)?, + to_html_with_options("![^]()", &Options::gfm())?, "<p>!<a href=\"\">^</a></p>", "should support an empty image with caret (as link)" ); // <https://github.com/github/cmark-gfm/issues/239> assert_eq!( - to_html_with_options("Call.[^a\\+b].\n\n[^a\\+b]: y", &gfm)?, + to_html_with_options("Call.[^a\\+b].\n\n[^a\\+b]: y", &Options::gfm())?, "<p>Call.<sup><a href=\"#user-content-fn-a%5C+b\" id=\"user-content-fnref-a%5C+b\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup>.</p> <section data-footnotes=\"\" class=\"footnotes\"><h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2> <ol> @@ -222,7 +202,7 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("Call.[^a©b].\n\n[^a©b]: y", &gfm)?, + to_html_with_options("Call.[^a©b].\n\n[^a©b]: y", &Options::gfm())?, "<p>Call.<sup><a href=\"#user-content-fn-a&copy;b\" id=\"user-content-fnref-a&copy;b\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup>.</p> <section data-footnotes=\"\" class=\"footnotes\"><h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2> <ol> @@ -238,7 +218,7 @@ fn gfm_footnote() -> Result<(), String> { // <https://github.com/github/cmark-gfm/issues/239> // <https://github.com/github/cmark-gfm/issues/240> assert_eq!( - to_html_with_options("Call.[^a\\]b].\n\n[^a\\]b]: y", &gfm)?, + to_html_with_options("Call.[^a\\]b].\n\n[^a\\]b]: y", &Options::gfm())?, "<p>Call.<sup><a href=\"#user-content-fn-a%5C%5Db\" id=\"user-content-fnref-a%5C%5Db\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup>.</p> <section data-footnotes=\"\" class=\"footnotes\"><h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2> <ol> @@ -252,7 +232,7 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("Call.[^a[b].\n\n[^a[b]: y", &gfm)?, + to_html_with_options("Call.[^a[b].\n\n[^a[b]: y", &Options::gfm())?, "<p>Call.<sup><a href=\"#user-content-fn-a&#91;b\" id=\"user-content-fnref-a&#91;b\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup>.</p> <section data-footnotes=\"\" class=\"footnotes\"><h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2> <ol> @@ -266,19 +246,19 @@ fn gfm_footnote() -> Result<(), String> { ); assert_eq!( - to_html_with_options("Call.[^a\\+b].\n\n[^a+b]: y", &gfm)?, + to_html_with_options("Call.[^a\\+b].\n\n[^a+b]: y", &Options::gfm())?, "<p>Call.[^a+b].</p>\n", "should match calls to definitions on the source of the label, not on resolved escapes" ); assert_eq!( - to_html_with_options("Call.[^a[b].\n\n[^a\\[b]: y", &gfm)?, + to_html_with_options("Call.[^a[b].\n\n[^a\\[b]: y", &Options::gfm())?, "<p>Call.[^a[b].</p>\n", "should match calls to definitions on the source of the label, not on resolved references" ); assert_eq!( - to_html_with_options("[^1].\n\n[^1]: a\nb", &gfm)?, + to_html_with_options("[^1].\n\n[^1]: a\nb", &Options::gfm())?, "<p><sup><a href=\"#user-content-fn-1\" id=\"user-content-fnref-1\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup>.</p> <section data-footnotes=\"\" class=\"footnotes\"><h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2> <ol> @@ -293,7 +273,7 @@ b <a href=\"#user-content-fnref-1\" data-footnote-backref=\"\" aria-label=\"Back ); assert_eq!( - to_html_with_options("[^1].\n\n> [^1]: a\nb", &gfm)?, + to_html_with_options("[^1].\n\n> [^1]: a\nb", &Options::gfm())?, "<p><sup><a href=\"#user-content-fn-1\" id=\"user-content-fnref-1\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup>.</p> <blockquote> </blockquote> @@ -310,7 +290,7 @@ b <a href=\"#user-content-fnref-1\" data-footnote-backref=\"\" aria-label=\"Back ); assert_eq!( - to_html_with_options("[^1].\n\n> [^1]: a\n> b", &gfm)?, + to_html_with_options("[^1].\n\n> [^1]: a\n> b", &Options::gfm())?, "<p><sup><a href=\"#user-content-fn-1\" id=\"user-content-fnref-1\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup>.</p> <blockquote> </blockquote> @@ -327,7 +307,7 @@ b <a href=\"#user-content-fnref-1\" data-footnote-backref=\"\" aria-label=\"Back ); assert_eq!( - to_html_with_options("[^1].\n\n[^1]: a\n\n > b", &gfm)?, + to_html_with_options("[^1].\n\n[^1]: a\n\n > b", &Options::gfm())?, "<p><sup><a href=\"#user-content-fn-1\" id=\"user-content-fnref-1\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup>.</p> <section data-footnotes=\"\" class=\"footnotes\"><h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2> <ol> @@ -348,7 +328,7 @@ b <a href=\"#user-content-fnref-1\" data-footnote-backref=\"\" aria-label=\"Back let max = "x".repeat(999); assert_eq!( - to_html_with_options(format!("Call.[^{}].\n\n[^{}]: y", max, max).as_str(), &gfm)?, + to_html_with_options(format!("Call.[^{}].\n\n[^{}]: y", max, max).as_str(), &Options::gfm())?, format!("<p>Call.<sup><a href=\"#user-content-fn-{}\" id=\"user-content-fnref-{}\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup>.</p> <section data-footnotes=\"\" class=\"footnotes\"><h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2> <ol> @@ -364,7 +344,7 @@ b <a href=\"#user-content-fnref-1\" data-footnote-backref=\"\" aria-label=\"Back assert_eq!( to_html_with_options( format!("Call.[^a{}].\n\n[^a{}]: y", max, max).as_str(), - &gfm + &Options::gfm() )?, format!("<p>Call.[^a{}].</p>\n<p>[^a{}]: y</p>", max, max), "should not support 1000 characters in a call / definition" @@ -373,7 +353,7 @@ b <a href=\"#user-content-fnref-1\" data-footnote-backref=\"\" aria-label=\"Back assert_eq!( to_html_with_options( "[^a]\n\n[^a]: b\n \n c", - &gfm + &Options::gfm() )?, "<p><sup><a href=\"#user-content-fn-a\" id=\"user-content-fnref-a\" data-footnote-ref=\"\" aria-describedby=\"footnote-label\">1</a></sup></p> <section data-footnotes=\"\" class=\"footnotes\"><h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2> @@ -399,7 +379,7 @@ a![^1] [^1]: b [i]: c"###, - &gfm + &Options::gfm() )?, r###"<p>a<img src="#" alt="i" /> a!<a href="#">i</a> @@ -419,7 +399,7 @@ a!<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref= ); assert_eq!( - to_html_with_options("a![^1]", &gfm)?, + to_html_with_options("a![^1]", &Options::gfm())?, "<p>a![^1]</p>", "should match bang/caret interplay (undefined) like GitHub" ); @@ -430,7 +410,7 @@ a!<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref= [^1]: b "###, - &gfm + &Options::gfm() )?, r###"<p>a!<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup></p> <section data-footnotes="" class="footnotes"><h2 id="footnote-label" class="sr-only">Footnotes</h2> @@ -469,7 +449,7 @@ even another caret. [^^]: caret "###, - &gfm + &Options::gfm() )?, r###"<p>Calls may not be empty: <a href="empty">^</a>.</p> <p>Calls cannot contain whitespace only: <a href="empty">^ </a>.</p> @@ -527,7 +507,7 @@ Some calls.[^ w][^x ][^y][^z] [^x ]: # z "###, - &gfm + &Options::gfm() )?, r###"<p>[^c d]: # e</p> <p>[^f g]: # h</p> @@ -595,7 +575,7 @@ j], [^ l], [^m ]</p> [^![image](#)]: a "###, - &gfm + &Options::gfm() )?, // Note: // * GH does not support colons. @@ -654,7 +634,7 @@ j], [^ l], [^m ]</p> More. [^4]: Directly after a list item. "###, - &gfm + &Options::gfm() )?, r###"<p>Call<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup></p> <blockquote> @@ -711,7 +691,7 @@ j], [^ l], [^m ]</p> - list "###, - &gfm + &Options::gfm() )?, r###"<p><sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup></p> <h1>Heading</h1> @@ -768,7 +748,7 @@ Lazy? Lazy! "###, - &gfm + &Options::gfm() )?, r###"<p>Call<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup><sup><a href="#user-content-fn-5" id="user-content-fnref-5" data-footnote-ref="" aria-describedby="footnote-label">5</a></sup>.</p> <p>Lazy?</p> @@ -824,7 +804,7 @@ Lazy! [^10]:- - - kilo "###, - &gfm + &Options::gfm() )?, r###"<p>Note!<sup><a href="#user-content-fn-0" id="user-content-fnref-0" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">5</a></sup><sup><a href="#user-content-fn-5" id="user-content-fnref-5" data-footnote-ref="" aria-describedby="footnote-label">6</a></sup><sup><a href="#user-content-fn-6" id="user-content-fnref-6" data-footnote-ref="" aria-describedby="footnote-label">7</a></sup><sup><a href="#user-content-fn-7" id="user-content-fnref-7" data-footnote-ref="" aria-describedby="footnote-label">8</a></sup><sup><a href="#user-content-fn-8" id="user-content-fnref-8" data-footnote-ref="" aria-describedby="footnote-label">9</a></sup><sup><a href="#user-content-fn-9" id="user-content-fnref-9" data-footnote-ref="" aria-describedby="footnote-label">10</a></sup><sup><a href="#user-content-fn-10" id="user-content-fnref-10" data-footnote-ref="" aria-describedby="footnote-label">11</a></sup></p> <section data-footnotes="" class="footnotes"><h2 id="footnote-label" class="sr-only">Footnotes</h2> @@ -897,7 +877,7 @@ indented delta <a href="#user-content-fnref-2" data-footnote-backref="" aria-lab [^1]: Recursion[^1][^1] "###, - &gfm + &Options::gfm() )?, r###"<p>Call<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-1" id="user-content-fnref-1-2" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup></p> <section data-footnotes="" class="footnotes"><h2 id="footnote-label" class="sr-only">Footnotes</h2> @@ -919,7 +899,7 @@ indented delta <a href="#user-content-fnref-2" data-footnote-backref="" aria-lab [^1]: b "###, - &gfm + &Options::gfm() )?, r###"<p>Call<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup></p> <section data-footnotes="" class="footnotes"><h2 id="footnote-label" class="sr-only">Footnotes</h2> @@ -961,7 +941,7 @@ indented delta <a href="#user-content-fnref-2" data-footnote-backref="" aria-lab [^5]: e "###, - &gfm + &Options::gfm() )?, r###"<p><em>emphasis<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup></em></p> <p><strong>strong<sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup></strong></p> @@ -998,7 +978,7 @@ indented delta <a href="#user-content-fnref-2" data-footnote-backref="" aria-lab [^3]: c "###, - &gfm + &Options::gfm() )?, r###"<p>What are these!<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup>, !<sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup>[], and ![this]<sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup>.</p> <section data-footnotes="" class="footnotes"><h2 id="footnote-label" class="sr-only">Footnotes</h2> @@ -1040,7 +1020,7 @@ indented delta <a href="#user-content-fnref-2" data-footnote-backref="" aria-lab …continuation * list "###, - &gfm + &Options::gfm() )?, r###"<p><sup><a href="#user-content-fn-0" id="user-content-fnref-0" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">5</a></sup><sup><a href="#user-content-fn-5" id="user-content-fnref-5" data-footnote-ref="" aria-describedby="footnote-label">6</a></sup></p> <h1>Heading</h1> @@ -1093,7 +1073,7 @@ indented delta <a href="#user-content-fnref-2" data-footnote-backref="" aria-lab [^3]: c "###, - &gfm + &Options::gfm() )?, r###"<p>What are these<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup>, <sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup>[], and [this]<sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup>.</p> <section data-footnotes="" class="footnotes"><h2 id="footnote-label" class="sr-only">Footnotes</h2> @@ -1143,7 +1123,7 @@ indented delta <a href="#user-content-fnref-2" data-footnote-backref="" aria-lab - list "###, - &gfm + &Options::gfm() )?, r###"<p><sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup></p> <h1>Heading</h1> @@ -1205,7 +1185,7 @@ indented delta <a href="#user-content-fnref-2" data-footnote-backref="" aria-lab - list "###, - &gfm + &Options::gfm() )?, r###"<p><sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup></p> <section data-footnotes="" class="footnotes"><h2 id="footnote-label" class="sr-only">Footnotes</h2> @@ -1254,7 +1234,7 @@ more code [^3]: [^4]: Paragraph "###, - &gfm + &Options::gfm() )?, r###"<p>Note!<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup></p> <ul> @@ -1304,7 +1284,7 @@ more code - list "###, - &gfm + &Options::gfm() )?, r###"<p><sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup></p> <h1>Heading</h1> @@ -1358,7 +1338,7 @@ more code - list "###, - &gfm + &Options::gfm() )?, r###"<p><sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup></p> <section data-footnotes="" class="footnotes"><h2 id="footnote-label" class="sr-only">Footnotes</h2> @@ -1416,7 +1396,7 @@ belong to the previous footnote. This paragraph won’t be part of the note, because it isn’t indented. "###, - &gfm + &Options::gfm() )?, r###"<p>Here is a footnote reference,<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup> and another.<sup><a href="#user-content-fn-longnote" id="user-content-fnref-longnote" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup></p> <p>This paragraph won’t be part of the note, because it @@ -1484,7 +1464,7 @@ multi-paragraph list items. <a href="#user-content-fnref-longnote" data-footnote 3 "###, - &gfm + &Options::gfm() )?, r###"<p>Call[^1][^2]<sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-5" id="user-content-fnref-5" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-6" id="user-content-fnref-6" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup><sup><a href="#user-content-fn-7" id="user-content-fnref-7" data-footnote-ref="" aria-describedby="footnote-label">5</a></sup><sup><a href="#user-content-fn-8" id="user-content-fnref-8" data-footnote-ref="" aria-describedby="footnote-label">6</a></sup><sup><a href="#user-content-fn-9" id="user-content-fnref-9" data-footnote-ref="" aria-describedby="footnote-label">7</a></sup><sup><a href="#user-content-fn-10" id="user-content-fnref-10" data-footnote-ref="" aria-describedby="footnote-label">8</a></sup><sup><a href="#user-content-fn-11" id="user-content-fnref-11" data-footnote-ref="" aria-describedby="footnote-label">9</a></sup><sup><a href="#user-content-fn-12" id="user-content-fnref-12" data-footnote-ref="" aria-describedby="footnote-label">10</a></sup>.</p> <pre><code> [^1]: 5 @@ -1576,7 +1556,7 @@ multi-paragraph list items. <a href="#user-content-fnref-longnote" data-footnote 0 "###, - &gfm + &Options::gfm() )?, r###"<p>Call<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup><sup><a href="#user-content-fn-2" id="user-content-fnref-2" data-footnote-ref="" aria-describedby="footnote-label">2</a></sup><sup><a href="#user-content-fn-3" id="user-content-fnref-3" data-footnote-ref="" aria-describedby="footnote-label">3</a></sup><sup><a href="#user-content-fn-4" id="user-content-fnref-4" data-footnote-ref="" aria-describedby="footnote-label">4</a></sup><sup><a href="#user-content-fn-5" id="user-content-fnref-5" data-footnote-ref="" aria-describedby="footnote-label">5</a></sup><sup><a href="#user-content-fn-6" id="user-content-fnref-6" data-footnote-ref="" aria-describedby="footnote-label">6</a></sup><sup><a href="#user-content-fn-7" id="user-content-fnref-7" data-footnote-ref="" aria-describedby="footnote-label">7</a></sup><sup><a href="#user-content-fn-8" id="user-content-fnref-8" data-footnote-ref="" aria-describedby="footnote-label">8</a></sup><sup><a href="#user-content-fn-9" id="user-content-fnref-9" data-footnote-ref="" aria-describedby="footnote-label">9</a></sup>.</p> <p>3</p> @@ -1635,7 +1615,7 @@ multi-paragraph list items. <a href="#user-content-fnref-longnote" data-footnote [3]: c "###, - &gfm + &Options::gfm() )?, r###"<p>Here is a short reference,<a href="a">1</a>, a collapsed one,<a href="b">2</a>, and a full <a href="c">one</a>.</p> "###, @@ -1643,7 +1623,7 @@ multi-paragraph list items. <a href="#user-content-fnref-longnote" data-footnote ); assert_eq!( - to_mdast("[^a]: b\n\tc\n\nd [^a] e.", &gfm.parse)?, + to_mdast("[^a]: b\n\tc\n\nd [^a] e.", &ParseOptions::gfm())?, Node::Root(Root { children: vec![ Node::FootnoteDefinition(FootnoteDefinition { diff --git a/tests/gfm_strikethrough.rs b/tests/gfm_strikethrough.rs index 980f1e9..b8e30a6 100644 --- a/tests/gfm_strikethrough.rs +++ b/tests/gfm_strikethrough.rs @@ -3,20 +3,12 @@ use markdown::{ mdast::{Delete, Node, Paragraph, Root, Text}, to_html, to_html_with_options, to_mdast, unist::Position, - Constructs, Options, ParseOptions, + Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn gfm_strikethrough() -> Result<(), String> { - let gfm = Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, - ..Options::default() - }; - assert_eq!( to_html("a ~b~ c"), "<p>a ~b~ c</p>", @@ -24,49 +16,49 @@ fn gfm_strikethrough() -> Result<(), String> { ); assert_eq!( - to_html_with_options("a ~b~", &gfm)?, + to_html_with_options("a ~b~", &Options::gfm())?, "<p>a <del>b</del></p>", "should support strikethrough w/ one tilde" ); assert_eq!( - to_html_with_options("a ~~b~~", &gfm)?, + to_html_with_options("a ~~b~~", &Options::gfm())?, "<p>a <del>b</del></p>", "should support strikethrough w/ two tildes" ); assert_eq!( - to_html_with_options("a ~~~b~~~", &gfm)?, + to_html_with_options("a ~~~b~~~", &Options::gfm())?, "<p>a ~~~b~~~</p>", "should not support strikethrough w/ three tildes" ); assert_eq!( - to_html_with_options("a \\~~~b~~ c", &gfm)?, + to_html_with_options("a \\~~~b~~ c", &Options::gfm())?, "<p>a ~<del>b</del> c</p>", "should support strikethrough after an escaped tilde" ); assert_eq!( - to_html_with_options("a ~~b ~~c~~ d~~ e", &gfm)?, + to_html_with_options("a ~~b ~~c~~ d~~ e", &Options::gfm())?, "<p>a <del>b <del>c</del> d</del> e</p>", "should support nested strikethrough" ); assert_eq!( - to_html_with_options("a ~-1~ b", &gfm)?, + to_html_with_options("a ~-1~ b", &Options::gfm())?, "<p>a <del>-1</del> b</p>", "should open if preceded by whitespace and followed by punctuation" ); assert_eq!( - to_html_with_options("a ~b.~ c", &gfm)?, + to_html_with_options("a ~b.~ c", &Options::gfm())?, "<p>a <del>b.</del> c</p>", "should close if preceded by punctuation and followed by whitespace" ); assert_eq!( - to_html_with_options("~b.~.", &gfm)?, + to_html_with_options("~b.~.", &Options::gfm())?, "<p><del>b.</del>.</p>", "should close if preceded and followed by punctuation" ); @@ -130,7 +122,7 @@ a ~~two b one~ c two~~ d a ~~two b two~~ c one~ d "###, - &gfm + &Options::gfm() )?, r###"<h1>Balanced</h1> <p>a <del>one</del> b</p> @@ -199,7 +191,7 @@ a ~~twoLeft b ~~twoLeft c twoRight~~ d a ~~twoLeft b ~~twoLeft c ~~twoLeft d "###, - &gfm + &Options::gfm() )?, r###"<h1>Flank</h1> <p>a oneRight~ b oneRight~ c oneRight~ d</p> @@ -316,7 +308,7 @@ t ~~**xxx**~~ zzz u ~**xxx**~ zzz "###, - &gfm + &Options::gfm() )?, r###"<h1>Interlpay</h1> <h2>Interleave with attention</h2> @@ -372,11 +364,10 @@ u ~**xxx**~ zzz "a ~b~ ~~c~~ d", &Options { parse: ParseOptions { - constructs: Constructs::gfm(), gfm_strikethrough_single_tilde: false, - ..ParseOptions::default() + ..ParseOptions::gfm() }, - ..Options::default() + ..Options::gfm() } )?, "<p>a ~b~ <del>c</del> d</p>", @@ -388,11 +379,10 @@ u ~**xxx**~ zzz "a ~b~ ~~c~~ d", &Options { parse: ParseOptions { - constructs: Constructs::gfm(), gfm_strikethrough_single_tilde: true, - ..ParseOptions::default() + ..ParseOptions::gfm() }, - ..Options::default() + ..Options::gfm() } )?, "<p>a <del>b</del> <del>c</del> d</p>", @@ -400,7 +390,7 @@ u ~**xxx**~ zzz ); assert_eq!( - to_mdast("a ~~alpha~~ b.", &gfm.parse)?, + to_mdast("a ~~alpha~~ b.", &ParseOptions::gfm())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![ diff --git a/tests/gfm_table.rs b/tests/gfm_table.rs index 54e0ace..db1c364 100644 --- a/tests/gfm_table.rs +++ b/tests/gfm_table.rs @@ -9,14 +9,6 @@ use pretty_assertions::assert_eq; #[test] fn gfm_table() -> Result<(), String> { - let gfm = Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, - ..Options::default() - }; - assert_eq!( to_html("| a |\n| - |\n| b |"), "<p>| a |\n| - |\n| b |</p>", @@ -24,181 +16,181 @@ fn gfm_table() -> Result<(), String> { ); assert_eq!( - to_html_with_options("| a |\n| - |\n| b |", &gfm)?, + to_html_with_options("| a |\n| - |\n| b |", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "should support tables" ); assert_eq!( - to_html_with_options("| a |", &gfm)?, + to_html_with_options("| a |", &Options::gfm())?, "<p>| a |</p>", "should not support a table w/ the head row ending in an eof (1)" ); assert_eq!( - to_html_with_options("| a", &gfm)?, + to_html_with_options("| a", &Options::gfm())?, "<p>| a</p>", "should not support a table w/ the head row ending in an eof (2)" ); assert_eq!( - to_html_with_options("a |", &gfm)?, + to_html_with_options("a |", &Options::gfm())?, "<p>a |</p>", "should not support a table w/ the head row ending in an eof (3)" ); assert_eq!( - to_html_with_options("| a |\n| - |", &gfm)?, + to_html_with_options("| a |\n| - |", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "should support a table w/ a delimiter row ending in an eof (1)" ); assert_eq!( - to_html_with_options("| a\n| -", &gfm)?, + to_html_with_options("| a\n| -", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "should support a table w/ a delimiter row ending in an eof (2)" ); assert_eq!( - to_html_with_options("| a |\n| - |\n| b |", &gfm)?, + to_html_with_options("| a |\n| - |\n| b |", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "should support a table w/ a body row ending in an eof (1)" ); assert_eq!( - to_html_with_options("| a\n| -\n| b", &gfm)?, + to_html_with_options("| a\n| -\n| b", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "should support a table w/ a body row ending in an eof (2)" ); assert_eq!( - to_html_with_options("a|b\n-|-\nc|d", &gfm)?, + to_html_with_options("a|b\n-|-\nc|d", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>c</td>\n<td>d</td>\n</tr>\n</tbody>\n</table>", "should support a table w/ a body row ending in an eof (3)" ); assert_eq!( - to_html_with_options("| a \n| -\t\n| b | ", &gfm)?, + to_html_with_options("| a \n| -\t\n| b | ", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "should support rows w/ trailing whitespace (1)" ); assert_eq!( - to_html_with_options("| a | \n| - |", &gfm)?, + to_html_with_options("| a | \n| - |", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "should support rows w/ trailing whitespace (2)" ); assert_eq!( - to_html_with_options("| a |\n| - | ", &gfm)?, + to_html_with_options("| a |\n| - | ", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "should support rows w/ trailing whitespace (3)" ); assert_eq!( - to_html_with_options("| a |\n| - |\n| b | ", &gfm)?, + to_html_with_options("| a |\n| - |\n| b | ", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "should support rows w/ trailing whitespace (4)" ); assert_eq!( - to_html_with_options("||a|\n|-|-|", &gfm)?, + to_html_with_options("||a|\n|-|-|", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th></th>\n<th>a</th>\n</tr>\n</thead>\n</table>", "should support empty first header cells" ); assert_eq!( - to_html_with_options("|a||\n|-|-|", &gfm)?, + to_html_with_options("|a||\n|-|-|", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th></th>\n</tr>\n</thead>\n</table>", "should support empty last header cells" ); assert_eq!( - to_html_with_options("a||b\n-|-|-", &gfm)?, + to_html_with_options("a||b\n-|-|-", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th></th>\n<th>b</th>\n</tr>\n</thead>\n</table>", "should support empty header cells" ); assert_eq!( - to_html_with_options("|a|b|\n|-|-|\n||c|", &gfm)?, + to_html_with_options("|a|b|\n|-|-|\n||c|", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td></td>\n<td>c</td>\n</tr>\n</tbody>\n</table>", "should support empty first body cells" ); assert_eq!( - to_html_with_options("|a|b|\n|-|-|\n|c||", &gfm)?, + to_html_with_options("|a|b|\n|-|-|\n|c||", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>c</td>\n<td></td>\n</tr>\n</tbody>\n</table>", "should support empty last body cells" ); assert_eq!( - to_html_with_options("a|b|c\n-|-|-\nd||e", &gfm)?, + to_html_with_options("a|b|c\n-|-|-\nd||e", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>d</td>\n<td></td>\n<td>e</td>\n</tr>\n</tbody>\n</table>", "should support empty body cells" ); assert_eq!( - to_html_with_options("| a |\n| - |\n- b", &gfm)?, + to_html_with_options("| a |\n| - |\n- b", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<ul>\n<li>b</li>\n</ul>", "should support a list after a table" ); assert_eq!( - to_html_with_options("> | a |\n| - |", &gfm)?, + to_html_with_options("> | a |\n| - |", &Options::gfm())?, "<blockquote>\n<p>| a |\n| - |</p>\n</blockquote>", "should not support a lazy delimiter row (1)" ); assert_eq!( - to_html_with_options("> a\n> | b |\n| - |", &gfm)?, + to_html_with_options("> a\n> | b |\n| - |", &Options::gfm())?, "<blockquote>\n<p>a\n| b |\n| - |</p>\n</blockquote>", "should not support a lazy delimiter row (2)" ); assert_eq!( - to_html_with_options("| a |\n> | - |", &gfm)?, + to_html_with_options("| a |\n> | - |", &Options::gfm())?, "<p>| a |</p>\n<blockquote>\n<p>| - |</p>\n</blockquote>", "should not support a piercing delimiter row" ); assert_eq!( - to_html_with_options("> a\n> | b |\n|-", &gfm)?, + to_html_with_options("> a\n> | b |\n|-", &Options::gfm())?, "<blockquote>\n<p>a\n| b |\n|-</p>\n</blockquote>", "should not support a lazy body row (2)" ); assert_eq!( - to_html_with_options("> | a |\n> | - |\n| b |", &gfm)?, + to_html_with_options("> | a |\n> | - |\n| b |", &Options::gfm())?, "<blockquote>\n<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n</blockquote>\n<p>| b |</p>", "should not support a lazy body row (1)" ); assert_eq!( - to_html_with_options("> a\n> | b |\n> | - |\n| c |", &gfm)?, + to_html_with_options("> a\n> | b |\n> | - |\n| c |", &Options::gfm())?, "<blockquote>\n<p>a</p>\n<table>\n<thead>\n<tr>\n<th>b</th>\n</tr>\n</thead>\n</table>\n</blockquote>\n<p>| c |</p>", "should not support a lazy body row (2)" ); assert_eq!( - to_html_with_options("> | A |\n> | - |\n> | 1 |\n| 2 |", &gfm)?, + to_html_with_options("> | A |\n> | - |\n> | 1 |\n| 2 |", &Options::gfm())?, "<blockquote>\n<table>\n<thead>\n<tr>\n<th>A</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>1</td>\n</tr>\n</tbody>\n</table>\n</blockquote>\n<p>| 2 |</p>", "should not support a lazy body row (3)" ); assert_eq!( - to_html_with_options(" - d\n - e", &gfm)?, + to_html_with_options(" - d\n - e", &Options::gfm())?, to_html(" - d\n - e"), "should not change how lists and lazyness work" ); assert_eq!( - to_html_with_options("| a |\n | - |", &gfm)?, + to_html_with_options("| a |\n | - |", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "should form a table if the delimiter row is indented w/ 3 spaces" ); assert_eq!( - to_html_with_options("| a |\n | - |", &gfm)?, + to_html_with_options("| a |\n | - |", &Options::gfm())?, "<p>| a |\n| - |</p>", "should not form a table if the delimiter row is indented w/ 4 spaces" ); @@ -210,34 +202,34 @@ fn gfm_table() -> Result<(), String> { code_indented: false, ..Constructs::gfm() }, - ..ParseOptions::default() + ..ParseOptions::gfm() }, - ..Options::default() + ..Options::gfm() })?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>", "should form a table if the delimiter row is indented w/ 4 spaces and indented code is turned off" ); assert_eq!( - to_html_with_options("| a |\n| - |\n> block quote?", &gfm)?, + to_html_with_options("| a |\n| - |\n> block quote?", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<blockquote>\n<p>block quote?</p>\n</blockquote>", "should be interrupted by a block quote" ); assert_eq!( - to_html_with_options("| a |\n| - |\n>", &gfm)?, + to_html_with_options("| a |\n| - |\n>", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<blockquote>\n</blockquote>", "should be interrupted by a block quote (empty)" ); assert_eq!( - to_html_with_options("| a |\n| - |\n- list?", &gfm)?, + to_html_with_options("| a |\n| - |\n- list?", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<ul>\n<li>list?</li>\n</ul>", "should be interrupted by a list" ); assert_eq!( - to_html_with_options("| a |\n| - |\n-", &gfm)?, + to_html_with_options("| a |\n| - |\n-", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<ul>\n<li></li>\n</ul>", "should be interrupted by a list (empty)" ); @@ -246,15 +238,12 @@ fn gfm_table() -> Result<(), String> { to_html_with_options( "| a |\n| - |\n<!-- HTML? -->", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() } )?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<!-- HTML? -->", @@ -263,15 +252,12 @@ fn gfm_table() -> Result<(), String> { assert_eq!( to_html_with_options("| a |\n| - |\n\tcode?", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() })?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<pre><code>code?\n</code></pre>", "should be interrupted by code (indented)" @@ -279,15 +265,12 @@ fn gfm_table() -> Result<(), String> { assert_eq!( to_html_with_options("| a |\n| - |\n```js\ncode?", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() })?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<pre><code class=\"language-js\">code?\n</code></pre>\n", "should be interrupted by code (fenced)" @@ -297,15 +280,12 @@ fn gfm_table() -> Result<(), String> { to_html_with_options( "| a |\n| - |\n***", &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() } )?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<hr />", @@ -313,67 +293,67 @@ fn gfm_table() -> Result<(), String> { ); assert_eq!( - to_html_with_options("| a |\n| - |\n# heading?", &gfm)?, + to_html_with_options("| a |\n| - |\n# heading?", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n<h1>heading?</h1>", "should be interrupted by a heading (ATX)" ); assert_eq!( - to_html_with_options("| a |\n| - |\nheading\n=", &gfm)?, + to_html_with_options("| a |\n| - |\nheading\n=", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>heading</td>\n</tr>\n<tr>\n<td>=</td>\n</tr>\n</tbody>\n</table>", "should *not* be interrupted by a heading (setext)" ); assert_eq!( - to_html_with_options("| a |\n| - |\nheading\n---", &gfm)?, + to_html_with_options("| a |\n| - |\nheading\n---", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>heading</td>\n</tr>\n</tbody>\n</table>\n<hr />", "should *not* be interrupted by a heading (setext), but interrupt if the underline is also a thematic break" ); assert_eq!( - to_html_with_options("| a |\n| - |\nheading\n-", &gfm)?, + to_html_with_options("| a |\n| - |\nheading\n-", &Options::gfm())?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>heading</td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li></li>\n</ul>", "should *not* be interrupted by a heading (setext), but interrupt if the underline is also an empty list item bullet" ); assert_eq!( - to_html_with_options("a\nb\n-:", &gfm)?, + to_html_with_options("a\nb\n-:", &Options::gfm())?, "<p>a</p>\n<table>\n<thead>\n<tr>\n<th align=\"right\">b</th>\n</tr>\n</thead>\n</table>", "should support a single head row" ); assert_eq!( - to_html_with_options("> | a |\n> | - |", &gfm)?, + to_html_with_options("> | a |\n> | - |", &Options::gfm())?, "<blockquote>\n<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n</blockquote>", "should support a table in a container" ); assert_eq!( - to_html_with_options("> | a |\n| - |", &gfm)?, + to_html_with_options("> | a |\n| - |", &Options::gfm())?, "<blockquote>\n<p>| a |\n| - |</p>\n</blockquote>", "should not support a lazy delimiter row if the head row is in a container" ); assert_eq!( - to_html_with_options("| a |\n> | - |", &gfm)?, + to_html_with_options("| a |\n> | - |", &Options::gfm())?, "<p>| a |</p>\n<blockquote>\n<p>| - |</p>\n</blockquote>", "should not support a “piercing” container for the delimiter row, if the head row was not in that container" ); assert_eq!( - to_html_with_options("> | a |\n> | - |\n| c |", &gfm)?, + to_html_with_options("> | a |\n> | - |\n| c |", &Options::gfm())?, "<blockquote>\n<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n</table>\n</blockquote>\n<p>| c |</p>", "should not support a lazy body row if the head row and delimiter row are in a container" ); assert_eq!( - to_html_with_options("> | a |\n| - |\n> | c |", &gfm)?, + to_html_with_options("> | a |\n| - |\n> | c |", &Options::gfm())?, "<blockquote>\n<p>| a |\n| - |\n| c |</p>\n</blockquote>", "should not support a lazy delimiter row if the head row and a further body row are in a container" ); assert_eq!( - to_html_with_options("[\na\n:-\n]: b", &gfm)?, + to_html_with_options("[\na\n:-\n]: b", &Options::gfm())?, "<p>[</p>\n<table>\n<thead>\n<tr>\n<th align=\"left\">a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\">]: b</td>\n</tr>\n</tbody>\n</table>", "should prefer GFM tables over definitions" ); @@ -385,13 +365,9 @@ fn gfm_table() -> Result<(), String> { code_indented: false, ..Constructs::gfm() }, - ..ParseOptions::default() + ..ParseOptions::gfm() }, - compile: CompileOptions { - allow_dangerous_html: true, - allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..Options::gfm() })?, "<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b</td>\n</tr>\n</tbody>\n</table>", "should support indented rows if code (indented) is off" @@ -477,7 +453,7 @@ a | - | - | :- | -: | :-: | | f | "###, - &gfm + &Options::gfm() )?, r###"<h1>Align</h1> <h2>An empty initial cell</h2> @@ -606,7 +582,7 @@ a | - | | b | "###, - &gfm + &Options::gfm() )?, r###"<h1>Tables</h1> <table> @@ -708,7 +684,7 @@ a a |- "###, - &gfm + &Options::gfm() )?, r###"<h1>Tables in things</h1> <h2>In lists</h2> @@ -853,7 +829,7 @@ a | - | | 1 | "###, - &gfm + &Options::gfm() )?, r###"<table> <thead> @@ -931,7 +907,7 @@ bar | abc | def | | --- | --- | "###, - &gfm + &Options::gfm() )?, r###"<h1>Examples from GFM</h1> <h2>A</h2> @@ -1090,15 +1066,12 @@ bar `\|\\` "###, &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() } )?, r###"<h1>Grave accents</h1> @@ -1210,7 +1183,7 @@ a | D | | E | "###, - &gfm + &Options::gfm() )?, r###"<h1>Code</h1> <h2>Indented delimiter row</h2> @@ -1405,15 +1378,12 @@ b *** "###, &Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() - } + ..CompileOptions::gfm() + }, + ..Options::gfm() } )?, r###"<h2>Blank line</h2> @@ -1765,7 +1735,7 @@ b a | - | "###, - &gfm + &Options::gfm() )?, r###"<h1>Loose</h1> <h2>Loose</h2> @@ -1817,7 +1787,7 @@ a Note: GH has a bug where in case C and E, the escaped escape is treated as a normal escape: <https://github.com/github/cmark-gfm/issues/277>. "###, - &gfm + &Options::gfm() )?, r###"<h1>Some more escapes</h1> <table> @@ -1853,7 +1823,7 @@ normal escape: <a href="https://github.com/github/cmark-gfm/issues/277">https:// assert_eq!( to_mdast( "| none | left | right | center |\n| - | :- | -: | :-: |\n| a |\n| b | c | d | e | f |", - &gfm.parse + &ParseOptions::gfm() )?, Node::Root(Root { children: vec![Node::Table(Table { @@ -1956,7 +1926,7 @@ normal escape: <a href="https://github.com/github/cmark-gfm/issues/277">https:// ); assert_eq!( - to_mdast("| `a\\|b` |\n| - |", &gfm.parse)?, + to_mdast("| `a\\|b` |\n| - |", &ParseOptions::gfm())?, Node::Root(Root { children: vec![Node::Table(Table { align: vec![AlignKind::None,], diff --git a/tests/gfm_tagfilter.rs b/tests/gfm_tagfilter.rs index d808374..e75b96b 100644 --- a/tests/gfm_tagfilter.rs +++ b/tests/gfm_tagfilter.rs @@ -10,9 +10,9 @@ fn gfm_tagfilter() -> Result<(), String> { &Options { compile: CompileOptions { allow_dangerous_html: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<iframe>", @@ -25,9 +25,9 @@ fn gfm_tagfilter() -> Result<(), String> { &Options { compile: CompileOptions { gfm_tagfilter: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>a <i></p>\n<script>", @@ -41,9 +41,9 @@ fn gfm_tagfilter() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, gfm_tagfilter: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<iframe>", @@ -99,9 +99,9 @@ javascript:/*--></title></style></textarea></script></xmp><svg/onload='+/"/+/onm compile: CompileOptions { allow_dangerous_html: true, gfm_tagfilter: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, r###"<title> diff --git a/tests/gfm_task_list_item.rs b/tests/gfm_task_list_item.rs index 0ef6ea3..7c68b21 100644 --- a/tests/gfm_task_list_item.rs +++ b/tests/gfm_task_list_item.rs @@ -3,20 +3,12 @@ use markdown::{ mdast::{List, ListItem, Node, Paragraph, Root, Text}, to_html, to_html_with_options, to_mdast, unist::Position, - Constructs, Options, ParseOptions, + Options, ParseOptions, }; use pretty_assertions::assert_eq; #[test] fn gfm_task_list_item() -> Result<(), String> { - let gfm = Options { - parse: ParseOptions { - constructs: Constructs::gfm(), - ..ParseOptions::default() - }, - ..Options::default() - }; - assert_eq!( to_html("* [x] y."), "<ul>\n<li>[x] y.</li>\n</ul>", @@ -24,25 +16,25 @@ fn gfm_task_list_item() -> Result<(), String> { ); assert_eq!( - to_html_with_options("* [x] y.", &gfm)?, + to_html_with_options("* [x] y.", &Options::gfm())?, "<ul>\n<li><input type=\"checkbox\" disabled=\"\" checked=\"\" /> y.</li>\n</ul>", "should support task list item checks" ); assert_eq!( - to_html_with_options("* [ ] z.", &gfm)?, + to_html_with_options("* [ ] z.", &Options::gfm())?, "<ul>\n<li><input type=\"checkbox\" disabled=\"\" /> z.</li>\n</ul>", "should support unchecked task list item checks" ); assert_eq!( - to_html_with_options("*\n [x]", &gfm)?, + to_html_with_options("*\n [x]", &Options::gfm())?, "<ul>\n<li>[x]</li>\n</ul>", "should not support laziness (1)" ); assert_eq!( - to_html_with_options("*\n[x]", &gfm)?, + to_html_with_options("*\n[x]", &Options::gfm())?, "<ul>\n<li></li>\n</ul>\n<p>[x]</p>", "should not support laziness (2)" ); @@ -129,7 +121,7 @@ EOL after: "### .replace('␠', " ") .replace('␉', "\t"), - &gfm + &Options::gfm() )?, r###"<ul> <li><input type="checkbox" disabled="" /> foo</li> @@ -249,7 +241,7 @@ Text.</li> ); assert_eq!( - to_mdast("* [x] a\n* [ ] b\n* c", &gfm.parse)?, + to_mdast("* [x] a\n* [ ] b\n* c", &ParseOptions::gfm())?, Node::Root(Root { children: vec![Node::List(List { ordered: false, diff --git a/tests/hard_break_escape.rs b/tests/hard_break_escape.rs index 44fe6ca..bd6830c 100644 --- a/tests/hard_break_escape.rs +++ b/tests/hard_break_escape.rs @@ -54,9 +54,9 @@ fn hard_break_escape() -> Result<(), String> { hard_break_escape: false, ..Constructs::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>a\\\nb</p>", @@ -64,7 +64,7 @@ fn hard_break_escape() -> Result<(), String> { ); assert_eq!( - to_mdast("a\\\nb.", &ParseOptions::default())?, + to_mdast("a\\\nb.", &Default::default())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![ diff --git a/tests/hard_break_trailing.rs b/tests/hard_break_trailing.rs index 78f5550..ee8f7fc 100644 --- a/tests/hard_break_trailing.rs +++ b/tests/hard_break_trailing.rs @@ -118,11 +118,11 @@ fn hard_break_trailing() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { hard_break_trailing: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>a\nb</p>", @@ -130,7 +130,7 @@ fn hard_break_trailing() -> Result<(), String> { ); assert_eq!( - to_mdast("a \nb.", &ParseOptions::default())?, + to_mdast("a \nb.", &Default::default())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![ diff --git a/tests/heading_atx.rs b/tests/heading_atx.rs index 089c2c7..3edcb55 100644 --- a/tests/heading_atx.rs +++ b/tests/heading_atx.rs @@ -214,11 +214,11 @@ fn heading_atx() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { heading_atx: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p># a</p>", @@ -226,7 +226,7 @@ fn heading_atx() -> Result<(), String> { ); assert_eq!( - to_mdast("## alpha #", &ParseOptions::default())?, + to_mdast("## alpha #", &Default::default())?, Node::Root(Root { children: vec![Node::Heading(Heading { depth: 2, diff --git a/tests/heading_setext.rs b/tests/heading_setext.rs index ec8b056..8cf0863 100644 --- a/tests/heading_setext.rs +++ b/tests/heading_setext.rs @@ -281,11 +281,11 @@ fn heading_setext() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { heading_setext: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>a\n-</p>", @@ -293,7 +293,7 @@ fn heading_setext() -> Result<(), String> { ); assert_eq!( - to_mdast("alpha\nbravo\n==", &ParseOptions::default())?, + to_mdast("alpha\nbravo\n==", &Default::default())?, Node::Root(Root { children: vec![Node::Heading(Heading { depth: 1, diff --git a/tests/html_flow.rs b/tests/html_flow.rs index 41f6565..d79f031 100644 --- a/tests/html_flow.rs +++ b/tests/html_flow.rs @@ -13,9 +13,9 @@ fn html_flow() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -37,11 +37,11 @@ fn html_flow() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { html_flow: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p><x></p>", @@ -49,7 +49,7 @@ fn html_flow() -> Result<(), String> { ); assert_eq!( - to_mdast("<div>\nstuff\n</div>", &ParseOptions::default())?, + to_mdast("<div>\nstuff\n</div>", &Default::default())?, Node::Root(Root { children: vec![Node::Html(Html { value: "<div>\nstuff\n</div>".into(), @@ -69,9 +69,9 @@ fn html_flow_1_raw() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -241,9 +241,9 @@ fn html_flow_2_comment() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -350,9 +350,9 @@ fn html_flow_3_instruction() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -407,9 +407,9 @@ fn html_flow_4_declaration() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -472,9 +472,9 @@ fn html_flow_5_cdata() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -546,9 +546,9 @@ fn html_flow_6_basic() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -833,9 +833,9 @@ fn html_flow_7_complete() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( diff --git a/tests/html_text.rs b/tests/html_text.rs index 5537d3d..43d2cf2 100644 --- a/tests/html_text.rs +++ b/tests/html_text.rs @@ -13,9 +13,9 @@ fn html_text() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -434,11 +434,11 @@ to_html_with_options("<x> a", &danger)?, parse: ParseOptions { constructs: Constructs { html_text: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>a <x></p>", @@ -446,7 +446,7 @@ to_html_with_options("<x> a", &danger)?, ); assert_eq!( - to_mdast("alpha <i>bravo</b> charlie.", &ParseOptions::default())?, + to_mdast("alpha <i>bravo</b> charlie.", &Default::default())?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![ diff --git a/tests/image.rs b/tests/image.rs index 3d53032..2fff14c 100644 --- a/tests/image.rs +++ b/tests/image.rs @@ -204,11 +204,11 @@ fn image() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { label_start_image: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>!<a href=\"\">x</a></p>", @@ -227,9 +227,9 @@ fn image() -> Result<(), String> { &Options { compile: CompileOptions { allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p><img src=\"javascript:alert(1)\" alt=\"\" /></p>", @@ -239,7 +239,7 @@ fn image() -> Result<(), String> { assert_eq!( to_mdast( "a ![alpha]() b ![bravo](charlie 'delta') c.", - &ParseOptions::default() + &Default::default() )?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { @@ -279,7 +279,7 @@ fn image() -> Result<(), String> { assert_eq!( to_mdast( "[x]: y\n\na ![x] b ![x][] c ![d][x] e.", - &ParseOptions::default() + &Default::default() )?, Node::Root(Root { children: vec![ diff --git a/tests/link_reference.rs b/tests/link_reference.rs index 3769fbc..310cf40 100644 --- a/tests/link_reference.rs +++ b/tests/link_reference.rs @@ -13,9 +13,9 @@ fn link_reference() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -397,11 +397,11 @@ fn link_reference() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { label_start_link: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>[x]()</p>", @@ -415,11 +415,11 @@ fn link_reference() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { label_end: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>[x]()</p>", @@ -427,10 +427,7 @@ fn link_reference() -> Result<(), String> { ); assert_eq!( - to_mdast( - "[x]: y\n\na [x] b [x][] c [d][x] e.", - &ParseOptions::default() - )?, + to_mdast("[x]: y\n\na [x] b [x][] c [d][x] e.", &Default::default())?, Node::Root(Root { children: vec![ Node::Definition(Definition { diff --git a/tests/link_resource.rs b/tests/link_resource.rs index 5f9cddc..959d07f 100644 --- a/tests/link_resource.rs +++ b/tests/link_resource.rs @@ -3,7 +3,7 @@ use markdown::{ mdast::{Link, Node, Paragraph, Root, Text}, to_html, to_html_with_options, to_mdast, unist::Position, - CompileOptions, Options, ParseOptions, + CompileOptions, Options, }; use pretty_assertions::assert_eq; @@ -13,9 +13,9 @@ fn link_resource() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -469,7 +469,7 @@ fn link_resource() -> Result<(), String> { assert_eq!( to_mdast( "a [alpha]() b [bravo](charlie 'delta') c.", - &ParseOptions::default() + &Default::default() )?, Node::Root(Root { children: vec![Node::Paragraph(Paragraph { diff --git a/tests/list.rs b/tests/list.rs index 476361e..cb4019b 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -13,9 +13,9 @@ fn list() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -579,11 +579,11 @@ fn list() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { list_item: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>- one</p>\n<p>two</p>", @@ -591,7 +591,7 @@ fn list() -> Result<(), String> { ); assert_eq!( - to_mdast("* a", &ParseOptions::default())?, + to_mdast("* a", &Default::default())?, Node::Root(Root { children: vec![Node::List(List { ordered: false, @@ -617,7 +617,7 @@ fn list() -> Result<(), String> { ); assert_eq!( - to_mdast("3. a", &ParseOptions::default())?, + to_mdast("3. a", &Default::default())?, Node::Root(Root { children: vec![Node::List(List { ordered: true, @@ -643,7 +643,7 @@ fn list() -> Result<(), String> { ); assert_eq!( - to_mdast("* a\n\n b\n* c", &ParseOptions::default())?, + to_mdast("* a\n\n b\n* c", &Default::default())?, Node::Root(Root { children: vec![Node::List(List { ordered: false, diff --git a/tests/math_flow.rs b/tests/math_flow.rs index b3ce669..18795ab 100644 --- a/tests/math_flow.rs +++ b/tests/math_flow.rs @@ -14,11 +14,11 @@ fn math_flow() -> Result<(), String> { constructs: Constructs { math_text: true, math_flow: true, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( diff --git a/tests/math_text.rs b/tests/math_text.rs index 892690b..4b6fb6a 100644 --- a/tests/math_text.rs +++ b/tests/math_text.rs @@ -14,11 +14,11 @@ fn math_text() -> Result<(), String> { constructs: Constructs { math_text: true, math_flow: true, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -41,12 +41,12 @@ fn math_text() -> Result<(), String> { constructs: Constructs { math_text: true, math_flow: true, - ..Constructs::default() + ..Default::default() }, math_text_single_dollar: false, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>$foo$ <code class=\"language-math math-inline\">bar</code></p>", @@ -151,14 +151,14 @@ fn math_text() -> Result<(), String> { constructs: Constructs { math_text: true, math_flow: true, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() } } )?, diff --git a/tests/mdx_esm.rs b/tests/mdx_esm.rs index 4d96b09..b64a5e9 100644 --- a/tests/mdx_esm.rs +++ b/tests/mdx_esm.rs @@ -16,9 +16,9 @@ fn mdx_esm() -> Result<(), String> { constructs: Constructs::mdx(), mdx_esm_parse: Some(Box::new(parse_esm)), mdx_expression_parse: Some(Box::new(parse_expression)), - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( diff --git a/tests/mdx_expression_flow.rs b/tests/mdx_expression_flow.rs index fe07743..4281e5d 100644 --- a/tests/mdx_expression_flow.rs +++ b/tests/mdx_expression_flow.rs @@ -12,11 +12,8 @@ use test_utils::swc::{parse_esm, parse_expression}; #[test] fn mdx_expression_flow_agnostic() -> Result<(), String> { let mdx = Options { - parse: ParseOptions { - constructs: Constructs::mdx(), - ..ParseOptions::default() - }, - ..Options::default() + parse: ParseOptions::mdx(), + ..Default::default() }; assert_eq!( @@ -39,11 +36,11 @@ fn mdx_expression_flow_agnostic() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { mdx_expression_flow: true, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<pre><code>{}\n</code></pre>", @@ -57,11 +54,11 @@ fn mdx_expression_flow_agnostic() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { mdx_expression_flow: true, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "", @@ -149,9 +146,9 @@ fn mdx_expression_flow_gnostic() -> Result<(), String> { constructs: Constructs::mdx(), mdx_esm_parse: Some(Box::new(parse_esm)), mdx_expression_parse: Some(Box::new(parse_expression)), - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -224,9 +221,9 @@ fn mdx_expression_spread() -> Result<(), String> { constructs: Constructs::mdx(), mdx_esm_parse: Some(Box::new(parse_esm)), mdx_expression_parse: Some(Box::new(parse_expression)), - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( diff --git a/tests/mdx_expression_text.rs b/tests/mdx_expression_text.rs index 61f5170..4ab26dd 100644 --- a/tests/mdx_expression_text.rs +++ b/tests/mdx_expression_text.rs @@ -16,9 +16,9 @@ fn mdx_expression_text_gnostic_core() -> Result<(), String> { constructs: Constructs::mdx(), mdx_esm_parse: Some(Box::new(parse_esm)), mdx_expression_parse: Some(Box::new(parse_expression)), - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -149,11 +149,8 @@ fn mdx_expression_text_gnostic_core() -> Result<(), String> { #[test] fn mdx_expression_text_agnostic() -> Result<(), String> { let mdx = Options { - parse: ParseOptions { - constructs: Constructs::mdx(), - ..ParseOptions::default() - }, - ..Options::default() + parse: ParseOptions::mdx(), + ..Default::default() }; assert_eq!( @@ -236,9 +233,9 @@ fn mdx_expression_text_gnostic() -> Result<(), String> { constructs: Constructs::mdx(), mdx_esm_parse: Some(Box::new(parse_esm)), mdx_expression_parse: Some(Box::new(parse_expression)), - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( diff --git a/tests/mdx_jsx_flow.rs b/tests/mdx_jsx_flow.rs index 337b4cd..219b0b5 100644 --- a/tests/mdx_jsx_flow.rs +++ b/tests/mdx_jsx_flow.rs @@ -10,11 +10,8 @@ use pretty_assertions::assert_eq; #[test] fn mdx_jsx_flow_agnostic() -> Result<(), String> { let mdx = Options { - parse: ParseOptions { - constructs: Constructs::mdx(), - ..ParseOptions::default() - }, - ..Options::default() + parse: ParseOptions::mdx(), + ..Default::default() }; assert_eq!( @@ -32,11 +29,11 @@ fn mdx_jsx_flow_agnostic() -> Result<(), String> { constructs: Constructs { html_flow: false, mdx_jsx_flow: true, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<pre><code><a />\n</code></pre>", @@ -51,11 +48,11 @@ fn mdx_jsx_flow_agnostic() -> Result<(), String> { constructs: Constructs { html_flow: false, mdx_jsx_flow: true, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "", @@ -94,11 +91,8 @@ fn mdx_jsx_flow_agnostic() -> Result<(), String> { #[test] fn mdx_jsx_flow_essence() -> Result<(), String> { let mdx = Options { - parse: ParseOptions { - constructs: Constructs::mdx(), - ..ParseOptions::default() - }, - ..Options::default() + parse: ParseOptions::mdx(), + ..Default::default() }; assert_eq!( diff --git a/tests/mdx_jsx_text.rs b/tests/mdx_jsx_text.rs index d6e3d56..a64df64 100644 --- a/tests/mdx_jsx_text.rs +++ b/tests/mdx_jsx_text.rs @@ -15,11 +15,8 @@ use test_utils::swc::{parse_esm, parse_expression}; #[test] fn mdx_jsx_text_core() -> Result<(), String> { let mdx = Options { - parse: ParseOptions { - constructs: Constructs::mdx(), - ..ParseOptions::default() - }, - ..Options::default() + parse: ParseOptions::mdx(), + ..Default::default() }; assert_eq!( @@ -487,11 +484,8 @@ fn mdx_jsx_text_core() -> Result<(), String> { #[test] fn mdx_jsx_text_agnosic() -> Result<(), String> { let mdx = Options { - parse: ParseOptions { - constructs: Constructs::mdx(), - ..ParseOptions::default() - }, - ..Options::default() + parse: ParseOptions::mdx(), + ..Default::default() }; assert_eq!( @@ -534,9 +528,9 @@ fn mdx_jsx_text_gnostic() -> Result<(), String> { constructs: Constructs::mdx(), mdx_esm_parse: Some(Box::new(parse_esm)), mdx_expression_parse: Some(Box::new(parse_expression)), - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( @@ -631,11 +625,8 @@ fn mdx_jsx_text_gnostic() -> Result<(), String> { #[test] fn mdx_jsx_text_complete() -> Result<(), String> { let mdx = Options { - parse: ParseOptions { - constructs: Constructs::mdx(), - ..ParseOptions::default() - }, - ..Options::default() + parse: ParseOptions::mdx(), + ..Default::default() }; assert_eq!( diff --git a/tests/mdx_swc.rs b/tests/mdx_swc.rs index ed9bc60..a24864f 100644 --- a/tests/mdx_swc.rs +++ b/tests/mdx_swc.rs @@ -11,9 +11,9 @@ fn mdx_swc() -> Result<(), String> { constructs: Constructs::mdx(), mdx_esm_parse: Some(Box::new(parse_esm)), mdx_expression_parse: Some(Box::new(parse_expression)), - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( diff --git a/tests/misc_dangerous_html.rs b/tests/misc_dangerous_html.rs index 6de045f..0610d23 100644 --- a/tests/misc_dangerous_html.rs +++ b/tests/misc_dangerous_html.rs @@ -8,9 +8,9 @@ fn dangerous_html() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( diff --git a/tests/misc_default_line_ending.rs b/tests/misc_default_line_ending.rs index 306b1bc..65c5867 100644 --- a/tests/misc_default_line_ending.rs +++ b/tests/misc_default_line_ending.rs @@ -34,9 +34,9 @@ fn default_line_ending() -> Result<(), String> { &Options { compile: CompileOptions { default_line_ending: LineEnding::CarriageReturn, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<blockquote>\r<p>a</p>\r</blockquote>", @@ -49,9 +49,9 @@ fn default_line_ending() -> Result<(), String> { &Options { compile: CompileOptions { default_line_ending: LineEnding::CarriageReturn, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, // To do: is this a bug in `to_html.js` that it uses `\r` for earlier line endings? diff --git a/tests/misc_line_ending.rs b/tests/misc_line_ending.rs index 52b84d8..ed91265 100644 --- a/tests/misc_line_ending.rs +++ b/tests/misc_line_ending.rs @@ -8,9 +8,9 @@ fn line_ending() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!(to_html("\n"), "", "should support just a line feed"); diff --git a/tests/misc_tabs.rs b/tests/misc_tabs.rs index 5de8de2..681f0b2 100644 --- a/tests/misc_tabs.rs +++ b/tests/misc_tabs.rs @@ -8,9 +8,9 @@ fn tabs_flow() -> Result<(), String> { compile: CompileOptions { allow_dangerous_html: true, allow_dangerous_protocol: true, - ..CompileOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() }; assert_eq!( diff --git a/tests/thematic_break.rs b/tests/thematic_break.rs index 735829d..35fa2e0 100644 --- a/tests/thematic_break.rs +++ b/tests/thematic_break.rs @@ -178,11 +178,11 @@ fn thematic_break() -> Result<(), String> { parse: ParseOptions { constructs: Constructs { thematic_break: false, - ..Constructs::default() + ..Default::default() }, - ..ParseOptions::default() + ..Default::default() }, - ..Options::default() + ..Default::default() } )?, "<p>***</p>", @@ -190,7 +190,7 @@ fn thematic_break() -> Result<(), String> { ); assert_eq!( - to_mdast("***", &ParseOptions::default())?, + to_mdast("***", &Default::default())?, Node::Root(Root { children: vec![Node::ThematicBreak(ThematicBreak { position: Some(Position::new(1, 1, 0, 1, 4, 3)) diff --git a/tests/xxx_mdx_plugin_recma_document.rs b/tests/xxx_mdx_plugin_recma_document.rs index de25699..9fdd053 100644 --- a/tests/xxx_mdx_plugin_recma_document.rs +++ b/tests/xxx_mdx_plugin_recma_document.rs @@ -3,7 +3,7 @@ extern crate swc_common; extern crate swc_ecma_ast; extern crate swc_ecma_codegen; mod test_utils; -use markdown::{to_mdast, Constructs, Location, ParseOptions}; +use markdown::{to_mdast, Location, ParseOptions}; use pretty_assertions::assert_eq; use test_utils::{ hast_util_to_swc::hast_util_to_swc, @@ -17,10 +17,9 @@ fn from_markdown(value: &str) -> Result<String, String> { let mdast = to_mdast( value, &ParseOptions { - constructs: Constructs::mdx(), mdx_esm_parse: Some(Box::new(parse_esm)), mdx_expression_parse: Some(Box::new(parse_expression)), - ..ParseOptions::default() + ..ParseOptions::mdx() }, )?; let hast = mdast_util_to_hast(&mdast); diff --git a/tests/xxx_mdx_plugin_recma_jsx_rewrite.rs b/tests/xxx_mdx_plugin_recma_jsx_rewrite.rs index 9b9a4bc..d78e5c8 100644 --- a/tests/xxx_mdx_plugin_recma_jsx_rewrite.rs +++ b/tests/xxx_mdx_plugin_recma_jsx_rewrite.rs @@ -3,7 +3,7 @@ extern crate swc_common; extern crate swc_ecma_ast; extern crate swc_ecma_codegen; mod test_utils; -use markdown::{to_mdast, Constructs, Location, ParseOptions}; +use markdown::{to_mdast, Location, ParseOptions}; use pretty_assertions::assert_eq; use test_utils::{ hast_util_to_swc::hast_util_to_swc, @@ -18,10 +18,9 @@ fn from_markdown(value: &str, options: &RewriteOptions) -> Result<String, String let mdast = to_mdast( value, &ParseOptions { - constructs: Constructs::mdx(), mdx_esm_parse: Some(Box::new(parse_esm)), mdx_expression_parse: Some(Box::new(parse_expression)), - ..ParseOptions::default() + ..ParseOptions::mdx() }, )?; let hast = mdast_util_to_hast(&mdast); |