Improve rendering of module members

This patch improves the rendering of module members:  Instead of the
full name of the member, we now display only the last part.  This also
fixes a bug where we would use the HTML instead of the text content for
the member name.

And we also display the description next to the member name.  As we
cannot extract the content of the description element (kuchiki nodes do
not have an inner_html method), we use the text representation instead.
Otherwise we would get formatting problems when rendering the
documentation.
This commit is contained in:
Robin Krahl 2020-07-21 23:50:52 +02:00
parent a97c9e5a0f
commit bb3b361d02
No known key found for this signature in database
GPG Key ID: 8E9B0870524F69D8
2 changed files with 15 additions and 3 deletions

View File

@ -137,8 +137,14 @@ fn get_members(
// On module pages, the members are listed in tables
let items = select(table.as_node(), "td:first-child :first-child")?;
for item in items {
let item_name = get_html(item.as_node())?;
members.push(doc::Doc::new(base_name.child(&item_name)))
let item_name = item.as_node().text_contents();
let docblock = item.as_node().parent().and_then(|n| n.next_sibling());
let mut doc = doc::Doc::new(base_name.child(&item_name));
// We would like to use inner_html() here, but that is currently not implemented in
// kuchiki
doc.description = docblock.map(|n| n.text_contents());
members.push(doc);
}
}
Ok(members)

View File

@ -40,7 +40,13 @@ impl<P: Printer> TextViewer<P> {
if !items.is_empty() {
self.printer.println()?;
self.printer.print_heading(2, heading)?;
self.print_list(items.iter())?;
self.print_list(items.iter().map(|i| {
if let Some(description) = &i.description {
format!("{}<br/>{}", i.name.last(), description)
} else {
i.name.last().to_owned()
}
}))?;
}
}
Ok(())