diff --git a/Userland/Libraries/LibManual/CMakeLists.txt b/Userland/Libraries/LibManual/CMakeLists.txt index 56258cf52b..15b4c3d62b 100644 --- a/Userland/Libraries/LibManual/CMakeLists.txt +++ b/Userland/Libraries/LibManual/CMakeLists.txt @@ -3,6 +3,7 @@ set(SOURCES PageNode.cpp Path.cpp SectionNode.cpp + SubsectionNode.cpp ) serenity_lib(LibManual manual) diff --git a/Userland/Libraries/LibManual/SubsectionNode.cpp b/Userland/Libraries/LibManual/SubsectionNode.cpp new file mode 100644 index 0000000000..1d166b9282 --- /dev/null +++ b/Userland/Libraries/LibManual/SubsectionNode.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022, kleines Filmröllchen + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "SubsectionNode.h" + +namespace Manual { + +SubsectionNode::SubsectionNode(NonnullRefPtr parent, StringView name) + : SectionNode(name, name) + , m_parent(move(parent)) +{ +} + +Node const* SubsectionNode::parent() const { return m_parent; } + +ErrorOr SubsectionNode::name() const { return m_name; } + +ErrorOr SubsectionNode::path() const +{ + return String::formatted("{}/{}", TRY(m_parent->path()), m_section); +} + +} diff --git a/Userland/Libraries/LibManual/SubsectionNode.h b/Userland/Libraries/LibManual/SubsectionNode.h new file mode 100644 index 0000000000..c2f8461bd8 --- /dev/null +++ b/Userland/Libraries/LibManual/SubsectionNode.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022, kleines Filmröllchen + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Manual { + +// A non-toplevel (i.e. not numbered) manual section. +class SubsectionNode : public SectionNode { +public: + SubsectionNode(NonnullRefPtr parent, StringView name); + virtual ~SubsectionNode() = default; + + virtual Node const* parent() const override; + virtual ErrorOr path() const override; + virtual ErrorOr name() const override; + +protected: + NonnullRefPtr m_parent; +}; + +}