Skip to content

Commit

Permalink
Auto merge of rust-lang#14428 - dpaoliello:mdman, r=epage
Browse files Browse the repository at this point in the history
[mdman] Normalize newlines when rendering options

When using `cargo build-man` on Windows, I noticed that some files I didn't modify were getting modified, specifically they had an extra space added in the middle of a code block in an option description.

The root cause appears to be that if a code block in a handlebars template was split across multiple lines, then both the `\r` and the `\n` were being converted to spaces.

The fix for this is to normalize newlines to `\n` after templates are expanded by handlebars but before the individual formatters render the block as an option.
  • Loading branch information
bors committed Aug 20, 2024
2 parents 3ef3f61 + 8e2a37c commit 9e152bb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/mdman/src/hbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ impl HelperDef for OptionHelper<'_> {
// Render the block.
let block = t.renders(r, gctx, rc)?;

// Windows newlines can break some rendering, so normalize.
let block = block.replace("\r\n", "\n");

// Get the name of this page.
let man_name = gctx
.data()
Expand Down
5 changes: 5 additions & 0 deletions crates/mdman/tests/compare/expected/options.1
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ Flag with optional value.
.RS 4
Alternate syntax for optional value (with required = for disambiguation).
.RE
.sp
\fB\-\-split\-block\fR
.RS 4
An option where the description has a \fBblock statement that is split across multiple lines\fR
.RE
.SH "EXAMPLES"
.sp
.RS 4
Expand Down
4 changes: 4 additions & 0 deletions crates/mdman/tests/compare/expected/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ A description of the command.
<dd class="option-desc">Alternate syntax for optional value (with required = for disambiguation).</dd>


<dt class="option-term" id="option-options---split-block"><a class="option-anchor" href="#option-options---split-block"></a><code>--split-block</code></dt>
<dd class="option-desc">An option where the description has a <code>block statement that is split across multiple lines</code></dd>


</dl>


Expand Down
4 changes: 4 additions & 0 deletions crates/mdman/tests/compare/expected/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ OPTIONS
Alternate syntax for optional value (with required = for
disambiguation).

--split-block
An option where the description has a block statement that is split
across multiple lines

EXAMPLES
1. An example

Expand Down
5 changes: 5 additions & 0 deletions crates/mdman/tests/compare/includes/options-common.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ Flag with optional value.
Alternate syntax for optional value (with required = for disambiguation).
{{/option}}

{{#option "`--split-block`"}}
An option where the description has a `block statement
that is split across multiple lines`
{{/option}}

{{/options}}

0 comments on commit 9e152bb

Please sign in to comment.