mini-docs 0.3.6

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

use mini_docs::Builder;

/// The crate's most important test: run the full build pipeline — Markdown render,
/// sanitize, then a template that renders `{{ page.content | safe }}` — over a
/// fixture containing a `<script>` tag and an `onerror=` event handler, and assert
/// neither survives into the written HTML file.
#[test]
fn full_pipeline_strips_script_and_event_handler_before_safe_render() {
    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("page.md"),
        "# Title\n\n<script>alert(1)</script>\n\n<img src=\"x\" onerror=\"alert(1)\">\n",
    )
    .expect("write page.md");

    fs::write(
        templates.path().join("page.html"),
        "<!doctype html><title>{{ page.title }}</title><body>{{ page.content | safe }}</body>",
    )
    .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("page.html")).expect("read output file");

    assert!(
        !written.contains("<script>"),
        "script tag survived sanitization: {written}"
    );
    assert!(
        !written.contains("onerror"),
        "event handler survived sanitization: {written}"
    );
    assert!(
        written.contains("Title"),
        "legitimate content was stripped too: {written}"
    );
}