2020-01-18 11:38:21 +03:00
|
|
|
/*
|
2020-01-24 16:45:29 +03:00
|
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
2022-03-04 23:21:26 +03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-09-21 00:46:18 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-05-18 23:58:00 +03:00
|
|
|
#include <AK/OwnPtr.h>
|
2019-09-21 00:46:18 +03:00
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <AK/Vector.h>
|
2020-04-28 22:04:25 +03:00
|
|
|
#include <LibMarkdown/Block.h>
|
2021-09-19 20:14:18 +03:00
|
|
|
#include <LibMarkdown/LineIterator.h>
|
2020-04-28 22:04:25 +03:00
|
|
|
#include <LibMarkdown/Text.h>
|
2019-09-21 00:46:18 +03:00
|
|
|
|
2020-04-28 22:04:25 +03:00
|
|
|
namespace Markdown {
|
|
|
|
|
|
|
|
class Heading final : public Block {
|
2019-09-21 00:46:18 +03:00
|
|
|
public:
|
2020-05-18 23:58:00 +03:00
|
|
|
Heading(Text&& text, size_t level)
|
|
|
|
: m_text(move(text))
|
|
|
|
, m_level(level)
|
|
|
|
{
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(m_level > 0);
|
2020-05-18 23:58:00 +03:00
|
|
|
}
|
2022-03-04 23:21:26 +03:00
|
|
|
virtual ~Heading() override = default;
|
2019-09-21 00:46:18 +03:00
|
|
|
|
2021-09-28 10:12:00 +03:00
|
|
|
virtual String render_to_html(bool tight = false) const override;
|
2020-09-20 15:11:04 +03:00
|
|
|
virtual String render_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<Heading> parse(LineIterator& lines);
|
2019-09-21 00:46:18 +03:00
|
|
|
|
|
|
|
private:
|
2020-04-28 22:04:25 +03:00
|
|
|
Text m_text;
|
2020-05-18 23:58:00 +03:00
|
|
|
size_t m_level { 0 };
|
2019-09-21 00:46:18 +03:00
|
|
|
};
|
2020-04-28 22:04:25 +03:00
|
|
|
|
|
|
|
}
|