Files
marqdo-lint/examples/render_fixtures.rs
T

47 lines
1.7 KiB
Rust

use std::{fs, path::Path};
use comrak::{markdown_to_html, Options};
fn main() {
let manifest = Path::new(env!("CARGO_MANIFEST_DIR"));
let fixtures = [
(
"examples/good/branches.mq.md",
"examples/rendered/branches.html",
),
(
"examples/bad/branch-single-item.mq.md",
"examples/rendered/branch-single-item.html",
),
(
"examples/bad/branches-unlisted.mq.md",
"examples/rendered/branches-unlisted.html",
),
(
"examples/nested/inventory.mq.md",
"examples/rendered/inventory.html",
),
(
"examples/knowledge/discount.mq.md",
"examples/rendered/discount.html",
),
];
let mut options = Options::default();
options.extension.table = true;
options.extension.strikethrough = true;
options.extension.tasklist = true;
options.extension.math_dollars = true;
options.extension.math_dollars_block = true;
options.extension.front_matter_delimiter = Some("---".to_string());
for (source, target) in fixtures {
let source_path = manifest.join(source);
let markdown = fs::read_to_string(&source_path).expect("读取渲染 Fixture");
let body = markdown_to_html(&markdown, &options);
let html = format!("<!doctype html>\n<html lang=\"zh-CN\">\n<meta charset=\"utf-8\">\n<title>Marqdo Lint Review Fixture</title>\n<body>\n{body}</body>\n</html>\n");
let target = manifest.join(target);
fs::create_dir_all(target.parent().expect("Fixture 父目录")).expect("创建渲染目录");
fs::write(target, html).expect("写入渲染 Fixture");
}
}