@@ -32,7 +32,6 @@ use std::ascii::AsciiExt;
32
32
use std:: cell:: RefCell ;
33
33
use std:: collections:: { HashMap , VecDeque } ;
34
34
use std:: default:: Default ;
35
- use std:: ffi:: CString ;
36
35
use std:: fmt:: { self , Write } ;
37
36
use std:: str;
38
37
use syntax:: feature_gate:: UnstableFeatures ;
@@ -531,6 +530,7 @@ extern {
531
530
fn hoedown_buffer_new ( unit : libc:: size_t ) -> * mut hoedown_buffer ;
532
531
fn hoedown_buffer_puts ( b : * mut hoedown_buffer , c : * const libc:: c_char ) ;
533
532
fn hoedown_buffer_free ( b : * mut hoedown_buffer ) ;
533
+ fn hoedown_buffer_put ( b : * mut hoedown_buffer , c : * const libc:: c_char , len : libc:: size_t ) ;
534
534
}
535
535
536
536
impl hoedown_buffer {
@@ -620,8 +620,7 @@ pub fn render(w: &mut fmt::Formatter,
620
620
Some ( "rust-example-rendered" ) ,
621
621
None ,
622
622
playground_button. as_ref ( ) . map ( String :: as_str) ) ) ;
623
- let output = CString :: new ( s) . unwrap ( ) ;
624
- hoedown_buffer_puts ( ob, output. as_ptr ( ) ) ;
623
+ hoedown_buffer_put ( ob, s. as_ptr ( ) as * const libc:: c_char , s. len ( ) ) ;
625
624
} )
626
625
}
627
626
}
@@ -681,8 +680,7 @@ pub fn render(w: &mut fmt::Formatter,
681
680
<a href='#{id}'>{sec}{}</a></h{lvl}>",
682
681
s, lvl = level, id = id, sec = sec) ;
683
682
684
- let text = CString :: new ( text) . unwrap ( ) ;
685
- unsafe { hoedown_buffer_puts ( ob, text. as_ptr ( ) ) }
683
+ unsafe { hoedown_buffer_put ( ob, text. as_ptr ( ) as * const libc:: c_char , text. len ( ) ) ; }
686
684
}
687
685
688
686
extern fn codespan (
@@ -699,9 +697,10 @@ pub fn render(w: &mut fmt::Formatter,
699
697
collapse_whitespace ( s)
700
698
} ;
701
699
702
- let content = format ! ( "<code>{}</code>" , Escape ( & content) ) ;
703
- let element = CString :: new ( content) . unwrap ( ) ;
704
- unsafe { hoedown_buffer_puts ( ob, element. as_ptr ( ) ) ; }
700
+ let content = format ! ( "<code>{}</code>" , Escape ( & content) ) . replace ( "\0 " , "\\ 0" ) ;
701
+ unsafe {
702
+ hoedown_buffer_put ( ob, content. as_ptr ( ) as * const libc:: c_char , content. len ( ) ) ;
703
+ }
705
704
// Return anything except 0, which would mean "also print the code span verbatim".
706
705
1
707
706
}
0 commit comments