Text.h 948 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/Noncopyable.h>
  8. #include <AK/String.h>
  9. #include <AK/Vector.h>
  10. namespace Markdown {
  11. class Text final {
  12. AK_MAKE_NONCOPYABLE(Text);
  13. public:
  14. struct Style {
  15. bool emph { false };
  16. bool strong { false };
  17. bool code { false };
  18. String href;
  19. String img;
  20. };
  21. struct Span {
  22. String text;
  23. Style style;
  24. };
  25. explicit Text(String&& text);
  26. Text(Text&& text) = default;
  27. Text() = default;
  28. Text& operator=(Text&&) = default;
  29. const Vector<Span>& spans() const { return m_spans; }
  30. String render_to_html() const;
  31. String render_for_terminal() const;
  32. static Optional<Text> parse(const StringView&);
  33. private:
  34. Text(Vector<Span>&& spans)
  35. : m_spans(move(spans))
  36. {
  37. }
  38. Vector<Span> m_spans;
  39. };
  40. }