summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibMarkdown/Paragraph.cpp
blob: 0b804a86b928c3ff4bfbe5d25b2b2e0b3257c9e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/StringBuilder.h>
#include <LibMarkdown/Paragraph.h>
#include <LibMarkdown/Visitor.h>

namespace Markdown {

String Paragraph::render_to_html(bool tight) const
{
    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.build();
}

String Paragraph::render_for_terminal(size_t) const
{
    StringBuilder builder;
    builder.append("  "sv);
    builder.append(m_text.render_for_terminal());
    builder.append("\n\n"sv);
    return builder.build();
}

RecursionDecision Paragraph::walk(Visitor& visitor) const
{
    RecursionDecision rd = visitor.visit(*this);
    if (rd != RecursionDecision::Recurse)
        return rd;

    return m_text.walk(visitor);
}

}