mini-docs 0.3.7

A minimal, secure build-time Markdown to HTML generator for the mini-* family.
Documentation
use std::fs;

use mini_docs::Builder;

/// The M0 exit criterion: one `input.md`, one `page.html` template, one hand-derived
/// `output.html`. No frontmatter `title` is set, exercising the heading-fallback path.
///
/// The expected string is derived by hand, not copied from a prior run:
/// - pulldown-cmark's HTML serializer (`html.rs` `start_tag`/`end_tag`) emits each
///   block tag on its own line: `<h1 id="...">Heading</h1>\n<p>...</p>\n`.
/// - every heading gets an auto-slugified `id` (`page::slugify`): "Getting Started"
///   lowercases and joins on `-` to `getting-started`.
/// - `sanitize_html` allowlists `id` as a generic attribute specifically so this
///   survives ammonia's default policy (which otherwise only allows `id` on `<a>`).
/// - Tera substitutes `{{ ... }}` in place, changing none of the template's literal
///   surrounding whitespace.
#[test]
fn build_produces_byte_exact_output_for_known_input_and_template() {
    let input = tempfile::tempdir().expect("create input tempdir");
    let templates = tempfile::tempdir().expect("create templates tempdir");
    let output = tempfile::tempdir().expect("create output tempdir");

    fs::write(
        input.path().join("guide.md"),
        "# Getting Started\n\nWelcome to the guide.\n",
    )
    .expect("write guide.md");

    fs::write(
        templates.path().join("page.html"),
        "<!doctype html>\n<title>{{ page.title }}</title>\n<body>{{ page.content | safe }}</body>\n",
    )
    .expect("write page.html");

    Builder::new(input.path())
        .templates(templates.path())
        .output(output.path())
        .default_template("page.html")
        .build()
        .expect("build should succeed");

    let written = fs::read_to_string(output.path().join("guide.html")).expect("read output file");

    let expected = "<!doctype html>\n<title>Getting Started</title>\n<body><h1 id=\"getting-started\">Getting Started</h1>\n<p>Welcome to the guide.</p>\n</body>\n";

    assert_eq!(written, expected);
}