summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibMarkdown/CodeBlock.cpp
diff options
context:
space:
mode:
authordemostanis <demostanis@protonmail.com>2022-07-31 21:53:25 +0200
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-08-04 16:57:26 +0000
commit55b7f8ab27b94af0a7daa49063c4d5db8271e61e (patch)
tree1f4114a26a5e8494f8fb20969d76dceaa92d64e3 /Userland/Libraries/LibMarkdown/CodeBlock.cpp
parent7537a045e5f127804040e44b13dcca3c7a5de3c6 (diff)
downloadserenity-55b7f8ab27b94af0a7daa49063c4d5db8271e61e.zip
LibMarkdown: Indent code blocks
Diffstat (limited to 'Userland/Libraries/LibMarkdown/CodeBlock.cpp')
-rw-r--r--Userland/Libraries/LibMarkdown/CodeBlock.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/Userland/Libraries/LibMarkdown/CodeBlock.cpp b/Userland/Libraries/LibMarkdown/CodeBlock.cpp
index c22aae97b7..87a82b24bb 100644
--- a/Userland/Libraries/LibMarkdown/CodeBlock.cpp
+++ b/Userland/Libraries/LibMarkdown/CodeBlock.cpp
@@ -51,9 +51,13 @@ String CodeBlock::render_for_terminal(size_t) const
StringBuilder builder;
for (auto line : m_code.split('\n')) {
+ // Do not indent too much if we are in the synopsis
+ if (!(m_current_section && m_current_section->render_for_terminal().contains("SYNOPSIS"sv)))
+ builder.append(" "sv);
+
builder.append(" "sv);
builder.append(line);
- builder.append("\n"sv);
+ builder.append("\x1b[0m\n"sv);
}
return builder.build();
@@ -104,14 +108,14 @@ static Optional<int> line_block_prefix(StringView const& line)
return {};
}
-OwnPtr<CodeBlock> CodeBlock::parse(LineIterator& lines)
+OwnPtr<CodeBlock> CodeBlock::parse(LineIterator& lines, Heading* current_section)
{
if (lines.is_end())
return {};
StringView line = *lines;
if (open_fence_re.match(line).success)
- return parse_backticks(lines);
+ return parse_backticks(lines, current_section);
if (line_block_prefix(line).has_value())
return parse_indent(lines);
@@ -119,7 +123,7 @@ OwnPtr<CodeBlock> CodeBlock::parse(LineIterator& lines)
return {};
}
-OwnPtr<CodeBlock> CodeBlock::parse_backticks(LineIterator& lines)
+OwnPtr<CodeBlock> CodeBlock::parse_backticks(LineIterator& lines, Heading* current_section)
{
StringView line = *lines;
@@ -160,7 +164,7 @@ OwnPtr<CodeBlock> CodeBlock::parse_backticks(LineIterator& lines)
builder.append('\n');
}
- return make<CodeBlock>(language, style, builder.build());
+ return make<CodeBlock>(language, style, builder.build(), current_section);
}
OwnPtr<CodeBlock> CodeBlock::parse_indent(LineIterator& lines)
@@ -183,6 +187,6 @@ OwnPtr<CodeBlock> CodeBlock::parse_indent(LineIterator& lines)
builder.append('\n');
}
- return make<CodeBlock>("", "", builder.build());
+ return make<CodeBlock>("", "", builder.build(), nullptr);
}
}