diff options
author | Peter Elliott <pelliott@ualberta.ca> | 2021-09-10 00:50:42 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-12 12:17:16 +0200 |
commit | 565b561522d5eaac29d1c8fd326018bad6ea3066 (patch) | |
tree | 3af82881596a9528fe4f74a062209cc862620931 /Userland/Libraries/LibMarkdown/Text.cpp | |
parent | 9c0563cc1026dc23da8639100cd782374d9debe6 (diff) | |
download | serenity-565b561522d5eaac29d1c8fd326018bad6ea3066.zip |
LibMarkdown: Render sequences of spaces properly in the terminal
Diffstat (limited to 'Userland/Libraries/LibMarkdown/Text.cpp')
-rw-r--r-- | Userland/Libraries/LibMarkdown/Text.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Userland/Libraries/LibMarkdown/Text.cpp b/Userland/Libraries/LibMarkdown/Text.cpp index 71995fc7fb..ddc0901c07 100644 --- a/Userland/Libraries/LibMarkdown/Text.cpp +++ b/Userland/Libraries/LibMarkdown/Text.cpp @@ -79,13 +79,19 @@ void Text::TextNode::render_to_html(StringBuilder& builder) const void Text::TextNode::render_for_terminal(StringBuilder& builder) const { - String text_copy = text; - text_copy.replace("\n", " "); - builder.append(text_copy); + if (collapsible && (text == "\n" || text.is_whitespace())) { + builder.append(" "); + } else { + builder.append(text); + } } size_t Text::TextNode::terminal_length() const { + if (collapsible && text.is_whitespace()) { + return 1; + } + return text.length(); } @@ -445,7 +451,7 @@ NonnullOwnPtr<Text::Node> Text::parse_code(Vector<Token>::ConstIterator& tokens) } is_all_whitespace = is_all_whitespace && iterator->data.is_whitespace(); - code->children.append(make<TextNode>((*iterator == "\n") ? " " : iterator->data)); + code->children.append(make<TextNode>((*iterator == "\n") ? " " : iterator->data, false)); } return make<TextNode>(opening.data); |