//! A tag written in code or in a comment opens no `markdown` element, so the //! lines after it are ordinary document lines in every flavor. use rumdl_lib::config::MarkdownFlavor; use rumdl_lib::lint_context::LintContext; const FLAVORS: [MarkdownFlavor; 2] = [MarkdownFlavor::Standard, MarkdownFlavor::MkDocs]; /// 1-indexed lines the document reads as inside a `markdown` element. fn container_lines(doc: &str, flavor: MarkdownFlavor) -> Vec { let ctx = LintContext::new(doc, flavor, None); (1..=doc.lines().count()) .filter(|&n| ctx.line_info(n).is_some_and(|l| l.in_mkdocs_html_markdown)) .collect() } #[test] fn a_tag_in_an_html_comment_opens_nothing() { for flavor in FLAVORS { for value in ["1", "span"] { let doc = format!("\n\nafter\n"); assert_eq!(container_lines(&doc, flavor), Vec::::new(), "{flavor:?} {value}"); } } } #[test] fn a_tag_in_an_indented_code_block_opens_nothing() { for flavor in FLAVORS { let doc = "para\n\n
\n\nafter\n"; assert_eq!(container_lines(doc, flavor), Vec::::new(), "{flavor:?}"); } } #[test] fn a_real_tag_next_to_a_comment_still_opens_its_element() { // Positive control: the same shapes without the code context do open one. for flavor in FLAVORS { let doc = "\n
\ninside\n
\n\nafter\n"; assert_eq!(container_lines(doc, flavor), vec![2, 3, 4], "{flavor:?}"); } } #[test] fn a_nested_tag_indented_inside_an_open_element_is_still_a_tag() { for flavor in FLAVORS { let doc = "
\n\n
\n inner\n
\n\n
\n\nafter\n"; let lines = container_lines(doc, flavor); assert!( lines.contains(&3) && lines.contains(&4) && !lines.contains(&9), "{flavor:?} {lines:?}" ); } } #[test] fn a_closing_tag_after_a_comment_on_the_same_line_still_closes_the_element() { for flavor in FLAVORS { let doc = "
\n
\n\nafter\n"; assert_eq!(container_lines(doc, flavor), vec![1, 2], "{flavor:?}"); } } #[test] fn a_tag_in_a_code_span_that_starts_the_line_opens_nothing() { // An inline element can start a line inside a paragraph, and a code span // can run across the line break in front of it. for flavor in FLAVORS { let doc = "text `\n