Fix definition for methods in documentation parser
This patch changes the documentation parser for methods to use the first code child of the subheading as the definition instead of the first child. This fixes a problems when there is additional information in the subheading, for example about the relevant traits.
This commit is contained in:
parent
64dd5a55ae
commit
bc3f1552ef
@ -9,6 +9,8 @@ SPDX-License-Identifier: MIT
|
||||
|
||||
- Use `rustc --print sysroot` to determine the Rust installation directory
|
||||
instead of always using `/usr`.
|
||||
- Improve the documentation parser:
|
||||
- Fix the definition of methods to only contain the actual definition.
|
||||
|
||||
## v0.1.2 (2020-07-25)
|
||||
|
||||
|
@ -82,6 +82,15 @@ fn select(
|
||||
.with_context(|| format!("Could not apply selector {}", selector))
|
||||
}
|
||||
|
||||
fn it_select<I: kuchiki::iter::NodeIterator>(
|
||||
iter: I,
|
||||
selector: &str,
|
||||
) -> anyhow::Result<kuchiki::iter::Select<kuchiki::iter::Elements<I>>> {
|
||||
iter.select(selector)
|
||||
.ok()
|
||||
.with_context(|| format!("Could not apply selector {}", selector))
|
||||
}
|
||||
|
||||
fn select_first(
|
||||
element: &kuchiki::NodeRef,
|
||||
selector: &str,
|
||||
@ -89,6 +98,13 @@ fn select_first(
|
||||
select(element, selector).map(|mut i| i.next())
|
||||
}
|
||||
|
||||
fn it_select_first<I: kuchiki::iter::NodeIterator>(
|
||||
iter: I,
|
||||
selector: &str,
|
||||
) -> anyhow::Result<Option<kuchiki::NodeDataRef<kuchiki::ElementData>>> {
|
||||
it_select(iter, selector).map(|mut i| i.next())
|
||||
}
|
||||
|
||||
pub fn find_examples(s: &str) -> anyhow::Result<Vec<doc::Example>> {
|
||||
let element = parse_string(s)?;
|
||||
let examples = select(&element, ".rust-example-rendered")?;
|
||||
@ -368,7 +384,9 @@ fn get_method_group(
|
||||
if is_element(&element, &heading_type) && has_class(&element, "method") {
|
||||
methods.push(&mut name, &mut definition, None)?;
|
||||
name = get_id_part(&element, 1);
|
||||
definition = element.first_child().map(|n| get_html(&n)).transpose()?;
|
||||
definition = it_select_first(element.children(), "code")?
|
||||
.map(|n| get_html(n.as_node()))
|
||||
.transpose()?;
|
||||
} else if is_element(&element, &local_name!("div")) && has_class(&element, "docblock") {
|
||||
methods.push(&mut name, &mut definition, Some(&element))?;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user