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