mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:27:46 +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:
parent
7a4b912ece
commit
5cc984d74c
20 changed files with 85 additions and 55 deletions
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Forward.h>
|
||||
#include <LibMarkdown/BlockQuote.h>
|
||||
#include <LibMarkdown/CodeBlock.h>
|
||||
#include <LibMarkdown/ContainerBlock.h>
|
||||
|
@ -39,16 +40,16 @@ DeprecatedString ContainerBlock::render_to_html(bool tight) const
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
DeprecatedString ContainerBlock::render_for_terminal(size_t view_width) const
|
||||
Vector<DeprecatedString> ContainerBlock::render_lines_for_terminal(size_t view_width) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
Vector<DeprecatedString> lines;
|
||||
|
||||
for (auto& block : m_blocks) {
|
||||
auto s = block.render_for_terminal(view_width);
|
||||
builder.append(s);
|
||||
for (auto& line : block.render_lines_for_terminal(view_width))
|
||||
lines.append(move(line));
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
return lines;
|
||||
}
|
||||
|
||||
RecursionDecision ContainerBlock::walk(Visitor& visitor) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue