2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2020-01-24 10:45:29 -03:00
|
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
2022-03-04 17:21:26 -03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-09-20 18:46:18 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-05-18 17:58:00 -03:00
|
|
|
#include <AK/OwnPtr.h>
|
2020-04-28 16:04:25 -03:00
|
|
|
#include <LibMarkdown/Block.h>
|
2022-07-31 16:53:25 -03:00
|
|
|
#include <LibMarkdown/Heading.h>
|
2021-09-19 14:14:18 -03:00
|
|
|
#include <LibMarkdown/LineIterator.h>
|
2020-04-28 16:04:25 -03:00
|
|
|
#include <LibMarkdown/Text.h>
|
2019-09-20 18:46:18 -03:00
|
|
|
|
2020-04-28 16:04:25 -03:00
|
|
|
namespace Markdown {
|
|
|
|
|
|
|
|
|
|
class CodeBlock final : public Block {
|
2019-09-20 18:46:18 -03:00
|
|
|
public:
|
2022-12-04 15:02:33 -03:00
|
|
|
CodeBlock(DeprecatedString const& language, DeprecatedString const& style, DeprecatedString const& code, Heading* current_section)
|
2020-05-18 17:58:00 -03:00
|
|
|
: m_code(move(code))
|
2021-09-06 22:11:46 -03:00
|
|
|
, m_language(language)
|
2021-09-11 04:37:28 -03:00
|
|
|
, m_style(style)
|
2022-07-31 16:53:25 -03:00
|
|
|
, m_current_section(current_section)
|
2020-05-18 17:58:00 -03:00
|
|
|
{
|
|
|
|
|
}
|
2022-03-04 17:21:26 -03:00
|
|
|
virtual ~CodeBlock() override = default;
|
2019-09-20 18:46:18 -03:00
|
|
|
|
2022-12-04 15:02:33 -03:00
|
|
|
virtual DeprecatedString render_to_html(bool tight = false) const override;
|
2022-12-23 06:25:00 -03:00
|
|
|
virtual Vector<DeprecatedString> render_lines_for_terminal(size_t view_width = 0) const override;
|
2021-09-10 16:36:29 -03:00
|
|
|
virtual RecursionDecision walk(Visitor&) const override;
|
2022-07-31 16:53:25 -03:00
|
|
|
static OwnPtr<CodeBlock> parse(LineIterator& lines, Heading* current_section);
|
2019-09-20 18:46:18 -03:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 15:02:33 -03:00
|
|
|
DeprecatedString m_code;
|
|
|
|
|
DeprecatedString m_language;
|
|
|
|
|
DeprecatedString m_style;
|
2022-07-31 16:53:25 -03:00
|
|
|
Heading* m_current_section;
|
2022-04-22 02:34:09 -03:00
|
|
|
|
2022-07-31 16:53:25 -03:00
|
|
|
static OwnPtr<CodeBlock> parse_backticks(LineIterator& lines, Heading* current_section);
|
2022-04-22 02:34:09 -03:00
|
|
|
static OwnPtr<CodeBlock> parse_indent(LineIterator& lines);
|
2019-09-20 18:46:18 -03:00
|
|
|
};
|
2020-04-28 16:04:25 -03:00
|
|
|
|
|
|
|
|
}
|