10
10
11
11
//! Markdown formatting for rustdoc
12
12
//!
13
- //! This module implements markdown formatting through the hoedown C-library
14
- //! (bundled into the rust runtime). This module self-contains the C bindings
15
- //! and necessary legwork to render markdown, and exposes all of the
13
+ //! This module implements markdown formatting through the pulldown-cmark
14
+ //! rust-library. This module exposes all of the
16
15
//! functionality through a unit-struct, `Markdown`, which has an implementation
17
16
//! of `fmt::Display`. Example usage:
18
17
//!
19
18
//! ```rust,ignore
20
- //! use rustdoc::html::markdown::Markdown;
19
+ //! use rustdoc::html::markdown::{ Markdown, MarkdownOutputStyle} ;
21
20
//!
22
21
//! let s = "My *markdown* _text_";
23
- //! let html = format!("{}", Markdown(s));
22
+ //! let html = format!("{}", Markdown(s, MarkdownOutputStyle::Fancy ));
24
23
//! // ... something using html
25
24
//! ```
26
25
@@ -138,7 +137,7 @@ pub fn render(w: &mut fmt::Formatter,
138
137
s : & str ,
139
138
print_toc : bool ,
140
139
shorter : MarkdownOutputStyle ) -> fmt:: Result {
141
- fn block ( parser : & mut Parser , buffer : & mut String , lang : & str ) {
140
+ fn code_block ( parser : & mut Parser , buffer : & mut String , lang : & str ) {
142
141
let mut origtext = String :: new ( ) ;
143
142
while let Some ( event) = parser. next ( ) {
144
143
match event {
@@ -216,8 +215,8 @@ pub fn render(w: &mut fmt::Formatter,
216
215
} ) ;
217
216
}
218
217
219
- fn header ( parser : & mut Parser , buffer : & mut String , toc_builder : & mut Option < TocBuilder > ,
220
- shorter : MarkdownOutputStyle , level : i32 ) {
218
+ fn heading ( parser : & mut Parser , buffer : & mut String , toc_builder : & mut Option < TocBuilder > ,
219
+ shorter : MarkdownOutputStyle , level : i32 ) {
221
220
let mut ret = String :: new ( ) ;
222
221
let mut id = String :: new ( ) ;
223
222
event_loop_break ! ( parser, toc_builder, shorter, ret, true , & mut Some ( & mut id) ,
@@ -250,8 +249,8 @@ pub fn render(w: &mut fmt::Formatter,
250
249
ret, lvl = level, id = id, sec = sec) ) ;
251
250
}
252
251
253
- fn codespan ( parser : & mut Parser , buffer : & mut String , toc_builder : & mut Option < TocBuilder > ,
254
- shorter : MarkdownOutputStyle , id : & mut Option < & mut String > ) {
252
+ fn inline_code ( parser : & mut Parser , buffer : & mut String , toc_builder : & mut Option < TocBuilder > ,
253
+ shorter : MarkdownOutputStyle , id : & mut Option < & mut String > ) {
255
254
let mut content = String :: new ( ) ;
256
255
event_loop_break ! ( parser, toc_builder, shorter, content, false , id, Event :: End ( Tag :: Code ) ) ;
257
256
buffer. push_str ( & format ! ( "<code>{}</code>" ,
@@ -274,8 +273,8 @@ pub fn render(w: &mut fmt::Formatter,
274
273
buffer. push_str ( & format ! ( "<p>{}</p>" , content. trim_right( ) ) ) ;
275
274
}
276
275
277
- fn cell ( parser : & mut Parser , buffer : & mut String , toc_builder : & mut Option < TocBuilder > ,
278
- shorter : MarkdownOutputStyle ) {
276
+ fn table_cell ( parser : & mut Parser , buffer : & mut String , toc_builder : & mut Option < TocBuilder > ,
277
+ shorter : MarkdownOutputStyle ) {
279
278
let mut content = String :: new ( ) ;
280
279
event_loop_break ! ( parser, toc_builder, shorter, content, true , & mut None ,
281
280
Event :: End ( Tag :: TableHead ) |
@@ -285,16 +284,16 @@ pub fn render(w: &mut fmt::Formatter,
285
284
buffer. push_str ( & format ! ( "<td>{}</td>" , content. trim( ) ) ) ;
286
285
}
287
286
288
- fn row ( parser : & mut Parser , buffer : & mut String , toc_builder : & mut Option < TocBuilder > ,
289
- shorter : MarkdownOutputStyle ) {
287
+ fn table_row ( parser : & mut Parser , buffer : & mut String , toc_builder : & mut Option < TocBuilder > ,
288
+ shorter : MarkdownOutputStyle ) {
290
289
let mut content = String :: new ( ) ;
291
290
while let Some ( event) = parser. next ( ) {
292
291
match event {
293
292
Event :: End ( Tag :: TableHead ) |
294
293
Event :: End ( Tag :: Table ( _) ) |
295
294
Event :: End ( Tag :: TableRow ) => break ,
296
295
Event :: Start ( Tag :: TableCell ) => {
297
- cell ( parser, & mut content, toc_builder, shorter) ;
296
+ table_cell ( parser, & mut content, toc_builder, shorter) ;
298
297
}
299
298
x => {
300
299
looper ( parser, & mut content, Some ( x) , toc_builder, shorter, & mut None ) ;
@@ -304,14 +303,14 @@ pub fn render(w: &mut fmt::Formatter,
304
303
buffer. push_str ( & format ! ( "<tr>{}</tr>" , content) ) ;
305
304
}
306
305
307
- fn head ( parser : & mut Parser , buffer : & mut String , toc_builder : & mut Option < TocBuilder > ,
308
- shorter : MarkdownOutputStyle ) {
306
+ fn table_head ( parser : & mut Parser , buffer : & mut String , toc_builder : & mut Option < TocBuilder > ,
307
+ shorter : MarkdownOutputStyle ) {
309
308
let mut content = String :: new ( ) ;
310
309
while let Some ( event) = parser. next ( ) {
311
310
match event {
312
311
Event :: End ( Tag :: TableHead ) | Event :: End ( Tag :: Table ( _) ) => break ,
313
312
Event :: Start ( Tag :: TableCell ) => {
314
- cell ( parser, & mut content, toc_builder, shorter) ;
313
+ table_cell ( parser, & mut content, toc_builder, shorter) ;
315
314
}
316
315
x => {
317
316
looper ( parser, & mut content, Some ( x) , toc_builder, shorter, & mut None ) ;
@@ -331,10 +330,10 @@ pub fn render(w: &mut fmt::Formatter,
331
330
match event {
332
331
Event :: End ( Tag :: Table ( _) ) => break ,
333
332
Event :: Start ( Tag :: TableHead ) => {
334
- head ( parser, & mut content, toc_builder, shorter) ;
333
+ table_head ( parser, & mut content, toc_builder, shorter) ;
335
334
}
336
335
Event :: Start ( Tag :: TableRow ) => {
337
- row ( parser, & mut rows, toc_builder, shorter) ;
336
+ table_row ( parser, & mut rows, toc_builder, shorter) ;
338
337
}
339
338
_ => { }
340
339
}
@@ -412,13 +411,13 @@ pub fn render(w: &mut fmt::Formatter,
412
411
if let Some ( event) = next_event {
413
412
match event {
414
413
Event :: Start ( Tag :: CodeBlock ( lang) ) => {
415
- block ( parser, buffer, & * lang) ;
414
+ code_block ( parser, buffer, & * lang) ;
416
415
}
417
416
Event :: Start ( Tag :: Header ( level) ) => {
418
- header ( parser, buffer, toc_builder, shorter, level) ;
417
+ heading ( parser, buffer, toc_builder, shorter, level) ;
419
418
}
420
419
Event :: Start ( Tag :: Code ) => {
421
- codespan ( parser, buffer, toc_builder, shorter, id) ;
420
+ inline_code ( parser, buffer, toc_builder, shorter, id) ;
422
421
}
423
422
Event :: Start ( Tag :: Paragraph ) => {
424
423
paragraph ( parser, buffer, toc_builder, shorter, id) ;
0 commit comments