diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-06-24 17:57:10 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-06-24 17:57:10 +0200 |
commit | a3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0 (patch) | |
tree | 7b4bf040da23a03f38efe92a252e187a630a14f6 /tests/misc_url.rs | |
parent | e7b3761c8cd6f0f902dd9927e4fbf2589465ed57 (diff) | |
download | markdown-rs-a3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0.tar.gz markdown-rs-a3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0.tar.bz2 markdown-rs-a3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0.zip |
Add link, images (resource)
This is still some messy code that needs cleaning up, but it adds support for
links and images, of the resource kind (`[a](b)`).
References (`[a][b]`) are parsed and will soon be supported, but need matching.
* Fix bug to pad percent-encoded bytes when normalizing urls
* Fix bug with escapes counting as balancing in destination
* Add `space_or_tab_one_line_ending`, to parse whitespace including up to
one line ending (but not a blank line)
* Add `ParserState` to share codes, definitions, etc
Diffstat (limited to '')
-rw-r--r-- | tests/misc_url.rs | 107 |
1 files changed, 51 insertions, 56 deletions
diff --git a/tests/misc_url.rs b/tests/misc_url.rs index a6f8ead..5e94366 100644 --- a/tests/misc_url.rs +++ b/tests/misc_url.rs @@ -9,28 +9,25 @@ fn url() { "should support incorrect percentage encoded values (0)" ); - // To do: link. - // assert_eq!( - // micromark("[](<%>)"), - // "<p><a href=\"%25\"></a></p>", - // "should support incorrect percentage encoded values (1)" - // ); - - // To do: link. - // assert_eq!( - // micromark("[](<%%20>)"), - // "<p><a href=\"%25%20\"></a></p>", - // "should support incorrect percentage encoded values (2)" - // ); - - // To do: link. - // assert_eq!( - // micromark("[](<%a%20>)"), - // "<p><a href=\"%25a%20\"></a></p>", - // "should support incorrect percentage encoded values (3)" - // ); + assert_eq!( + micromark("[](<%>)"), + "<p><a href=\"%25\"></a></p>", + "should support incorrect percentage encoded values (1)" + ); - // Surrogate handling not needed in Rust. + assert_eq!( + micromark("[](<%%20>)"), + "<p><a href=\"%25%20\"></a></p>", + "should support incorrect percentage encoded values (2)" + ); + + assert_eq!( + micromark("[](<%a%20>)"), + "<p><a href=\"%25a%20\"></a></p>", + "should support incorrect percentage encoded values (3)" + ); + + // Note: Surrogate handling not needed in Rust. // assert_eq!( // micromark("[](<foo\u{D800}bar>)"), // "<p><a href=\"foo%EF%BF%BDbar\"></a></p>", @@ -114,39 +111,37 @@ fn url() { // "should support a lone low surrogate at the end (highest)" // ); - // To do: link. - // assert_eq!( - // micromark("[](<🤔>)"), - // "<p><a href=\"%F0%9F%A4%94\"></a></p>", - // "should support an emoji" - // ); - - // To do: link. - // let mut ascii: Vec<char> = vec![]; - // let mut code = 0; - - // while code < 128 { - // // LF and CR can’t be in resources. - // if code == 10 || code == 13 { - // code += 1; - // continue; - // } - - // // `<`, `>`, `\` need to be escaped. - // if code == 60 || code == 62 || code == 92 { - // ascii.push('\\'); - // } - - // ascii.push(char::from_u32(code).unwrap()); - - // code += 1; - // } - - // let ascii_in = ascii.into_iter().collect::<String>(); - // let ascii_out = "%EF%BF%BD%01%02%03%04%05%06%07%08%09%0B%0C%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22#$%25&\"()*+,-./0123456789:;%3C=%3E?@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F"; - // assert_eq!( - // micromark(&format!("[](<{}>)", ascii_in)), - // format!("<p><a href=\"{}\"></a></p>", ascii_out), - // "should support ascii characters" - // ); + assert_eq!( + micromark("[](<🤔>)"), + "<p><a href=\"%F0%9F%A4%94\"></a></p>", + "should support an emoji" + ); + + let mut ascii: Vec<char> = vec![]; + let mut code = 0; + + while code < 128 { + // LF and CR can’t be in resources. + if code == 10 || code == 13 { + code += 1; + continue; + } + + // `<`, `>`, `\` need to be escaped. + if code == 60 || code == 62 || code == 92 { + ascii.push('\\'); + } + + ascii.push(char::from_u32(code).unwrap()); + + code += 1; + } + + let ascii_in = ascii.into_iter().collect::<String>(); + let ascii_out = "%EF%BF%BD%01%02%03%04%05%06%07%08%09%0B%0C%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22#$%25&'()*+,-./0123456789:;%3C=%3E?@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F"; + assert_eq!( + micromark(&format!("[](<{}>)", ascii_in)), + format!("<p><a href=\"{}\"></a></p>", ascii_out), + "should support ascii characters" + ); } |