| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "tools/gn/standard_out.h" | 5 #include "tools/gn/standard_out.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 244 } |
| 245 | 245 |
| 246 OutputString(line.substr(first_normal) + "\n"); | 246 OutputString(line.substr(first_normal) + "\n"); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void PrintLongHelp(const std::string& text, const std::string& tag) { | 249 void PrintLongHelp(const std::string& text, const std::string& tag) { |
| 250 EnsureInitialized(); | 250 EnsureInitialized(); |
| 251 | 251 |
| 252 bool first_header = true; | 252 bool first_header = true; |
| 253 bool in_body = false; | 253 bool in_body = false; |
| 254 std::size_t empty_lines = 0; |
| 254 for (const std::string& line : base::SplitString( | 255 for (const std::string& line : base::SplitString( |
| 255 text, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL)) { | 256 text, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 256 // Check for a heading line. | 257 // Check for a heading line. |
| 257 if (!line.empty() && line[0] != ' ') { | 258 if (!line.empty() && line[0] != ' ') { |
| 259 // New paragraph, just skip any trailing empty lines. |
| 260 empty_lines = 0; |
| 261 |
| 258 if (is_markdown) { | 262 if (is_markdown) { |
| 259 // GN's block-level formatting is converted to markdown as follows: | 263 // GN's block-level formatting is converted to markdown as follows: |
| 260 // * The first heading is treated as an H3. | 264 // * The first heading is treated as an H3. |
| 261 // * Subsequent heading are treated as H4s. | 265 // * Subsequent heading are treated as H4s. |
| 262 // * Any other text is wrapped in a code block and displayed as-is. | 266 // * Any other text is wrapped in a code block and displayed as-is. |
| 263 // | 267 // |
| 264 // Span-level formatting (the decorations) is converted inside | 268 // Span-level formatting (the decorations) is converted inside |
| 265 // OutputString(). | 269 // OutputString(). |
| 266 if (in_body) { | 270 if (in_body) { |
| 267 OutputString("```\n\n", DECORATION_NONE); | 271 OutputString("```\n\n", DECORATION_NONE); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 291 | 295 |
| 292 OutputString(line.substr(0, chars_to_highlight), DECORATION_YELLOW); | 296 OutputString(line.substr(0, chars_to_highlight), DECORATION_YELLOW); |
| 293 OutputString(line.substr(chars_to_highlight)); | 297 OutputString(line.substr(chars_to_highlight)); |
| 294 OutputString("\n"); | 298 OutputString("\n"); |
| 295 continue; | 299 continue; |
| 296 } else if (is_markdown && !line.empty() && !in_body) { | 300 } else if (is_markdown && !line.empty() && !in_body) { |
| 297 OutputString("```\n", DECORATION_NONE); | 301 OutputString("```\n", DECORATION_NONE); |
| 298 in_body = true; | 302 in_body = true; |
| 299 } | 303 } |
| 300 | 304 |
| 305 // We buffer empty lines, so we can skip them if needed |
| 306 // (i.e. new paragraph body, end of final paragraph body). |
| 307 if (in_body && is_markdown) { |
| 308 if (!line.empty() && empty_lines != 0) { |
| 309 OutputString(std::string(empty_lines, '\n')); |
| 310 empty_lines = 0; |
| 311 } else if (line.empty()) { |
| 312 ++empty_lines; |
| 313 continue; |
| 314 } |
| 315 } |
| 316 |
| 301 // Check for a comment. | 317 // Check for a comment. |
| 302 TextDecoration dec = DECORATION_NONE; | 318 TextDecoration dec = DECORATION_NONE; |
| 303 for (const auto& elem : line) { | 319 for (const auto& elem : line) { |
| 304 if (elem == '#' && !is_markdown) { | 320 if (elem == '#' && !is_markdown) { |
| 305 // Got a comment, draw dimmed. | 321 // Got a comment, draw dimmed. |
| 306 dec = DECORATION_DIM; | 322 dec = DECORATION_DIM; |
| 307 break; | 323 break; |
| 308 } else if (elem != ' ') { | 324 } else if (elem != ' ') { |
| 309 break; | 325 break; |
| 310 } | 326 } |
| 311 } | 327 } |
| 312 | 328 |
| 313 OutputString(line + "\n", dec); | 329 OutputString(line + "\n", dec); |
| 314 } | 330 } |
| 315 | 331 |
| 316 if (is_markdown && in_body) | 332 if (is_markdown && in_body) |
| 317 OutputString("\n```\n"); | 333 OutputString("```\n"); |
| 318 } | 334 } |
| 319 | 335 |
| OLD | NEW |