@@ -143,12 +143,16 @@ fn pandoc_header_id(header: &str) -> ~str {
143143 let s = str:: replace( s, ~": ", ~"") ;
144144 let s = str:: replace( s, ~"& ", ~" ") ;
145145 let s = str:: replace( s, ~"^", ~"") ;
146+ let s = str:: replace( s, ~", ", ~" ") ;
147+ let s = str:: replace( s, ~"' ", ~"") ;
148+ let s = str:: replace( s, ~"+", ~"") ;
146149 return s;
147150 }
148151 fn replace_with_hyphens( s: & str) -> ~str {
149152 // Collapse sequences of whitespace to a single dash
150153 // XXX: Hacky implementation here that only covers
151154 // one or two spaces.
155+ let s = str:: trim( s) ;
152156 let s = str:: replace( s, ~" ", ~" -") ;
153157 let s = str:: replace( s, ~" ", ~" -") ;
154158 return s;
@@ -170,6 +174,17 @@ fn should_remove_punctuation_from_headers() {
170174 == ~" impl -of-numnum-for -int");
171175 fail_unless!(pandoc_header_id(~" impl for & condvar")
172176 == ~" impl -for -condvar");
177+ fail_unless!(pandoc_header_id(~" impl of Select <T , U > for ( Left , Right ) ")
178+ == ~" impl -of-selectt-u-for -left-right");
179+ fail_unless!(pandoc_header_id(~" impl of Condition <' self , T , U >")
180+ == ~" impl -of-conditionself-t-u");
181+ fail_unless!(pandoc_header_id(~" impl of Condition <T : Copy + Clone >")
182+ == ~" impl -of-conditiont-copy-clone");
183+ }
184+
185+ #[test]
186+ fn should_trim_whitespace_after_removing_punctuation() {
187+ fail_unless!(pandoc_header_id(" impl foo for ( ) ") == ~" impl -foo-for ");
173188}
174189
175190#[test]
0 commit comments