2424//! // ... something using html
2525//! ```
2626
27- #![ allow( dead_code) ]
2827#![ allow( non_camel_case_types) ]
2928
3029use libc;
@@ -51,7 +50,7 @@ pub struct Markdown<'a>(pub &'a str);
5150pub struct MarkdownWithToc < ' a > ( pub & ' a str ) ;
5251
5352const DEF_OUNIT : libc:: size_t = 64 ;
54- const HOEDOWN_EXT_NO_INTRA_EMPHASIS : libc:: c_uint = 1 << 10 ;
53+ const HOEDOWN_EXT_NO_INTRA_EMPHASIS : libc:: c_uint = 1 << 11 ;
5554const HOEDOWN_EXT_TABLES : libc:: c_uint = 1 << 0 ;
5655const HOEDOWN_EXT_FENCED_CODE : libc:: c_uint = 1 << 1 ;
5756const HOEDOWN_EXT_AUTOLINK : libc:: c_uint = 1 << 3 ;
@@ -65,52 +64,63 @@ const HOEDOWN_EXTENSIONS: libc::c_uint =
6564 HOEDOWN_EXT_STRIKETHROUGH | HOEDOWN_EXT_SUPERSCRIPT |
6665 HOEDOWN_EXT_FOOTNOTES ;
6766
68- type hoedown_document = libc :: c_void ; // this is opaque to us
67+ enum hoedown_document { }
6968
7069type blockcodefn = extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
71- * const hoedown_buffer , * mut libc:: c_void ) ;
70+ * const hoedown_buffer , * const hoedown_renderer_data ) ;
71+
72+ type blockquotefn = extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
73+ * const hoedown_renderer_data ) ;
7274
7375type headerfn = extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
74- libc:: c_int , * mut libc:: c_void ) ;
76+ libc:: c_int , * const hoedown_renderer_data ) ;
77+
78+ type blockhtmlfn = extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
79+ * const hoedown_renderer_data ) ;
7580
7681type codespanfn = extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
77- * mut libc :: c_void ) -> libc:: c_int ;
82+ * const hoedown_renderer_data ) -> libc:: c_int ;
7883
7984type linkfn = extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
8085 * const hoedown_buffer , * const hoedown_buffer ,
81- * mut libc:: c_void ) -> libc:: c_int ;
86+ * const hoedown_renderer_data ) -> libc:: c_int ;
87+
88+ type entityfn = extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
89+ * const hoedown_renderer_data ) ;
8290
8391type normaltextfn = extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
84- * mut libc:: c_void ) ;
92+ * const hoedown_renderer_data ) ;
93+
94+ #[ repr( C ) ]
95+ struct hoedown_renderer_data {
96+ opaque : * mut libc:: c_void ,
97+ }
8598
8699#[ repr( C ) ]
87100struct hoedown_renderer {
88101 opaque : * mut libc:: c_void ,
89102
90103 blockcode : Option < blockcodefn > ,
91- blockquote : Option < extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
92- * mut libc:: c_void ) > ,
93- blockhtml : Option < extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
94- * mut libc:: c_void ) > ,
104+ blockquote : Option < blockquotefn > ,
95105 header : Option < headerfn > ,
96- other_block_level_callbacks : [ libc:: size_t ; 9 ] ,
106+
107+ other_block_level_callbacks : [ libc:: size_t ; 11 ] ,
108+
109+ blockhtml : Option < blockhtmlfn > ,
97110
98111 /* span level callbacks - NULL or return 0 prints the span verbatim */
99112 autolink : libc:: size_t , // unused
100113 codespan : Option < codespanfn > ,
101114 other_span_level_callbacks_1 : [ libc:: size_t ; 7 ] ,
102115 link : Option < linkfn > ,
103- other_span_level_callbacks_2 : [ libc:: size_t ; 5 ] ,
104- // hoedown will add `math` callback here, but we use an old version of it.
116+ other_span_level_callbacks_2 : [ libc:: size_t ; 6 ] ,
105117
106118 /* low level callbacks - NULL copies input directly into the output */
107- entity : Option < extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
108- * mut libc:: c_void ) > ,
119+ entity : Option < entityfn > ,
109120 normal_text : Option < normaltextfn > ,
110121
111122 /* header and footer */
112- doc_header : Option < extern "C" fn ( * mut hoedown_buffer , * mut libc:: c_void ) > ,
113- doc_footer : Option < extern "C" fn ( * mut hoedown_buffer , * mut libc:: c_void ) > ,
123+ other_callbacks : [ libc:: size_t ; 2 ] ,
114124}
115125
116126#[ repr( C ) ]
@@ -120,7 +130,7 @@ struct hoedown_html_renderer_state {
120130 flags : libc:: c_uint ,
121131 link_attributes : Option < extern "C" fn ( * mut hoedown_buffer ,
122132 * const hoedown_buffer ,
123- * mut libc :: c_void ) > ,
133+ * const hoedown_renderer_data ) > ,
124134}
125135
126136#[ repr( C ) ]
@@ -133,7 +143,7 @@ struct html_toc_data {
133143
134144struct MyOpaque {
135145 dfltblk : extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
136- * const hoedown_buffer , * mut libc :: c_void ) ,
146+ * const hoedown_buffer , * const hoedown_renderer_data ) ,
137147 toc_builder : Option < TocBuilder > ,
138148}
139149
@@ -153,7 +163,7 @@ extern {
153163 -> * mut hoedown_renderer ;
154164 fn hoedown_html_renderer_free ( renderer : * mut hoedown_renderer ) ;
155165
156- fn hoedown_document_new ( rndr : * mut hoedown_renderer ,
166+ fn hoedown_document_new ( rndr : * const hoedown_renderer ,
157167 extensions : libc:: c_uint ,
158168 max_nesting : libc:: size_t ) -> * mut hoedown_document ;
159169 fn hoedown_document_render ( doc : * mut hoedown_document ,
@@ -212,11 +222,11 @@ thread_local!(pub static PLAYGROUND_KRATE: RefCell<Option<Option<String>>> = {
212222
213223pub fn render ( w : & mut fmt:: Formatter , s : & str , print_toc : bool ) -> fmt:: Result {
214224 extern fn block ( ob : * mut hoedown_buffer , orig_text : * const hoedown_buffer ,
215- lang : * const hoedown_buffer , opaque : * mut libc :: c_void ) {
225+ lang : * const hoedown_buffer , data : * const hoedown_renderer_data ) {
216226 unsafe {
217227 if orig_text. is_null ( ) { return }
218228
219- let opaque = opaque as * mut hoedown_html_renderer_state ;
229+ let opaque = ( * data ) . opaque as * mut hoedown_html_renderer_state ;
220230 let my_opaque: & MyOpaque = & * ( ( * opaque) . opaque as * const MyOpaque ) ;
221231 let text = ( * orig_text) . as_bytes ( ) ;
222232 let origtext = str:: from_utf8 ( text) . unwrap ( ) ;
@@ -228,7 +238,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
228238 let rlang = str:: from_utf8 ( rlang) . unwrap ( ) ;
229239 if !LangString :: parse ( rlang) . rust {
230240 ( my_opaque. dfltblk ) ( ob, orig_text, lang,
231- opaque as * mut libc :: c_void ) ;
241+ opaque as * const hoedown_renderer_data ) ;
232242 true
233243 } else {
234244 false
@@ -261,7 +271,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
261271 }
262272
263273 extern fn header ( ob : * mut hoedown_buffer , text : * const hoedown_buffer ,
264- level : libc:: c_int , opaque : * mut libc :: c_void ) {
274+ level : libc:: c_int , data : * const hoedown_renderer_data ) {
265275 // hoedown does this, we may as well too
266276 unsafe { hoedown_buffer_puts ( ob, "\n \0 " . as_ptr ( ) as * const _ ) ; }
267277
@@ -280,7 +290,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
280290 // This is a terrible hack working around how hoedown gives us rendered
281291 // html for text rather than the raw text.
282292
283- let opaque = opaque as * mut hoedown_html_renderer_state ;
293+ let opaque = unsafe { ( * data ) . opaque as * mut hoedown_html_renderer_state } ;
284294 let opaque = unsafe { & mut * ( ( * opaque) . opaque as * mut MyOpaque ) } ;
285295
286296 // Make sure our hyphenated ID is unique for this page
@@ -320,7 +330,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
320330 extern fn codespan (
321331 ob : * mut hoedown_buffer ,
322332 text : * const hoedown_buffer ,
323- _: * mut libc :: c_void ,
333+ _: * const hoedown_renderer_data ,
324334 ) -> libc:: c_int {
325335 let content = if text. is_null ( ) {
326336 "" . to_string ( )
@@ -375,7 +385,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
375385 extern fn block ( _ob : * mut hoedown_buffer ,
376386 text : * const hoedown_buffer ,
377387 lang : * const hoedown_buffer ,
378- opaque : * mut libc :: c_void ) {
388+ data : * const hoedown_renderer_data ) {
379389 unsafe {
380390 if text. is_null ( ) { return }
381391 let block_info = if lang. is_null ( ) {
@@ -387,7 +397,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
387397 } ;
388398 if !block_info. rust { return }
389399 let text = ( * text) . as_bytes ( ) ;
390- let opaque = opaque as * mut hoedown_html_renderer_state ;
400+ let opaque = ( * data ) . opaque as * mut hoedown_html_renderer_state ;
391401 let tests = & mut * ( ( * opaque) . opaque as * mut :: test:: Collector ) ;
392402 let text = str:: from_utf8 ( text) . unwrap ( ) ;
393403 let lines = text. lines ( ) . map ( |l| {
@@ -402,9 +412,9 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
402412
403413 extern fn header ( _ob : * mut hoedown_buffer ,
404414 text : * const hoedown_buffer ,
405- level : libc:: c_int , opaque : * mut libc :: c_void ) {
415+ level : libc:: c_int , data : * const hoedown_renderer_data ) {
406416 unsafe {
407- let opaque = opaque as * mut hoedown_html_renderer_state ;
417+ let opaque = ( * data ) . opaque as * mut hoedown_html_renderer_state ;
408418 let tests = & mut * ( ( * opaque) . opaque as * mut :: test:: Collector ) ;
409419 if text. is_null ( ) {
410420 tests. register_header ( "" , level as u32 ) ;
@@ -514,11 +524,11 @@ pub fn plain_summary_line(md: &str) -> String {
514524 _link : * const hoedown_buffer ,
515525 _title : * const hoedown_buffer ,
516526 content : * const hoedown_buffer ,
517- opaque : * mut libc :: c_void ) -> libc:: c_int
527+ data : * const hoedown_renderer_data ) -> libc:: c_int
518528 {
519529 unsafe {
520530 if !content. is_null ( ) && ( * content) . size > 0 {
521- let ob = opaque as * mut hoedown_buffer ;
531+ let ob = ( * data ) . opaque as * mut hoedown_buffer ;
522532 hoedown_buffer_put ( ob, ( * content) . data as * const libc:: c_char ,
523533 ( * content) . size ) ;
524534 }
@@ -528,10 +538,10 @@ pub fn plain_summary_line(md: &str) -> String {
528538
529539 extern fn normal_text ( _ob : * mut hoedown_buffer ,
530540 text : * const hoedown_buffer ,
531- opaque : * mut libc :: c_void )
541+ data : * const hoedown_renderer_data )
532542 {
533543 unsafe {
534- let ob = opaque as * mut hoedown_buffer ;
544+ let ob = ( * data ) . opaque as * mut hoedown_buffer ;
535545 hoedown_buffer_put ( ob, ( * text) . data as * const libc:: c_char ,
536546 ( * text) . size ) ;
537547 }
0 commit comments