use crate::cm::{escape_inline, escape_link_destination}; use crate::{Arena, Options, entity, format_commonmark, markdown_to_html, parse_document}; /// Assert that the input text escapes to the expected result in inline context, /// and that the expected result renders to HTML which displays the input text. #[track_caller] fn assert_escape_inline(input: &str, expected: &str) { let actual = escape_inline(input); assert_eq!(expected, actual); let mut html = markdown_to_html(expected, &Options::default()); html = html .strip_prefix("
") .expect("html should be one paragraph") .to_string(); html = html .strip_suffix("
\n") .expect("html should be one paragraph") .to_string(); assert_eq!(input, entity::unescape_html(&html)); } #[test] fn escape_inline_baseline() { assert_escape_inline("abcdefg", "abcdefg"); assert_escape_inline("*hello*", r#"\*hello\*"#); assert_escape_inline( "[A link](https://link.com)", r#"\[A link\]\(https://link\.com\)"#, ); assert_escape_inline( r#"some <"complicated"> & '/problematic\' input"#, r#"some \<\"complicated\"\> \& '/problematic\\' input"#, ); } /// Assert that the URL is escaped as expected, and that the result is rendered /// into HTML in such a way that preserves the meaning of the input. /// /// [link destination]: https://spec.commonmark.org/0.31.2/#link-destination #[test] fn escape_link_target() { let url = "rabbits)