1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 21:35:06 +00:00
serenity/Userland/Libraries/LibMarkdown/Paragraph.cpp
Peter Elliott 0a21c2bace LibMarkdown: Implement "tightness" for lists
From the commonmark spec:
A list is loose if any of its constituent list items are separated by
blank lines, or if any of its constituent list items directly contain
two block-level elements with a blank line between them. Otherwise a
list is tight. (The difference in HTML output is that paragraphs in a
loose list are wrapped in <p> tags, while paragraphs in a tight list are
not.)
2021-10-05 13:27:25 +03:30

37 lines
681 B
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(bool tight) const
{
StringBuilder builder;
if (!tight)
builder.append("<p>");
builder.append(m_text.render_to_html());
if (!tight)
builder.append("</p>");
builder.append('\n');
return builder.build();
}
String Paragraph::render_for_terminal(size_t) const
{
StringBuilder builder;
builder.append(m_text.render_for_terminal());
builder.append("\n\n");
return builder.build();
}
}