As described in the previous commit, Rust 1.45 changed the ID of the
methods subheading from "methods" to "implementations". The last patch
fixed this for the trait implementations, this patch updates the method
group parser with the new IDs.
In older Rust versions, trait implementations were listed under the
heading with the id "implementations" and in the div with the id
"implementations-list". Since Rust 1.45, the method heading has the id
"implementations" and the trait implementations have the ids
"trait-implementations" and "trait-implementations-list".
This patch updates the parser with these new IDs while also checking the
old IDs for older documentation.
Previously, we only showed plain text versions of the item descriptions
in the module overview due to a formatting issue. As this issue
disappeared, we can now use the HTML version of the description.
Similar to the fix for functions in 1a242e5, we have to use a different
selector to query the definition for constants, "pre.const" instead of
".docblock.type-decl".
With this patch, we require that the identifier element for a member in
the module documentation is a direct child of the table cell. This
fixes problems with spurious member elements if there are more elements
in the table cell, e. g. stability annotations.
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.
Previously, we were used /usr/share/doc/rust{,-doc}/html as a default
source, assuming that it would contain the standard library
documentation. This is true if the user installed the Rust
documentation manually or using a package manager. If they use rustup
instead, the documentation is placed in a subdirectory of ~/.rustup.
With this patch, we call `rustc --print sysroot` to determine the
installation directory of the currently activated Rust toolchain –
either the system Rust installation or a Rust installation managed by
rustup. We then use `$(sysroot)/share/doc/…` as a default path for the
standard library documentation (with /usr as a fallback if the call to
rustc does not return a valid path).
This patch release adds basic logging output and a new `-e`/`--examples`
option to extract only the examples from the documentation. It also
fixes a bug when displaying the documentation for a function.
As I noticed when trying to debug an issue with a very large HTML file,
we still need more log messages that indicate what is currently going on
in rusty-man. This patch adds some more log messages.
Previosuly, we always used the selector ".docblock.type-decl" to select
the definition for an item. But this did not work for functions.
Therefore we change the selector to "pre.fn" for functions.
This patch adds some basic info log messages to make it easier to debug
incompatible rustdoc output. To show the messages, run rusty-man with
the environment variable RUST_LOG=info.
With this patch, we replace the termion dependency with crossterm. This
should make it possible to compile and run rusty-man on other platforms
than Unix.
This patch updates the readme with better usage examples and with the
documentation for rusty-man itself.
Signed-off-by: Robin Krahl <robin.krahl@ireas.org>
rustdoc normalizes the name of a crate by replacing hyphens with
underscores. With this patch, we also perform this normalization when
looking up a crate.
With this patch, we change our rich and plain viewer implementations to
format their output similar to the output of man. This means:
- Adding a title with the current crate, documentation item and
“rusty-man”
- Printing headings at indent levels 0, 3, 6 and printing content with
indent 6, 12
- Printing headings bold and uppercase (level 1) or bold (levels 2, 3)
This patch introduces the helper struct MemberDocs that wraps a Vec<Doc>
that allows us to simplify the parser code. The MemberDocs struct takes
care of creating Doc instances using the names, definitions and
descriptions of member items.
Previosuly, we stored the members as a vector of vectors, group by a
string -- their title. This was very hard to read and also too simple:
For example, there can be multiple blocks of methods in the
documentation for a struct. Therefore we introduce a new type,
MemberGroup, that represents a group of member items with an optional
title.
Previously, we only displayed the member name when viewing the
documentation of a member. With this patch, we use the ItemType enum to
also print the type of the member.
For consistency, we remove the title field from doc::Doc that was
previously used for the titles of modules and items and use the same
title as for members. While we lose the links to the parent items,
these were not particularly helpful anyway. If we want to, we could
also generate them from the item name.
Previously, we maintained a list of headings and HTML element IDs for
item types in parser.rs. As we now have a complete ItemType enum, we
can use ItemType methods to provide this data.
Some elements, for example std::io::ErrorKind, have nested docblocks in
their type-decl docblock. This would lead to a wrong description
because we pick the first non-type-decl docblock for the description.
With this patch, we require that the description docblock is a direct
child of #main to fix this issue.
Previously, our ItemType enum only had three values: Module, Item and
Member. With this patch we import the ItemType variants from librustdoc
(see html/item_type.rs) for better compatibility and easier parsing.
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 patch refactors the viewer module:
- The `text` option is renamed to `plain`.
- The TextViewer and RichViewer structs are replaced by a new TextViewer
struct that handles the basic documentation structure and uses a
Printer implementation for formatting.
- The new structs PlainTextRenderer and RichTextRenderer implement the
Printer trait.
- The Printer trait and the TextViewer struct are placed in the
viewer::text module. The Printer implementations are placed in the
plain and rich submodules.
This reduces code duplication and makes it easier to render more complex
documentation items.