1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:17:35 +00:00

LibMarkdown: Render lines to terminal instead of a single string

With this patch, the blocks in a markdown document render a vector of
lines. These lines get concatenated in Document::render_to_terminal, so
this does not change any external APIs of LibMarkdown.

This change makes it possible to indent individual lines in the rendered
markdown. So, rendering blockquotes in a similar way to code blocks :^)
This commit is contained in:
Arda Cinar 2022-12-23 12:25:00 +03:00 committed by Andreas Kling
parent 7a4b912ece
commit 5cc984d74c
20 changed files with 85 additions and 55 deletions

View file

@ -15,7 +15,7 @@ DeprecatedString Heading::render_to_html(bool) const
return DeprecatedString::formatted("<h{}>{}</h{}>\n", m_level, m_text.render_to_html(), m_level);
}
DeprecatedString Heading::render_for_terminal(size_t) const
Vector<DeprecatedString> Heading::render_lines_for_terminal(size_t) const
{
StringBuilder builder;
@ -24,15 +24,15 @@ DeprecatedString Heading::render_for_terminal(size_t) const
case 1:
case 2:
builder.append(m_text.render_for_terminal().to_uppercase());
builder.append("\033[0m\n"sv);
builder.append("\033[0m"sv);
break;
default:
builder.append(m_text.render_for_terminal());
builder.append("\033[0m\n"sv);
builder.append("\033[0m"sv);
break;
}
return builder.build();
return Vector<DeprecatedString> { builder.build() };
}
RecursionDecision Heading::walk(Visitor& visitor) const