Migrate custom_header_attributes to BookTest

This commit is contained in:
Eric Huss 2025-04-22 11:30:11 -07:00
parent 74e01ea6e3
commit 6904653a82
5 changed files with 21 additions and 16 deletions

View file

@ -829,22 +829,6 @@ fn custom_fonts() {
);
}
#[test]
fn custom_header_attributes() {
let temp = DummyBook::new().build().unwrap();
let md = MDBook::load(temp.path()).unwrap();
md.build().unwrap();
let contents = temp.path().join("book/first/heading-attributes.html");
let summary_strings = &[
r##"<h1 id="attrs"><a class="header" href="#attrs">Heading Attributes</a></h1>"##,
r##"<h2 id="heading-with-classes" class="class1 class2"><a class="header" href="#heading-with-classes">Heading with classes</a></h2>"##,
r##"<h2 id="both" class="class1 class2"><a class="header" href="#both">Heading with id and classes</a></h2>"##,
];
assert_contains_strings(&contents, summary_strings);
}
#[test]
fn with_no_source_path() {
// Test for a regression where search would fail if source_path is None.

View file

@ -2,6 +2,17 @@
use crate::prelude::*;
// Checks custom header id and classes.
#[test]
fn custom_header_attributes() {
BookTest::from_dir("markdown/custom_header_attributes")
.check_main_file("book/custom_header_attributes.html", str![[r##"
<h1 id="attrs"><a class="header" href="#attrs">Heading Attributes</a></h1>
<h2 id="heading-with-classes" class="class1 class2"><a class="header" href="#heading-with-classes">Heading with classes</a></h2>
<h2 id="both" class="class1 class2"><a class="header" href="#both">Heading with id and classes</a></h2>
"##]]);
}
// Test for a variety of footnote renderings.
#[test]
fn footnotes() {

View file

@ -0,0 +1,2 @@
[book]
title = "custom_header_attributes"

View file

@ -0,0 +1,3 @@
# Summary
- [Heading Attributes](./custom_header_attributes.md)

View file

@ -0,0 +1,5 @@
# Heading Attributes {#attrs}
## Heading with classes {.class1 .class2}
## Heading with id and classes {#both .class1 .class2}