2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2020-01-24 16:45:29 +03:00
|
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-09-21 00:46:18 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-05-18 16:58:00 -04:00
|
|
|
#include <AK/OwnPtr.h>
|
2020-04-28 21:04:25 +02:00
|
|
|
#include <LibMarkdown/Block.h>
|
2021-09-19 11:14:18 -06:00
|
|
|
#include <LibMarkdown/LineIterator.h>
|
2020-04-28 21:04:25 +02:00
|
|
|
#include <LibMarkdown/Text.h>
|
2019-09-21 00:46:18 +03:00
|
|
|
|
2020-04-28 21:04:25 +02:00
|
|
|
namespace Markdown {
|
|
|
|
|
|
|
|
|
|
class CodeBlock final : public Block {
|
2019-09-21 00:46:18 +03:00
|
|
|
public:
|
2021-09-11 01:37:28 -06:00
|
|
|
CodeBlock(String const& language, String const& style, String const& code)
|
2020-05-18 16:58:00 -04:00
|
|
|
: m_code(move(code))
|
2021-09-06 19:11:46 -06:00
|
|
|
, m_language(language)
|
2021-09-11 01:37:28 -06:00
|
|
|
, m_style(style)
|
2020-05-18 16:58:00 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
virtual ~CodeBlock() override { }
|
2019-09-21 00:46:18 +03:00
|
|
|
|
2021-09-28 01:12:00 -06:00
|
|
|
virtual String render_to_html(bool tight = false) const override;
|
2020-09-20 16:41:04 +04:30
|
|
|
virtual String render_for_terminal(size_t view_width = 0) const override;
|
2021-09-19 11:14:18 -06:00
|
|
|
static OwnPtr<CodeBlock> parse(LineIterator& lines);
|
2019-09-21 00:46:18 +03:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
String m_code;
|
2021-09-06 19:11:46 -06:00
|
|
|
String m_language;
|
2021-09-11 01:37:28 -06:00
|
|
|
String m_style;
|
2019-09-21 00:46:18 +03:00
|
|
|
};
|
2020-04-28 21:04:25 +02:00
|
|
|
|
|
|
|
|
}
|