Document.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteString.h>
  8. #include <AK/OwnPtr.h>
  9. #include <AK/String.h>
  10. #include <LibMarkdown/Block.h>
  11. #include <LibMarkdown/ContainerBlock.h>
  12. namespace Markdown {
  13. class Document final {
  14. public:
  15. Document(OwnPtr<ContainerBlock> container)
  16. : m_container(move(container))
  17. {
  18. }
  19. ByteString render_to_html(StringView extra_head_contents = ""sv) const;
  20. ByteString render_to_inline_html() const;
  21. ErrorOr<String> render_for_terminal(size_t view_width = 0) const;
  22. /*
  23. * Walk recursively through the document tree. Returning `RecursionDecision::Recurse` from
  24. * `Visitor::visit` proceeds with the next element of the pre-order walk, usually a child element.
  25. * Returning `RecursionDecision::Continue` skips the subtree, and usually proceeds with the next
  26. * sibling. Returning `RecursionDecision::Break` breaks the recursion, with no further calls to
  27. * any of the `Visitor::visit` methods.
  28. *
  29. * Note that `walk()` will only return `RecursionDecision::Continue` or `RecursionDecision::Break`.
  30. */
  31. RecursionDecision walk(Visitor&) const;
  32. static OwnPtr<Document> parse(StringView);
  33. private:
  34. OwnPtr<ContainerBlock> m_container;
  35. };
  36. }