From 2b11a80a60dbae980418b229ab89d2a28dbbc15f Mon Sep 17 00:00:00 2001 From: Liigo Zhuang Date: Fri, 16 Jan 2015 20:56:26 +0800 Subject: [PATCH] address review comments: reuse Escape etc. --- src/librustdoc/html/markdown.rs | 7 ++----- src/librustdoc/html/render.rs | 18 ++---------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 45b77ea2dddc4..31c01e7777a22 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -471,7 +471,7 @@ impl<'a> fmt::String for MarkdownWithToc<'a> { } pub fn plain_summary_line(md: &str) -> String { - extern "C" fn link(_ob: *mut hoedown_buffer, + extern fn link(_ob: *mut hoedown_buffer, _link: *const hoedown_buffer, _title: *const hoedown_buffer, content: *const hoedown_buffer, @@ -479,9 +479,6 @@ pub fn plain_summary_line(md: &str) -> String { { unsafe { if !content.is_null() && (*content).size > 0 { - // FIXME(liigo): I don't know why the parameter `_ob` is - // not the value passed in by `hoedown_document_render`. - // I have to manually pass in `ob` through `opaque` currently. let ob = opaque as *mut hoedown_buffer; hoedown_buffer_put(ob, (*content).data as *const libc::c_char, (*content).size); @@ -490,7 +487,7 @@ pub fn plain_summary_line(md: &str) -> String { 1 } - extern "C" fn normal_text(_ob: *mut hoedown_buffer, + extern fn normal_text(_ob: *mut hoedown_buffer, text: *const hoedown_buffer, opaque: *mut libc::c_void) { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 86c945125f624..480c61534e6bf 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -64,6 +64,7 @@ use html::item_type::ItemType; use html::layout; use html::markdown::Markdown; use html::markdown; +use html::escape::Escape; use stability_summary; /// A pair of name and its optional document. @@ -2197,21 +2198,6 @@ fn item_typedef(w: &mut fmt::Formatter, it: &clean::Item, document(w, it) } -fn escape_title(title: &str) -> String { - let title = markdown::plain_summary_line(title); - let mut result = String::with_capacity(title.len()); - for c in title.chars() { - match c { - '<' => result.push_str("<"), - '>' => result.push_str(">"), - '"' => result.push_str("""), - '\'' => result.push_str("'"), - _ => result.push(c), - } - } - result -} - impl<'a> fmt::String for Sidebar<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let cx = self.cx; @@ -2251,7 +2237,7 @@ impl<'a> fmt::String for Sidebar<'a> { } else { format!("{}.{}.html", short, name.as_slice()) }, - title = escape_title(doc.as_ref().unwrap().as_slice()), + title = Escape(doc.as_ref().unwrap().as_slice()), name = name.as_slice())); } try!(write!(w, ""));