@@ -832,10 +832,12 @@ fn insert_link_into_header(
832
832
id_counter : & mut HashMap < String , usize > ,
833
833
) -> String {
834
834
let id = id. unwrap_or_else ( || utils:: unique_id_from_content ( content, id_counter) ) ;
835
- let classes = classes. unwrap_or ( "" . to_string ( ) ) ;
835
+ let classes = classes
836
+ . map ( |s| format ! ( " class=\" {s}\" " ) )
837
+ . unwrap_or_default ( ) ;
836
838
837
839
format ! (
838
- r##"<h{level} id="{id}" class=" {classes}" ><a class="header" href="#{id}">{text}</a></h{level}>"## ,
840
+ r##"<h{level} id="{id}"{classes}><a class="header" href="#{id}">{text}</a></h{level}>"## ,
839
841
level = level,
840
842
id = id,
841
843
text = content,
@@ -1014,28 +1016,39 @@ mod tests {
1014
1016
let inputs = vec ! [
1015
1017
(
1016
1018
"blah blah <h1>Foo</h1>" ,
1017
- r##"blah blah <h1 id="foo" class="" ><a class="header" href="#foo">Foo</a></h1>"## ,
1019
+ r##"blah blah <h1 id="foo"><a class="header" href="#foo">Foo</a></h1>"## ,
1018
1020
) ,
1019
1021
(
1020
1022
"<h1>Foo</h1>" ,
1021
- r##"<h1 id="foo" class="" ><a class="header" href="#foo">Foo</a></h1>"## ,
1023
+ r##"<h1 id="foo"><a class="header" href="#foo">Foo</a></h1>"## ,
1022
1024
) ,
1023
1025
(
1024
1026
"<h3>Foo^bar</h3>" ,
1025
- r##"<h3 id="foobar" class="" ><a class="header" href="#foobar">Foo^bar</a></h3>"## ,
1027
+ r##"<h3 id="foobar"><a class="header" href="#foobar">Foo^bar</a></h3>"## ,
1026
1028
) ,
1027
1029
(
1028
1030
"<h4></h4>" ,
1029
- r##"<h4 id="" class="" ><a class="header" href="#"></a></h4>"## ,
1031
+ r##"<h4 id=""><a class="header" href="#"></a></h4>"## ,
1030
1032
) ,
1031
1033
(
1032
1034
"<h4><em>Hï</em></h4>" ,
1033
- r##"<h4 id="hï" class="" ><a class="header" href="#hï"><em>Hï</em></a></h4>"## ,
1035
+ r##"<h4 id="hï"><a class="header" href="#hï"><em>Hï</em></a></h4>"## ,
1034
1036
) ,
1035
1037
(
1036
1038
"<h1>Foo</h1><h3>Foo</h3>" ,
1037
- r##"<h1 id="foo" class="" ><a class="header" href="#foo">Foo</a></h1><h3 id="foo-1" class=" "><a class="header" href="#foo-1">Foo</a></h3>"## ,
1039
+ r##"<h1 id="foo"><a class="header" href="#foo">Foo</a></h1><h3 id="foo-1"><a class="header" href="#foo-1">Foo</a></h3>"## ,
1038
1040
) ,
1041
+ // id only
1042
+ (
1043
+ r##"<h1 id="foobar">Foo</h1>"## ,
1044
+ r##"<h1 id="foobar"><a class="header" href="#foobar">Foo</a></h1>"## ,
1045
+ ) ,
1046
+ // class only
1047
+ (
1048
+ r##"<h1 class="class1 class2">Foo</h1>"## ,
1049
+ r##"<h1 id="foo" class="class1 class2"><a class="header" href="#foo">Foo</a></h1>"## ,
1050
+ ) ,
1051
+ // both id and class
1039
1052
(
1040
1053
r##"<h1 id="foobar" class="class1 class2">Foo</h1>"## ,
1041
1054
r##"<h1 id="foobar" class="class1 class2"><a class="header" href="#foobar">Foo</a></h1>"## ,
0 commit comments