ladybird/Userland/Libraries/LibMarkdown/Paragraph.cpp

46 lines
976 B
C++
Raw Normal View History

/*
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Forward.h>
2019-09-21 00:46:18 +03:00
#include <AK/StringBuilder.h>
#include <LibMarkdown/Paragraph.h>
#include <LibMarkdown/Visitor.h>
2019-09-21 00:46:18 +03:00
namespace Markdown {
DeprecatedString Paragraph::render_to_html(bool tight) const
2019-09-21 00:46:18 +03:00
{
StringBuilder builder;
if (!tight)
builder.append("<p>"sv);
builder.append(m_text.render_to_html());
if (!tight)
builder.append("</p>"sv);
builder.append('\n');
return builder.to_deprecated_string();
2019-09-21 00:46:18 +03:00
}
Vector<DeprecatedString> Paragraph::render_lines_for_terminal(size_t) const
2019-09-21 00:46:18 +03:00
{
return Vector<DeprecatedString> { DeprecatedString::formatted(" {}", m_text.render_for_terminal()), "" };
}
2019-09-21 00:46:18 +03:00
RecursionDecision Paragraph::walk(Visitor& visitor) const
{
RecursionDecision rd = visitor.visit(*this);
if (rd != RecursionDecision::Recurse)
return rd;
return m_text.walk(visitor);
}
}