From bb3b361d029a751e99fd8906fbb69cb4fb9f10a9 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 21 Jul 2020 23:50:52 +0200 Subject: [PATCH] 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. --- src/parser.rs | 10 ++++++++-- src/viewer/text/mod.rs | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index af9c9a1..4e9408e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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) diff --git a/src/viewer/text/mod.rs b/src/viewer/text/mod.rs index e51cb45..a0fea46 100644 --- a/src/viewer/text/mod.rs +++ b/src/viewer/text/mod.rs @@ -40,7 +40,13 @@ impl TextViewer

{ 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!("{}
{}", i.name.last(), description) + } else { + i.name.last().to_owned() + } + }))?; } } Ok(())