2020-09-20 15:14:03 +03:00
|
|
|
/*
|
2022-03-04 23:21:26 +03:00
|
|
|
* Copyright (c) 2020-2022, the SerenityOS developers.
|
2020-09-20 15:14:03 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-20 15:14:03 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
#include <LibMarkdown/Block.h>
|
2021-09-19 20:14:18 +03:00
|
|
|
#include <LibMarkdown/LineIterator.h>
|
2020-09-20 15:14:03 +03:00
|
|
|
#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 22:36:29 +03:00
|
|
|
|
|
|
|
RecursionDecision walk(Visitor&) const;
|
2020-09-20 15:14:03 +03:00
|
|
|
};
|
|
|
|
|
2022-03-04 23:21:26 +03:00
|
|
|
Table() = default;
|
|
|
|
virtual ~Table() override = default;
|
2020-09-20 15:14:03 +03:00
|
|
|
|
2022-12-04 21:02:33 +03:00
|
|
|
virtual DeprecatedString render_to_html(bool tight = false) const override;
|
2022-12-23 12:25:00 +03:00
|
|
|
virtual Vector<DeprecatedString> render_lines_for_terminal(size_t view_width = 0) const override;
|
2021-09-10 22:36:29 +03:00
|
|
|
virtual RecursionDecision walk(Visitor&) const override;
|
2021-09-19 20:14:18 +03:00
|
|
|
static OwnPtr<Table> parse(LineIterator& lines);
|
2020-09-20 15:14:03 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
Vector<Column> m_columns;
|
|
|
|
size_t m_total_width { 1 };
|
|
|
|
size_t m_row_count { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|