diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index e55f3fa91dcd..117cfbabb52f 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -10,17 +10,16 @@ //! Markdown formatting for rustdoc //! -//! This module implements markdown formatting through the hoedown C-library -//! (bundled into the rust runtime). This module self-contains the C bindings -//! and necessary legwork to render markdown, and exposes all of the +//! This module implements markdown formatting through the pulldown-cmark +//! rust-library. This module exposes all of the //! functionality through a unit-struct, `Markdown`, which has an implementation //! of `fmt::Display`. Example usage: //! //! ```rust,ignore -//! use rustdoc::html::markdown::Markdown; +//! use rustdoc::html::markdown::{Markdown, MarkdownOutputStyle}; //! //! let s = "My *markdown* _text_"; -//! let html = format!("{}", Markdown(s)); +//! let html = format!("{}", Markdown(s, MarkdownOutputStyle::Fancy)); //! // ... something using html //! ``` @@ -138,7 +137,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool, shorter: MarkdownOutputStyle) -> fmt::Result { - fn block(parser: &mut Parser, buffer: &mut String, lang: &str) { + fn code_block(parser: &mut Parser, buffer: &mut String, lang: &str) { let mut origtext = String::new(); while let Some(event) = parser.next() { match event { @@ -216,8 +215,8 @@ fn dont_escape(c: u8) -> bool { }); } - fn header(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option, - shorter: MarkdownOutputStyle, level: i32) { + fn heading(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option, + shorter: MarkdownOutputStyle, level: i32) { let mut ret = String::new(); let mut id = String::new(); event_loop_break!(parser, toc_builder, shorter, ret, true, &mut Some(&mut id), @@ -250,8 +249,8 @@ fn header(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option, - shorter: MarkdownOutputStyle, id: &mut Option<&mut String>) { + fn inline_code(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option, + shorter: MarkdownOutputStyle, id: &mut Option<&mut String>) { let mut content = String::new(); event_loop_break!(parser, toc_builder, shorter, content, false, id, Event::End(Tag::Code)); buffer.push_str(&format!("{}", @@ -274,8 +273,8 @@ fn paragraph(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option< buffer.push_str(&format!("

{}

", content.trim_right())); } - fn cell(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option, - shorter: MarkdownOutputStyle) { + fn table_cell(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option, + shorter: MarkdownOutputStyle) { let mut content = String::new(); event_loop_break!(parser, toc_builder, shorter, content, true, &mut None, Event::End(Tag::TableHead) | @@ -285,8 +284,8 @@ fn cell(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option{}", content.trim())); } - fn row(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option, - shorter: MarkdownOutputStyle) { + fn table_row(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option, + shorter: MarkdownOutputStyle) { let mut content = String::new(); while let Some(event) = parser.next() { match event { @@ -294,7 +293,7 @@ fn row(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option break, Event::Start(Tag::TableCell) => { - cell(parser, &mut content, toc_builder, shorter); + table_cell(parser, &mut content, toc_builder, shorter); } x => { looper(parser, &mut content, Some(x), toc_builder, shorter, &mut None); @@ -304,14 +303,14 @@ fn row(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option{}", content)); } - fn head(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option, - shorter: MarkdownOutputStyle) { + fn table_head(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option, + shorter: MarkdownOutputStyle) { let mut content = String::new(); while let Some(event) = parser.next() { match event { Event::End(Tag::TableHead) | Event::End(Tag::Table(_)) => break, Event::Start(Tag::TableCell) => { - cell(parser, &mut content, toc_builder, shorter); + table_cell(parser, &mut content, toc_builder, shorter); } x => { looper(parser, &mut content, Some(x), toc_builder, shorter, &mut None); @@ -331,10 +330,10 @@ fn table(parser: &mut Parser, buffer: &mut String, toc_builder: &mut Option break, Event::Start(Tag::TableHead) => { - head(parser, &mut content, toc_builder, shorter); + table_head(parser, &mut content, toc_builder, shorter); } Event::Start(Tag::TableRow) => { - row(parser, &mut rows, toc_builder, shorter); + table_row(parser, &mut rows, toc_builder, shorter); } _ => {} } @@ -412,13 +411,13 @@ fn looper<'a>(parser: &'a mut Parser, buffer: &mut String, next_event: Option { - block(parser, buffer, &*lang); + code_block(parser, buffer, &*lang); } Event::Start(Tag::Header(level)) => { - header(parser, buffer, toc_builder, shorter, level); + heading(parser, buffer, toc_builder, shorter, level); } Event::Start(Tag::Code) => { - codespan(parser, buffer, toc_builder, shorter, id); + inline_code(parser, buffer, toc_builder, shorter, id); } Event::Start(Tag::Paragraph) => { paragraph(parser, buffer, toc_builder, shorter, id);