Table.h 907 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullOwnPtrVector.h>
  8. #include <AK/OwnPtr.h>
  9. #include <LibMarkdown/Block.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. };
  25. Table() { }
  26. virtual ~Table() override { }
  27. virtual String render_to_html() const override;
  28. virtual String render_for_terminal(size_t view_width = 0) const override;
  29. static OwnPtr<Table> parse(Vector<StringView>::ConstIterator& lines);
  30. private:
  31. Vector<Column> m_columns;
  32. size_t m_total_width { 1 };
  33. size_t m_row_count { 0 };
  34. };
  35. }