Serenity Operating System
1/*
2 * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
3 * Copyright (c) 2022, the SerenityOS developers.
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#pragma once
9
10#include <AK/RefCounted.h>
11#include <AK/String.h>
12#include <AK/StringView.h>
13
14namespace Manual {
15
16class PageNode;
17
18class Node : public RefCounted<Node> {
19public:
20 virtual ~Node() = default;
21
22 virtual ErrorOr<Span<NonnullRefPtr<Node const>>> children() const = 0;
23 virtual Node const* parent() const = 0;
24 virtual ErrorOr<String> name() const = 0;
25 virtual bool is_page() const { return false; }
26 virtual bool is_open() const { return false; }
27 virtual ErrorOr<String> path() const = 0;
28 virtual PageNode const* document() const = 0;
29
30 // Backend for the command-line argument format that Help and man accept. Handles:
31 // [/path/to/documentation.md] (no second argument)
32 // [page] (no second argument) - will find first section with that page
33 // [section] [page]
34 // Help can also (externally) handle search queries, which is not possible (yet) in man.
35 static ErrorOr<NonnullRefPtr<PageNode const>> try_create_from_query(Vector<StringView, 2> const& query_parameters);
36
37 // Finds a page via the help://man/<number>/<subsections...>/page URLs.
38 // This will automatically start discovering pages by inspecting the filesystem.
39 static ErrorOr<NonnullRefPtr<Node const>> try_find_from_help_url(URL const&);
40};
41
42}