Document.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/DeprecatedString.h>
  8. #include <AK/OwnPtr.h>
  9. #include <LibMarkdown/Block.h>
  10. #include <LibMarkdown/ContainerBlock.h>
  11. namespace Markdown {
  12. class Document final {
  13. public:
  14. Document(OwnPtr<ContainerBlock> container)
  15. : m_container(move(container))
  16. {
  17. }
  18. DeprecatedString render_to_html(StringView extra_head_contents = ""sv) const;
  19. DeprecatedString render_to_inline_html() const;
  20. DeprecatedString render_for_terminal(size_t view_width = 0) const;
  21. /*
  22. * Walk recursively through the document tree. Returning `RecursionDecision::Recurse` from
  23. * `Visitor::visit` proceeds with the next element of the pre-order walk, usually a child element.
  24. * Returning `RecursionDecision::Continue` skips the subtree, and usually proceeds with the next
  25. * sibling. Returning `RecursionDecision::Break` breaks the recursion, with no further calls to
  26. * any of the `Visitor::visit` methods.
  27. *
  28. * Note that `walk()` will only return `RecursionDecision::Continue` or `RecursionDecision::Break`.
  29. */
  30. RecursionDecision walk(Visitor&) const;
  31. static OwnPtr<Document> parse(StringView);
  32. private:
  33. OwnPtr<ContainerBlock> m_container;
  34. };
  35. }