@@ -108,7 +108,7 @@ pub fn render(w: &mut fmt::Formatter, md: &str, _: bool) -> fmt::Result {
108
108
HmToken :: EndTag { ref name } if is_header ( name. as_ref ( ) ) => {
109
109
let id = id_from_text ( & * header_id_buf) ;
110
110
try!( write ! ( w,
111
- "{start}<a href=\" #{id}\" >{inner}</a>{end}" ,
111
+ "\n {start}<a href=\" #{id}\" >{inner}</a>{end}" ,
112
112
start = HmToken :: start_tag( name. as_ref( ) ,
113
113
attrs!( id = & * id,
114
114
class = "section-header" ) ) ,
@@ -273,18 +273,13 @@ impl<'a> fmt::Display for MarkdownWithToc<'a> {
273
273
}
274
274
275
275
pub fn plain_summary_line ( md : & str ) -> String {
276
- let events = Parser :: new ( md) . map ( |ev| match ev {
277
- CmEvent :: Start ( Tag :: Code ) => CmEvent :: Text ( Cow :: Borrowed ( "`" ) ) ,
278
- CmEvent :: End ( Tag :: Code ) => CmEvent :: Text ( Cow :: Borrowed ( "`" ) ) ,
279
- CmEvent :: Text ( _) => ev,
280
- //CmEvent::SoftBreak | CmEvent::HardBreak => ev,
281
- _ => CmEvent :: Text ( Cow :: Borrowed ( "" ) ) ,
282
- } ) ;
283
-
284
- let hm_toks = cmark_hamlet:: Adapter :: new ( events, false ) ;
285
276
let mut ret = String :: from ( "" ) ;
286
- for tok in hm_toks {
287
- write ! ( ret, "{}" , tok) . unwrap ( ) ;
277
+ for ev in Parser :: new ( md) {
278
+ match ev {
279
+ CmEvent :: Start ( Tag :: Code ) | CmEvent :: End ( Tag :: Code ) => ret. push ( '`' ) ,
280
+ CmEvent :: Text ( text) => ret. push_str ( text. as_ref ( ) ) ,
281
+ _ => ( ) ,
282
+ }
288
283
}
289
284
ret
290
285
}
@@ -340,17 +335,17 @@ mod tests {
340
335
reset_ids ( ) ;
341
336
}
342
337
343
- t ( "# Foo bar" , "\n <h1 id=' foo-bar' class=' section-header' >\
344
- <a href=' #foo-bar' >Foo bar</a></h1>") ;
345
- t ( "## Foo-bar_baz qux" , "\n <h2 id=' foo-bar_baz-qux' class=\' section-\
346
- header' ><a href=' #foo-bar_baz-qux' >Foo-bar_baz qux</a></h2>") ;
338
+ t ( "# Foo bar" , "\n <h1 id=\" foo-bar\" class=\" section-header\" >\
339
+ <a href=\" #foo-bar\" >Foo bar</a></h1>") ;
340
+ t ( "## Foo-bar_baz qux" , "\n <h2 id=\" foo-bar_baz-qux\" class=\" section-\
341
+ header\" ><a href=\" #foo-bar_baz-qux\" >Foo-bar_baz qux</a></h2>") ;
347
342
t ( "### **Foo** *bar* baz!?!& -_qux_-%" ,
348
- "\n <h3 id=' foo-bar-baz--_qux_-' class=' section-header' >\
349
- <a href=' #foo-bar-baz--_qux_-' ><strong>Foo</strong> \
350
- <em>bar</em> baz!?!& -_qux_ -%</a></h3>") ;
351
- t ( "####**Foo?** & \\ *bar?!* _`baz`_ ❤ #qux" ,
352
- "\n <h4 id=' foo--bar--baz--qux' class=' section-header' >\
353
- <a href=' #foo--bar--baz--qux' ><strong>Foo?</strong> & *bar?!* \
343
+ "\n <h3 id=\" foo-bar-baz--qux- \" class=\" section-header\" >\
344
+ <a href=\" #foo-bar-baz--qux- \" ><strong>Foo</strong> \
345
+ <em>bar</em> baz!?!& -<em>qux</em> -%</a></h3>") ;
346
+ t ( "#### **Foo?** & \\ *bar?!* _`baz`_ ❤ #qux" ,
347
+ "\n <h4 id=\" foo--bar--baz--qux\" class=\" section-header\" >\
348
+ <a href=\" #foo--bar--baz--qux\" ><strong>Foo?</strong> & *bar?!* \
354
349
<em><code>baz</code></em> ❤ #qux</a></h4>") ;
355
350
}
356
351
@@ -362,18 +357,18 @@ mod tests {
362
357
}
363
358
364
359
let test = || {
365
- t ( "# Example" , "\n <h1 id=' example' class=' section-header' >\
366
- <a href=' #example' >Example</a></h1>") ;
367
- t ( "# Panics" , "\n <h1 id=' panics' class=' section-header' >\
368
- <a href=' #panics' >Panics</a></h1>") ;
369
- t ( "# Example" , "\n <h1 id=' example-1' class=' section-header' >\
370
- <a href=' #example-1' >Example</a></h1>") ;
371
- t ( "# Main" , "\n <h1 id=' main-1' class=' section-header' >\
372
- <a href=' #main-1' >Main</a></h1>") ;
373
- t ( "# Example" , "\n <h1 id=' example-2' class=' section-header' >\
374
- <a href=' #example-2' >Example</a></h1>") ;
375
- t ( "# Panics" , "\n <h1 id=' panics-1' class=' section-header' >\
376
- <a href=' #panics-1' >Panics</a></h1>") ;
360
+ t ( "# Example" , "\n <h1 id=\" example\" class=\" section-header\" >\
361
+ <a href=\" #example\" >Example</a></h1>") ;
362
+ t ( "# Panics" , "\n <h1 id=\" panics\" class=\" section-header\" >\
363
+ <a href=\" #panics\" >Panics</a></h1>") ;
364
+ t ( "# Example" , "\n <h1 id=\" example-1\" class=\" section-header\" >\
365
+ <a href=\" #example-1\" >Example</a></h1>") ;
366
+ t ( "# Main" , "\n <h1 id=\" main-1\" class=\" section-header\" >\
367
+ <a href=\" #main-1\" >Main</a></h1>") ;
368
+ t ( "# Example" , "\n <h1 id=\" example-2\" class=\" section-header\" >\
369
+ <a href=\" #example-2\" >Example</a></h1>") ;
370
+ t ( "# Panics" , "\n <h1 id=\" panics-1\" class=\" section-header\" >\
371
+ <a href=\" #panics-1\" >Panics</a></h1>") ;
377
372
} ;
378
373
test ( ) ;
379
374
reset_ids ( ) ;
0 commit comments