11use comrak:: html:: ChildRendering ;
22use comrak:: { create_formatter, nodes:: NodeValue } ;
3- use std:: io :: Write ;
3+ use std:: fmt :: Write ;
44
55create_formatter ! ( CustomFormatter <usize >, {
66 NodeValue :: Emph => |context, entering| {
77 context. user += 1 ;
88 if entering {
9- context. write_all ( b "<i>") ?;
9+ context. write_str ( "<i>" ) ?;
1010 } else {
11- context. write_all ( b "</i>") ?;
11+ context. write_str ( "</i>" ) ?;
1212 }
1313 } ,
1414 NodeValue :: Strong => |context, entering| {
1515 context. user += 1 ;
16- context. write_all ( if entering { b "<b>" } else { b "</b>" } ) ?;
16+ context. write_str ( if entering { "<b>" } else { "</b>" } ) ?;
1717 } ,
1818 NodeValue :: Image ( ref nl) => |context, node, entering| {
1919 assert!( node. data. borrow( ) . sourcepos == ( 3 , 1 , 3 , 18 ) . into( ) ) ;
2020 if entering {
21- context. write_all ( nl. url. to_uppercase( ) . as_bytes ( ) ) ?;
21+ context. write_str ( & nl. url. to_uppercase( ) ) ?;
2222 }
2323 return Ok ( ChildRendering :: Skip ) ;
2424 } ,
@@ -35,13 +35,10 @@ fn main() {
3535 & options,
3636 ) ;
3737
38- let mut buf : Vec < u8 > = vec ! [ ] ;
39- let converted_count = CustomFormatter :: format_document ( doc, & options, & mut buf , 0 ) . unwrap ( ) ;
38+ let mut out = String :: new ( ) ;
39+ let converted_count = CustomFormatter :: format_document ( doc, & options, & mut out , 0 ) . unwrap ( ) ;
4040
41- assert_eq ! (
42- std:: str :: from_utf8( & buf) . unwrap( ) ,
43- "<p><i>Hello</i>, <b>world</b>.</p>\n <p>/IMG.PNG</p>\n "
44- ) ;
41+ assert_eq ! ( out, "<p><i>Hello</i>, <b>world</b>.</p>\n <p>/IMG.PNG</p>\n " ) ;
4542
4643 assert_eq ! ( converted_count, 4 ) ;
4744}
0 commit comments