Skip to content

Commit e3be293

Browse files
committed
Add an integration test for heading attributes
1 parent 861197e commit e3be293

File tree

4 files changed

+431
-117
lines changed

4 files changed

+431
-117
lines changed

tests/dummy_book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [Unicode](first/unicode.md)
1515
- [No Headers](first/no-headers.md)
1616
- [Duplicate Headers](first/duplicate-headers.md)
17+
- [Heading Attributes](first/heading-attributes.md)
1718
- [Second Chapter](second.md)
1819
- [Nested Chapter](second/nested.md)
1920

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Heading Attributes {#attrs}
2+
3+
## Heading with classes {.class1 .class2}
4+
5+
## Heading with id and classes {#both .class1 .class2}

tests/rendered_output.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const TOC_SECOND_LEVEL: &[&str] = &[
3535
"1.5. Unicode",
3636
"1.6. No Headers",
3737
"1.7. Duplicate Headers",
38+
"1.8. Heading Attributes",
3839
"2.1. Nested Chapter",
3940
];
4041

@@ -766,7 +767,7 @@ mod search {
766767
assert_eq!(docs[&some_section]["body"], "");
767768
assert_eq!(
768769
docs[&summary]["body"],
769-
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode No Headers Duplicate Headers Second Chapter Nested Chapter Conclusion"
770+
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode No Headers Duplicate Headers Heading Attributes Second Chapter Nested Chapter Conclusion"
770771
);
771772
assert_eq!(
772773
docs[&summary]["breadcrumbs"],
@@ -946,3 +947,19 @@ fn custom_fonts() {
946947
&["fonts.css", "myfont.woff"]
947948
);
948949
}
950+
951+
#[test]
952+
fn custom_header_attributes() {
953+
let temp = DummyBook::new().build().unwrap();
954+
let md = MDBook::load(temp.path()).unwrap();
955+
md.build().unwrap();
956+
957+
let contents = temp.path().join("book/first/heading-attributes.html");
958+
959+
let summary_strings = &[
960+
r##"<h1 id="attrs"><a class="header" href="#attrs">Heading Attributes</a></h1>"##,
961+
r##"<h2 id="heading-with-classes" class="class1 class2"><a class="header" href="#heading-with-classes">Heading with classes</a></h2>"##,
962+
r##"<h2 id="both" class="class1 class2"><a class="header" href="#both">Heading with id and classes</a></h2>"##,
963+
];
964+
assert_contains_strings(&contents, summary_strings);
965+
}

0 commit comments

Comments
 (0)