diff --git a/Userland/Libraries/LibMarkdown/BlockQuote.cpp b/Userland/Libraries/LibMarkdown/BlockQuote.cpp new file mode 100644 index 0000000000..a40a24dbc1 --- /dev/null +++ b/Userland/Libraries/LibMarkdown/BlockQuote.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021, Peter Elliott + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Markdown { + +String BlockQuote::render_to_html(bool) const +{ + StringBuilder builder; + builder.append("
\n"); + builder.append(m_contents->render_to_html()); + builder.append("
\n"); + return builder.build(); +} + +String BlockQuote::render_for_terminal(size_t view_width) const +{ + // FIXME: Rewrite the whole terminal renderer to make blockquote rendering possible + return m_contents->render_for_terminal(view_width); +} + +OwnPtr
BlockQuote::parse(LineIterator& lines) +{ + lines.push_context(LineIterator::Context::block_quote()); + if (lines.is_end()) { + lines.pop_context(); + return {}; + } + + auto contents = ContainerBlock::parse(lines); + lines.pop_context(); + + if (!contents) + return {}; + + return make
(move(contents)); +} + +} diff --git a/Userland/Libraries/LibMarkdown/BlockQuote.h b/Userland/Libraries/LibMarkdown/BlockQuote.h new file mode 100644 index 0000000000..5c9abbbfab --- /dev/null +++ b/Userland/Libraries/LibMarkdown/BlockQuote.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021, Peter Elliott + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Markdown { + +class BlockQuote final : public Block { +public: + BlockQuote(OwnPtr contents) + : m_contents(move(contents)) + { + } + virtual ~BlockQuote() override { } + + virtual String render_to_html(bool tight = false) const override; + virtual String render_for_terminal(size_t view_width = 0) const override; + + static OwnPtr
parse(LineIterator& lines); + +private: + OwnPtr m_contents; +}; + +} diff --git a/Userland/Libraries/LibMarkdown/CMakeLists.txt b/Userland/Libraries/LibMarkdown/CMakeLists.txt index c079e687a4..01cd4882b9 100644 --- a/Userland/Libraries/LibMarkdown/CMakeLists.txt +++ b/Userland/Libraries/LibMarkdown/CMakeLists.txt @@ -1,4 +1,5 @@ set(SOURCES + BlockQuote.cpp CodeBlock.cpp ContainerBlock.cpp Document.cpp diff --git a/Userland/Libraries/LibMarkdown/ContainerBlock.cpp b/Userland/Libraries/LibMarkdown/ContainerBlock.cpp index 9585264661..8ae1213459 100644 --- a/Userland/Libraries/LibMarkdown/ContainerBlock.cpp +++ b/Userland/Libraries/LibMarkdown/ContainerBlock.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -91,7 +92,8 @@ OwnPtr ContainerBlock::parse(LineIterator& lines) } bool any = try_parse_block(lines, blocks) || try_parse_block(lines, blocks) || try_parse_block(lines, blocks) - || try_parse_block(lines, blocks) || try_parse_block(lines, blocks); + || try_parse_block(lines, blocks) || try_parse_block(lines, blocks) + || try_parse_block
(lines, blocks); if (any) { if (!paragraph_text.is_empty()) {