Skip to content

Commit

Permalink
address review comments: reuse Escape etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
liigo committed Jan 21, 2015
1 parent 17ebb60 commit 2b11a80
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
7 changes: 2 additions & 5 deletions src/librustdoc/html/markdown.rs
Expand Up @@ -471,17 +471,14 @@ 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,
opaque: *mut libc::c_void) -> libc::c_int
{
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);
Expand All @@ -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)
{
Expand Down
18 changes: 2 additions & 16 deletions src/librustdoc/html/render.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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("&lt;"),
'>' => result.push_str("&gt;"),
'"' => result.push_str("&quot;"),
'\'' => result.push_str("&#39;"),
_ => result.push(c),
}
}
result
}

impl<'a> fmt::String for Sidebar<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let cx = self.cx;
Expand Down Expand Up @@ -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, "</div>"));
Expand Down

0 comments on commit 2b11a80

Please sign in to comment.