2020-09-20 16:44:03 +04:30
|
|
|
/*
|
2022-03-04 13:21:26 -07:00
|
|
|
* Copyright (c) 2020-2022, the SerenityOS developers.
|
2020-09-20 16:44:03 +04:30
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-20 16:44:03 +04:30
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
|
#include <LibMarkdown/Block.h>
|
2021-09-19 11:14:18 -06:00
|
|
|
#include <LibMarkdown/LineIterator.h>
|
2020-09-20 16:44:03 +04:30
|
|
|
#include <LibMarkdown/Text.h>
|
|
|
|
|
|
|
|
|
|
namespace Markdown {
|
|
|
|
|
|
|
|
|
|
class Table final : public Block {
|
|
|
|
|
public:
|
|
|
|
|
enum class Alignment {
|
|
|
|
|
Center,
|
|
|
|
|
Left,
|
|
|
|
|
Right,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Column {
|
|
|
|
|
Text header;
|
|
|
|
|
Vector<Text> rows;
|
|
|
|
|
Alignment alignment { Alignment::Left };
|
|
|
|
|
size_t relative_width { 0 };
|
2021-09-10 21:36:29 +02:00
|
|
|
|
|
|
|
|
RecursionDecision walk(Visitor&) const;
|
2020-09-20 16:44:03 +04:30
|
|
|
};
|
|
|
|
|
|
2022-03-04 13:21:26 -07:00
|
|
|
Table() = default;
|
|
|
|
|
virtual ~Table() override = default;
|
2020-09-20 16:44:03 +04:30
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
virtual ByteString render_to_html(bool tight = false) const override;
|
|
|
|
|
virtual Vector<ByteString> render_lines_for_terminal(size_t view_width = 0) const override;
|
2021-09-10 21:36:29 +02:00
|
|
|
virtual RecursionDecision walk(Visitor&) const override;
|
2021-09-19 11:14:18 -06:00
|
|
|
static OwnPtr<Table> parse(LineIterator& lines);
|
2020-09-20 16:44:03 +04:30
|
|
|
|
2023-05-25 22:41:43 +03:00
|
|
|
Vector<Column> const& columns() const { return m_columns; }
|
|
|
|
|
|
2020-09-20 16:44:03 +04:30
|
|
|
private:
|
|
|
|
|
Vector<Column> m_columns;
|
|
|
|
|
size_t m_total_width { 1 };
|
|
|
|
|
size_t m_row_count { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|