Node.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #pragma once
  8. #include <AK/NonnullRefPtrVector.h>
  9. #include <AK/RefCounted.h>
  10. #include <AK/String.h>
  11. #include <AK/StringView.h>
  12. namespace Manual {
  13. class PageNode;
  14. class Node : public RefCounted<Node> {
  15. public:
  16. virtual ~Node() = default;
  17. virtual ErrorOr<Span<NonnullRefPtr<Node const>>> children() const = 0;
  18. virtual Node const* parent() const = 0;
  19. virtual ErrorOr<String> name() const = 0;
  20. virtual bool is_page() const { return false; }
  21. virtual bool is_open() const { return false; }
  22. virtual ErrorOr<String> path() const = 0;
  23. virtual PageNode const* document() const = 0;
  24. // Backend for the command-line argument format that Help and man accept. Handles:
  25. // [/path/to/documentation.md] (no second argument)
  26. // [page] (no second argument) - will find first section with that page
  27. // [section] [page]
  28. // Help can also (externally) handle search queries, which is not possible (yet) in man.
  29. static ErrorOr<NonnullRefPtr<PageNode const>> try_create_from_query(Vector<StringView, 2> const& query_parameters);
  30. // Finds a page via the help://man/<number>/<subsections...>/page URLs.
  31. // This will automatically start discovering pages by inspecting the filesystem.
  32. static ErrorOr<NonnullRefPtr<Node const>> try_find_from_help_url(URL const&);
  33. };
  34. }