LibMarkdown: Convert a bunch of StringBuilder::appendf() => appendff()

This commit is contained in:
Andreas Kling 2021-05-05 20:12:26 +02:00
parent beae2d5caa
commit 89f5f92b7e
4 changed files with 14 additions and 18 deletions

View file

@ -11,11 +11,7 @@ namespace Markdown {
String Heading::render_to_html() const
{
StringBuilder builder;
builder.appendf("<h%zu>", m_level);
builder.append(m_text.render_to_html());
builder.appendf("</h%zu>\n", m_level);
return builder.build();
return String::formatted("<h{}>{}</h{}>\n", m_level, m_text.render_to_html(), m_level);
}
String Heading::render_for_terminal(size_t) const

View file

@ -14,7 +14,7 @@ String List::render_to_html() const
StringBuilder builder;
const char* tag = m_is_ordered ? "ol" : "ul";
builder.appendf("<%s>", tag);
builder.appendff("<{}>", tag);
for (auto& item : m_items) {
builder.append("<li>");
@ -22,7 +22,7 @@ String List::render_to_html() const
builder.append("</li>\n");
}
builder.appendf("</%s>\n", tag);
builder.appendff("</{}>\n", tag);
return builder.build();
}
@ -35,7 +35,7 @@ String List::render_for_terminal(size_t) const
for (auto& item : m_items) {
builder.append(" ");
if (m_is_ordered)
builder.appendf("%d. ", ++i);
builder.appendff("{}. ", ++i);
else
builder.append("* ");
builder.append(item.render_for_terminal());

View file

@ -12,7 +12,7 @@ namespace Markdown {
String Paragraph::render_to_html() const
{
StringBuilder builder;
builder.appendf("<p>");
builder.append("<p>");
bool first = true;
for (auto& line : m_lines) {
if (!first)
@ -20,7 +20,7 @@ String Paragraph::render_to_html() const
first = false;
builder.append(line.text().render_to_html());
}
builder.appendf("</p>\n");
builder.append("</p>\n");
return builder.build();
}
@ -34,7 +34,7 @@ String Paragraph::render_for_terminal(size_t) const
first = false;
builder.append(line.text().render_for_terminal());
}
builder.appendf("\n\n");
builder.append("\n\n");
return builder.build();
}

View file

@ -72,7 +72,7 @@ String Text::render_to_html() const
current_style.img = {};
continue;
}
builder.appendf("</%s>", tag.characters());
builder.appendff("</{}>", tag);
if (tag == "a") {
current_style.href = {};
continue;
@ -85,16 +85,16 @@ String Text::render_to_html() const
}
if (current_style.href.is_null() && !span.style.href.is_null()) {
open_tags.append("a");
builder.appendf("<a href=\"%s\">", span.style.href.characters());
builder.appendff("<a href=\"{}\">", span.style.href);
}
if (current_style.img.is_null() && !span.style.img.is_null()) {
open_tags.append("img");
builder.appendf("<img src=\"%s\" alt=\"", span.style.img.characters());
builder.appendff("<img src=\"{}\" alt=\"", span.style.img);
}
for (auto& tag_and_flag : tags_and_flags) {
if (current_style.*tag_and_flag.flag != span.style.*tag_and_flag.flag) {
open_tags.append(tag_and_flag.tag);
builder.appendf("<%s>", tag_and_flag.tag.characters());
builder.appendff("<{}>", tag_and_flag.tag);
}
}
@ -108,7 +108,7 @@ String Text::render_to_html() const
builder.append("\" />");
continue;
}
builder.appendf("</%s>", tag.characters());
builder.appendff("</{}>", tag);
}
return builder.build();
@ -153,13 +153,13 @@ String Text::render_for_terminal() const
// non-absolute links, because the user has no
// chance to follow them anyway.
if (strstr(span.style.href.characters(), "://") != nullptr) {
builder.appendf(" <%s>", span.style.href.characters());
builder.appendff(" <{}>", span.style.href);
builder.append("\033]8;;\033\\");
}
}
if (!span.style.img.is_null()) {
if (strstr(span.style.img.characters(), "://") != nullptr) {
builder.appendf(" <%s>", span.style.img.characters());
builder.appendff(" <{}>", span.style.img);
}
}
}