diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs
index a4e65fab..e753dc2e 100644
--- a/src/renderer/html_handlebars/hbs_renderer.rs
+++ b/src/renderer/html_handlebars/hbs_renderer.rs
@@ -832,10 +832,12 @@ fn insert_link_into_header(
id_counter: &mut HashMap,
) -> String {
let id = id.unwrap_or_else(|| utils::unique_id_from_content(content, id_counter));
- let classes = classes.unwrap_or("".to_string());
+ let classes = classes
+ .map(|s| format!(" class=\"{s}\""))
+ .unwrap_or_default();
format!(
- r##""##,
+ r##""##,
level = level,
id = id,
text = content,
@@ -1014,28 +1016,39 @@ mod tests {
let inputs = vec![
(
"blah blah Foo
",
- r##"blah blah "##,
+ r##"blah blah "##,
),
(
"Foo
",
- r##""##,
+ r##""##,
),
(
"Foo^bar
",
- r##""##,
+ r##""##,
),
(
"",
- r##""##,
+ r##""##,
),
(
"Hï
",
- r##""##,
+ r##""##,
),
(
"Foo
Foo
",
- r##""##,
+ r##""##,
),
+ // id only
+ (
+ r##"Foo
"##,
+ r##""##,
+ ),
+ // class only
+ (
+ r##"Foo
"##,
+ r##""##,
+ ),
+ // both id and class
(
r##"Foo
"##,
r##""##,
diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs
index 9fffe7bc..813f70fd 100644
--- a/tests/rendered_output.rs
+++ b/tests/rendered_output.rs
@@ -105,12 +105,12 @@ fn check_correct_cross_links_in_nested_dir() {
assert_contains_strings(
first.join("index.html"),
- &[r##"