Table.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2020-2022, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/OwnPtr.h>
  8. #include <LibMarkdown/Block.h>
  9. #include <LibMarkdown/LineIterator.h>
  10. #include <LibMarkdown/Text.h>
  11. namespace Markdown {
  12. class Table final : public Block {
  13. public:
  14. enum class Alignment {
  15. Center,
  16. Left,
  17. Right,
  18. };
  19. struct Column {
  20. Text header;
  21. Vector<Text> rows;
  22. Alignment alignment { Alignment::Left };
  23. size_t relative_width { 0 };
  24. RecursionDecision walk(Visitor&) const;
  25. };
  26. Table() = default;
  27. virtual ~Table() override = default;
  28. virtual DeprecatedString render_to_html(bool tight = false) const override;
  29. virtual Vector<DeprecatedString> render_lines_for_terminal(size_t view_width = 0) const override;
  30. virtual RecursionDecision walk(Visitor&) const override;
  31. static OwnPtr<Table> parse(LineIterator& lines);
  32. private:
  33. Vector<Column> m_columns;
  34. size_t m_total_width { 1 };
  35. size_t m_row_count { 0 };
  36. };
  37. }