@@ -117,7 +117,7 @@ pub fn render(w: &mut fmt::Formatter, md: &str, _: bool) -> fmt::Result {
117
117
HmToken :: EndTag { ref name } if is_header ( name. as_ref ( ) ) => {
118
118
let id = id_from_text ( & * header_id_buf) ;
119
119
try!( write ! ( w,
120
- "{start}<a href=\" #{id}\" >{inner}</a>{end}" ,
120
+ "\n {start}<a href=\" #{id}\" >{inner}</a>{end}" ,
121
121
start = HmToken :: start_tag( name. as_ref( ) ,
122
122
attrs!( id = & * id,
123
123
class = "section-header" ) ) ,
@@ -325,18 +325,13 @@ impl<'a> fmt::Display for MarkdownWithToc<'a> {
325
325
}
326
326
327
327
pub fn plain_summary_line ( md : & str ) -> String {
328
- let events = Parser :: new ( md) . map ( |ev| match ev {
329
- CmEvent :: Start ( Tag :: Code ) => CmEvent :: Text ( Cow :: Borrowed ( "`" ) ) ,
330
- CmEvent :: End ( Tag :: Code ) => CmEvent :: Text ( Cow :: Borrowed ( "`" ) ) ,
331
- CmEvent :: Text ( _) => ev,
332
- //CmEvent::SoftBreak | CmEvent::HardBreak => ev,
333
- _ => CmEvent :: Text ( Cow :: Borrowed ( "" ) ) ,
334
- } ) ;
335
-
336
- let hm_toks = cmark_hamlet:: Adapter :: new ( events, false ) ;
337
328
let mut ret = String :: from ( "" ) ;
338
- for tok in hm_toks {
339
- write ! ( ret, "{}" , tok) . unwrap ( ) ;
329
+ for ev in Parser :: new ( md) {
330
+ match ev {
331
+ CmEvent :: Start ( Tag :: Code ) | CmEvent :: End ( Tag :: Code ) => ret. push ( '`' ) ,
332
+ CmEvent :: Text ( text) => ret. push_str ( text. as_ref ( ) ) ,
333
+ _ => ( ) ,
334
+ }
340
335
}
341
336
ret
342
337
}
@@ -396,17 +391,17 @@ mod tests {
396
391
reset_ids ( true ) ;
397
392
}
398
393
399
- t ( "# Foo bar" , "\n <h1 id=' foo-bar' class=' section-header' >\
400
- <a href=' #foo-bar' >Foo bar</a></h1>") ;
401
- t ( "## Foo-bar_baz qux" , "\n <h2 id=' foo-bar_baz-qux' class=\' section-\
402
- header' ><a href=' #foo-bar_baz-qux' >Foo-bar_baz qux</a></h2>") ;
394
+ t ( "# Foo bar" , "\n <h1 id=\" foo-bar\" class=\" section-header\" >\
395
+ <a href=\" #foo-bar\" >Foo bar</a></h1>") ;
396
+ t ( "## Foo-bar_baz qux" , "\n <h2 id=\" foo-bar_baz-qux\" class=\" section-\
397
+ header\" ><a href=\" #foo-bar_baz-qux\" >Foo-bar_baz qux</a></h2>") ;
403
398
t ( "### **Foo** *bar* baz!?!& -_qux_-%" ,
404
- "\n <h3 id=' foo-bar-baz--_qux_-' class=' section-header' >\
405
- <a href=' #foo-bar-baz--_qux_-' ><strong>Foo</strong> \
406
- <em>bar</em> baz!?!& -_qux_ -%</a></h3>") ;
407
- t ( "####**Foo?** & \\ *bar?!* _`baz`_ ❤ #qux" ,
408
- "\n <h4 id=' foo--bar--baz--qux' class=' section-header' >\
409
- <a href=' #foo--bar--baz--qux' ><strong>Foo?</strong> & *bar?!* \
399
+ "\n <h3 id=\" foo-bar-baz--qux- \" class=\" section-header\" >\
400
+ <a href=\" #foo-bar-baz--qux- \" ><strong>Foo</strong> \
401
+ <em>bar</em> baz!?!& -<em>qux</em> -%</a></h3>") ;
402
+ t ( "#### **Foo?** & \\ *bar?!* _`baz`_ ❤ #qux" ,
403
+ "\n <h4 id=\" foo--bar--baz--qux\" class=\" section-header\" >\
404
+ <a href=\" #foo--bar--baz--qux\" ><strong>Foo?</strong> & *bar?!* \
410
405
<em><code>baz</code></em> ❤ #qux</a></h4>") ;
411
406
}
412
407
@@ -418,18 +413,18 @@ mod tests {
418
413
}
419
414
420
415
let test = || {
421
- t ( "# Example" , "\n <h1 id=' example' class=' section-header' >\
422
- <a href=' #example' >Example</a></h1>") ;
423
- t ( "# Panics" , "\n <h1 id=' panics' class=' section-header' >\
424
- <a href=' #panics' >Panics</a></h1>") ;
425
- t ( "# Example" , "\n <h1 id=' example-1' class=' section-header' >\
426
- <a href=' #example-1' >Example</a></h1>") ;
427
- t ( "# Main" , "\n <h1 id=' main-1' class=' section-header' >\
428
- <a href=' #main-1' >Main</a></h1>") ;
429
- t ( "# Example" , "\n <h1 id=' example-2' class=' section-header' >\
430
- <a href=' #example-2' >Example</a></h1>") ;
431
- t ( "# Panics" , "\n <h1 id=' panics-1' class=' section-header' >\
432
- <a href=' #panics-1' >Panics</a></h1>") ;
416
+ t ( "# Example" , "\n <h1 id=\" example\" class=\" section-header\" >\
417
+ <a href=\" #example\" >Example</a></h1>") ;
418
+ t ( "# Panics" , "\n <h1 id=\" panics\" class=\" section-header\" >\
419
+ <a href=\" #panics\" >Panics</a></h1>") ;
420
+ t ( "# Example" , "\n <h1 id=\" example-1\" class=\" section-header\" >\
421
+ <a href=\" #example-1\" >Example</a></h1>") ;
422
+ t ( "# Main" , "\n <h1 id=\" main-1\" class=\" section-header\" >\
423
+ <a href=\" #main-1\" >Main</a></h1>") ;
424
+ t ( "# Example" , "\n <h1 id=\" example-2\" class=\" section-header\" >\
425
+ <a href=\" #example-2\" >Example</a></h1>") ;
426
+ t ( "# Panics" , "\n <h1 id=\" panics-1\" class=\" section-header\" >\
427
+ <a href=\" #panics-1\" >Panics</a></h1>") ;
433
428
} ;
434
429
test ( ) ;
435
430
reset_ids ( true ) ;
0 commit comments