Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: tools/gn/standard_out.cc

Issue 2773043005: GN: Trim newlines in markdown help blocks (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/command_help.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/standard_out.cc
diff --git a/tools/gn/standard_out.cc b/tools/gn/standard_out.cc
index fa347e2a146b93cf75c316cb30b75248835a708e..8a6b7ef63b0352fdc57706b67fb8b2baf2b7f06b 100644
--- a/tools/gn/standard_out.cc
+++ b/tools/gn/standard_out.cc
@@ -251,10 +251,14 @@ void PrintLongHelp(const std::string& text, const std::string& tag) {
bool first_header = true;
bool in_body = false;
+ std::size_t empty_lines = 0;
for (const std::string& line : base::SplitString(
text, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL)) {
// Check for a heading line.
if (!line.empty() && line[0] != ' ') {
+ // New paragraph, just skip any trailing empty lines.
+ empty_lines = 0;
+
if (is_markdown) {
// GN's block-level formatting is converted to markdown as follows:
// * The first heading is treated as an H3.
@@ -298,6 +302,18 @@ void PrintLongHelp(const std::string& text, const std::string& tag) {
in_body = true;
}
+ // We buffer empty lines, so we can skip them if needed
+ // (i.e. new paragraph body, end of final paragraph body).
+ if (in_body && is_markdown) {
+ if (!line.empty() && empty_lines != 0) {
+ OutputString(std::string(empty_lines, '\n'));
+ empty_lines = 0;
+ } else if (line.empty()) {
+ ++empty_lines;
+ continue;
+ }
+ }
+
// Check for a comment.
TextDecoration dec = DECORATION_NONE;
for (const auto& elem : line) {
@@ -314,6 +330,6 @@ void PrintLongHelp(const std::string& text, const std::string& tag) {
}
if (is_markdown && in_body)
- OutputString("\n```\n");
+ OutputString("```\n");
}
« no previous file with comments | « tools/gn/command_help.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698