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