2020-01-18 11:38:21 +03:00
|
|
|
/*
|
2020-01-24 16:45:29 +03:00
|
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2022-12-23 12:25:00 +03:00
|
|
|
#include <AK/Forward.h>
|
2019-09-21 00:46:18 +03:00
|
|
|
#include <AK/StringBuilder.h>
|
2020-04-28 22:04:25 +03:00
|
|
|
#include <LibMarkdown/Paragraph.h>
|
2021-09-10 22:36:29 +03:00
|
|
|
#include <LibMarkdown/Visitor.h>
|
2019-09-21 00:46:18 +03:00
|
|
|
|
2020-04-28 22:04:25 +03:00
|
|
|
namespace Markdown {
|
|
|
|
|
2022-12-04 21:02:33 +03:00
|
|
|
DeprecatedString Paragraph::render_to_html(bool tight) const
|
2019-09-21 00:46:18 +03:00
|
|
|
{
|
|
|
|
StringBuilder builder;
|
2021-09-28 10:12:00 +03:00
|
|
|
|
|
|
|
if (!tight)
|
2022-07-11 20:32:29 +03:00
|
|
|
builder.append("<p>"sv);
|
2021-09-28 10:12:00 +03:00
|
|
|
|
2021-09-07 04:11:46 +03:00
|
|
|
builder.append(m_text.render_to_html());
|
2021-09-28 10:12:00 +03:00
|
|
|
|
|
|
|
if (!tight)
|
2022-07-11 20:32:29 +03:00
|
|
|
builder.append("</p>"sv);
|
2021-09-28 10:12:00 +03:00
|
|
|
|
|
|
|
builder.append('\n');
|
|
|
|
|
2023-01-26 21:58:09 +03:00
|
|
|
return builder.to_deprecated_string();
|
2019-09-21 00:46:18 +03:00
|
|
|
}
|
|
|
|
|
2022-12-23 12:25:00 +03:00
|
|
|
Vector<DeprecatedString> Paragraph::render_lines_for_terminal(size_t) const
|
2019-09-21 00:46:18 +03:00
|
|
|
{
|
2022-12-23 12:25:00 +03:00
|
|
|
return Vector<DeprecatedString> { DeprecatedString::formatted(" {}", m_text.render_for_terminal()), "" };
|
2020-09-20 19:12:23 +03:00
|
|
|
}
|
2019-09-21 00:46:18 +03:00
|
|
|
|
2021-09-10 22:36:29 +03:00
|
|
|
RecursionDecision Paragraph::walk(Visitor& visitor) const
|
|
|
|
{
|
|
|
|
RecursionDecision rd = visitor.visit(*this);
|
|
|
|
if (rd != RecursionDecision::Recurse)
|
|
|
|
return rd;
|
|
|
|
|
|
|
|
return m_text.walk(visitor);
|
|
|
|
}
|
|
|
|
|
2020-04-28 22:04:25 +03:00
|
|
|
}
|