24
24
//! // ... something using html
25
25
//! ```
26
26
27
- #![ allow( dead_code) ]
28
27
#![ allow( non_camel_case_types) ]
29
28
30
29
use libc;
@@ -51,7 +50,7 @@ pub struct Markdown<'a>(pub &'a str);
51
50
pub struct MarkdownWithToc < ' a > ( pub & ' a str ) ;
52
51
53
52
const 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 ;
55
54
const HOEDOWN_EXT_TABLES : libc:: c_uint = 1 << 0 ;
56
55
const HOEDOWN_EXT_FENCED_CODE : libc:: c_uint = 1 << 1 ;
57
56
const HOEDOWN_EXT_AUTOLINK : libc:: c_uint = 1 << 3 ;
@@ -65,52 +64,63 @@ const HOEDOWN_EXTENSIONS: libc::c_uint =
65
64
HOEDOWN_EXT_STRIKETHROUGH | HOEDOWN_EXT_SUPERSCRIPT |
66
65
HOEDOWN_EXT_FOOTNOTES ;
67
66
68
- type hoedown_document = libc :: c_void ; // this is opaque to us
67
+ enum hoedown_document { }
69
68
70
69
type 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 ) ;
72
74
73
75
type 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 ) ;
75
80
76
81
type 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 ;
78
83
79
84
type linkfn = extern "C" fn ( * mut hoedown_buffer , * const hoedown_buffer ,
80
85
* 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 ) ;
82
90
83
91
type 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
+ }
85
98
86
99
#[ repr( C ) ]
87
100
struct hoedown_renderer {
88
101
opaque : * mut libc:: c_void ,
89
102
90
103
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 > ,
95
105
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 > ,
97
110
98
111
/* span level callbacks - NULL or return 0 prints the span verbatim */
99
112
autolink : libc:: size_t , // unused
100
113
codespan : Option < codespanfn > ,
101
114
other_span_level_callbacks_1 : [ libc:: size_t ; 7 ] ,
102
115
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 ] ,
105
117
106
118
/* 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 > ,
109
120
normal_text : Option < normaltextfn > ,
110
121
111
122
/* 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 ] ,
114
124
}
115
125
116
126
#[ repr( C ) ]
@@ -120,7 +130,7 @@ struct hoedown_html_renderer_state {
120
130
flags : libc:: c_uint ,
121
131
link_attributes : Option < extern "C" fn ( * mut hoedown_buffer ,
122
132
* const hoedown_buffer ,
123
- * mut libc :: c_void ) > ,
133
+ * const hoedown_renderer_data ) > ,
124
134
}
125
135
126
136
#[ repr( C ) ]
@@ -133,7 +143,7 @@ struct html_toc_data {
133
143
134
144
struct MyOpaque {
135
145
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 ) ,
137
147
toc_builder : Option < TocBuilder > ,
138
148
}
139
149
@@ -153,7 +163,7 @@ extern {
153
163
-> * mut hoedown_renderer ;
154
164
fn hoedown_html_renderer_free ( renderer : * mut hoedown_renderer ) ;
155
165
156
- fn hoedown_document_new ( rndr : * mut hoedown_renderer ,
166
+ fn hoedown_document_new ( rndr : * const hoedown_renderer ,
157
167
extensions : libc:: c_uint ,
158
168
max_nesting : libc:: size_t ) -> * mut hoedown_document ;
159
169
fn hoedown_document_render ( doc : * mut hoedown_document ,
@@ -212,11 +222,11 @@ thread_local!(pub static PLAYGROUND_KRATE: RefCell<Option<Option<String>>> = {
212
222
213
223
pub fn render ( w : & mut fmt:: Formatter , s : & str , print_toc : bool ) -> fmt:: Result {
214
224
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 ) {
216
226
unsafe {
217
227
if orig_text. is_null ( ) { return }
218
228
219
- let opaque = opaque as * mut hoedown_html_renderer_state ;
229
+ let opaque = ( * data ) . opaque as * mut hoedown_html_renderer_state ;
220
230
let my_opaque: & MyOpaque = & * ( ( * opaque) . opaque as * const MyOpaque ) ;
221
231
let text = ( * orig_text) . as_bytes ( ) ;
222
232
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 {
228
238
let rlang = str:: from_utf8 ( rlang) . unwrap ( ) ;
229
239
if !LangString :: parse ( rlang) . rust {
230
240
( my_opaque. dfltblk ) ( ob, orig_text, lang,
231
- opaque as * mut libc :: c_void ) ;
241
+ opaque as * const hoedown_renderer_data ) ;
232
242
true
233
243
} else {
234
244
false
@@ -261,7 +271,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
261
271
}
262
272
263
273
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 ) {
265
275
// hoedown does this, we may as well too
266
276
unsafe { hoedown_buffer_puts ( ob, "\n \0 " . as_ptr ( ) as * const _ ) ; }
267
277
@@ -280,7 +290,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
280
290
// This is a terrible hack working around how hoedown gives us rendered
281
291
// html for text rather than the raw text.
282
292
283
- let opaque = opaque as * mut hoedown_html_renderer_state ;
293
+ let opaque = unsafe { ( * data ) . opaque as * mut hoedown_html_renderer_state } ;
284
294
let opaque = unsafe { & mut * ( ( * opaque) . opaque as * mut MyOpaque ) } ;
285
295
286
296
// 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 {
320
330
extern fn codespan (
321
331
ob : * mut hoedown_buffer ,
322
332
text : * const hoedown_buffer ,
323
- _: * mut libc :: c_void ,
333
+ _: * const hoedown_renderer_data ,
324
334
) -> libc:: c_int {
325
335
let content = if text. is_null ( ) {
326
336
"" . to_string ( )
@@ -375,7 +385,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
375
385
extern fn block ( _ob : * mut hoedown_buffer ,
376
386
text : * const hoedown_buffer ,
377
387
lang : * const hoedown_buffer ,
378
- opaque : * mut libc :: c_void ) {
388
+ data : * const hoedown_renderer_data ) {
379
389
unsafe {
380
390
if text. is_null ( ) { return }
381
391
let block_info = if lang. is_null ( ) {
@@ -387,7 +397,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
387
397
} ;
388
398
if !block_info. rust { return }
389
399
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 ;
391
401
let tests = & mut * ( ( * opaque) . opaque as * mut :: test:: Collector ) ;
392
402
let text = str:: from_utf8 ( text) . unwrap ( ) ;
393
403
let lines = text. lines ( ) . map ( |l| {
@@ -402,9 +412,9 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
402
412
403
413
extern fn header ( _ob : * mut hoedown_buffer ,
404
414
text : * const hoedown_buffer ,
405
- level : libc:: c_int , opaque : * mut libc :: c_void ) {
415
+ level : libc:: c_int , data : * const hoedown_renderer_data ) {
406
416
unsafe {
407
- let opaque = opaque as * mut hoedown_html_renderer_state ;
417
+ let opaque = ( * data ) . opaque as * mut hoedown_html_renderer_state ;
408
418
let tests = & mut * ( ( * opaque) . opaque as * mut :: test:: Collector ) ;
409
419
if text. is_null ( ) {
410
420
tests. register_header ( "" , level as u32 ) ;
@@ -514,11 +524,11 @@ pub fn plain_summary_line(md: &str) -> String {
514
524
_link : * const hoedown_buffer ,
515
525
_title : * const hoedown_buffer ,
516
526
content : * const hoedown_buffer ,
517
- opaque : * mut libc :: c_void ) -> libc:: c_int
527
+ data : * const hoedown_renderer_data ) -> libc:: c_int
518
528
{
519
529
unsafe {
520
530
if !content. is_null ( ) && ( * content) . size > 0 {
521
- let ob = opaque as * mut hoedown_buffer ;
531
+ let ob = ( * data ) . opaque as * mut hoedown_buffer ;
522
532
hoedown_buffer_put ( ob, ( * content) . data as * const libc:: c_char ,
523
533
( * content) . size ) ;
524
534
}
@@ -528,10 +538,10 @@ pub fn plain_summary_line(md: &str) -> String {
528
538
529
539
extern fn normal_text ( _ob : * mut hoedown_buffer ,
530
540
text : * const hoedown_buffer ,
531
- opaque : * mut libc :: c_void )
541
+ data : * const hoedown_renderer_data )
532
542
{
533
543
unsafe {
534
- let ob = opaque as * mut hoedown_buffer ;
544
+ let ob = ( * data ) . opaque as * mut hoedown_buffer ;
535
545
hoedown_buffer_put ( ob, ( * text) . data as * const libc:: c_char ,
536
546
( * text) . size ) ;
537
547
}
0 commit comments