mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-26 19:32:06 -05:00
1682f0b760
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/StringBuilder.h>
|
|
#include <LibMarkdown/Paragraph.h>
|
|
|
|
namespace Markdown {
|
|
|
|
String Paragraph::render_to_html() const
|
|
{
|
|
StringBuilder builder;
|
|
builder.appendf("<p>");
|
|
bool first = true;
|
|
for (auto& line : m_lines) {
|
|
if (!first)
|
|
builder.append(' ');
|
|
first = false;
|
|
builder.append(line.text().render_to_html());
|
|
}
|
|
builder.appendf("</p>\n");
|
|
return builder.build();
|
|
}
|
|
|
|
String Paragraph::render_for_terminal(size_t) const
|
|
{
|
|
StringBuilder builder;
|
|
bool first = true;
|
|
for (auto& line : m_lines) {
|
|
if (!first)
|
|
builder.append(' ');
|
|
first = false;
|
|
builder.append(line.text().render_for_terminal());
|
|
}
|
|
builder.appendf("\n\n");
|
|
return builder.build();
|
|
}
|
|
|
|
OwnPtr<Paragraph::Line> Paragraph::Line::parse(Vector<StringView>::ConstIterator& lines)
|
|
{
|
|
if (lines.is_end())
|
|
return {};
|
|
|
|
auto text = Text::parse(*lines++);
|
|
if (!text.has_value())
|
|
return {};
|
|
|
|
return make<Paragraph::Line>(text.release_value());
|
|
}
|
|
}
|