//! Under the MkDocs flavor MD077 must place a nested item's continuation where //! Python-Markdown reads it as that item's content: four columns per nesting //! level, not the CommonMark content column. //! //! pulldown-cmark is CommonMark and cannot judge MkDocs structure, so the //! expectations are exact outputs. The documents were rendered with //! Python-Markdown 3.11 (`markdown.markdown(text, extensions=["tables", //! "def_list", "admonition", "fenced_code"])`); the rendering that fixes each //! expectation is quoted beside it. The standard-flavor controls do use the //! pulldown-cmark structure oracle. use super::cli_md077_continuation_structure_test::structure; use std::fs; use std::process::Command; use tempfile::tempdir; /// One `rumdl check --fix` run with MD077 alone under `flavor`. fn fix_once(content: &str, flavor: &str) -> String { let dir = tempdir().unwrap(); let path = dir.path().join("doc.md"); fs::write(&path, content).unwrap(); // The exit status reports what is left unfixed, which is not under test. Command::new(env!("CARGO_BIN_EXE_rumdl")) .current_dir(dir.path()) .args([ "check", "--isolated", "--no-cache", "--fix", "--flavor", flavor, "--enable", "MD077", ]) .arg(&path) .output() .expect("run rumdl check --fix"); fs::read_to_string(&path).unwrap() } /// Layouts Python-Markdown reads as content of the innermost item. const CORRECT: &[&str] = &[ //
b
text
c
text
b
text
a
b
c
text
a
text
b
text
texta
text
para text
`) and is snapped back like any over-indented continuation. #[test] fn mkdocs_over_indented_paragraph_continuation_is_not_taken_for_code() { assert_eq!( fix_once("- a\n\n para\n text\n", "mkdocs"), "- a\n\n para\n text\n" ); assert_eq!( fix_once("- a\n - b\n\n para\n text\n", "mkdocs"), "- a\n - b\n\n para\n text\n" ); } /// A marker two levels below its parent is text of the parent's paragraph for /// Python-Markdown, and what follows it is literal code that must keep its /// indentation: ` text- - b
text`), so the line below is
/// literal code that keeps its indentation. With a space after the marker it is
/// an item and the line is its content.
#[test]
fn mkdocs_bare_marker_is_not_an_item() {
for content in [
"-\n - b\n\n text\n",
"1.\n - b\n\n text\n",
"- a\n -\n\n text\n",
"-\n -\n\n text\n",
] {
assert_eq!(fix_once(content, "mkdocs"), content, "{content:?}");
}
assert_eq!(
fix_once("- \n - b\n\n text\n", "mkdocs"),
"- \n - b\n\n text\n"
);
}
/// The bare marker above a heading is not the parent of the list below it.
#[test]
fn mkdocs_bare_marker_does_not_unscope_a_later_list() {
assert_eq!(
fix_once("-\n\n# Heading\n\n - b\n\n text\n", "mkdocs"),
"-\n\n# Heading\n\n - b\n\n text\n"
);
}
/// Python-Markdown does not know `1)`: `b` is text of `a`, so text at column 7
/// is a paragraph of `a` and text at column 8 is indented code.
#[test]
fn mkdocs_paren_marker_is_not_an_item() {
let paragraph = "- a\n 1) b\n\n text\n";
assert_eq!(fix_once(paragraph, "mkdocs"), paragraph);
let code = "- a\n 1) b\n\n text\n";
assert_eq!(fix_once(code, "mkdocs"), code);
}
/// Python-Markdown reads `- b` as text of `- a` here, so the text at column 10
/// is a paragraph; at column 12 it would be code.
#[test]
fn mkdocs_item_below_a_same_line_item_is_text() {
let content = "1. - a\n - b\n\n text\n";
assert_eq!(fix_once(content, "mkdocs"), content);
}