1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:27:35 +00:00

LibManual: Allow directly obtaining any page's main section number

This has previously been incorrectly handled in a variety of
applications, e.g. subsections were not accounted for.
This commit is contained in:
kleines Filmröllchen 2023-07-02 13:25:53 +02:00 committed by Linus Groh
parent b1eacf8801
commit a9053618a8
6 changed files with 13 additions and 4 deletions

View file

@ -26,6 +26,7 @@ public:
virtual bool is_open() const { return false; }
virtual ErrorOr<String> path() const = 0;
virtual PageNode const* document() const = 0;
virtual unsigned section_number() const = 0;
// Backend for the command-line argument format that Help and man accept. Handles:
// [/path/to/documentation.md] (no second argument)

View file

@ -27,6 +27,11 @@ ErrorOr<String> PageNode::path() const
return TRY(String::formatted("{}/{}.md", TRY(m_section->path()), m_page));
}
unsigned PageNode::section_number() const
{
return m_section->section_number();
}
ErrorOr<NonnullRefPtr<PageNode>> PageNode::help_index_page()
{
static NonnullRefPtr<PageNode> const help_index_page = TRY(try_make_ref_counted<PageNode>(sections[7 - 1], TRY("Help-index"_string)));

View file

@ -28,6 +28,7 @@ public:
virtual ErrorOr<String> name() const override { return m_page; };
virtual bool is_page() const override { return true; }
virtual PageNode const* document() const override { return this; };
virtual unsigned section_number() const override;
virtual ErrorOr<String> path() const override;

View file

@ -32,6 +32,7 @@ public:
virtual Node const* parent() const override { return nullptr; }
virtual ErrorOr<String> name() const override;
String const& section_name() const { return m_section; }
virtual unsigned section_number() const override { return m_section.to_number<unsigned>().value_or(0); }
virtual ErrorOr<String> path() const override;
virtual PageNode const* document() const override { return nullptr; }

View file

@ -21,6 +21,7 @@ public:
virtual ErrorOr<String> path() const override;
virtual ErrorOr<String> name() const override;
virtual PageNode const* document() const override;
virtual unsigned section_number() const override { return m_parent->section_number(); }
protected:
NonnullRefPtr<SectionNode const> m_parent;