Skip to content

Commit 9e152bb

Browse files
committed
Auto merge of #14428 - dpaoliello:mdman, r=epage
[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.
2 parents 3ef3f61 + 8e2a37c commit 9e152bb

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

crates/mdman/src/hbs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ impl HelperDef for OptionHelper<'_> {
139139
// Render the block.
140140
let block = t.renders(r, gctx, rc)?;
141141

142+
// Windows newlines can break some rendering, so normalize.
143+
let block = block.replace("\r\n", "\n");
144+
142145
// Get the name of this page.
143146
let man_name = gctx
144147
.data()

crates/mdman/tests/compare/expected/options.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ Flag with optional value.
6969
.RS 4
7070
Alternate syntax for optional value (with required = for disambiguation).
7171
.RE
72+
.sp
73+
\fB\-\-split\-block\fR
74+
.RS 4
75+
An option where the description has a \fBblock statement that is split across multiple lines\fR
76+
.RE
7277
.SH "EXAMPLES"
7378
.sp
7479
.RS 4

crates/mdman/tests/compare/expected/options.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ A description of the command.
5858
<dd class="option-desc">Alternate syntax for optional value (with required = for disambiguation).</dd>
5959

6060

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

6367

crates/mdman/tests/compare/expected/options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ OPTIONS
4343
Alternate syntax for optional value (with required = for
4444
disambiguation).
4545

46+
--split-block
47+
An option where the description has a block statement that is split
48+
across multiple lines
49+
4650
EXAMPLES
4751
1. An example
4852

crates/mdman/tests/compare/includes/options-common.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ Flag with optional value.
1111
Alternate syntax for optional value (with required = for disambiguation).
1212
{{/option}}
1313

14+
{{#option "`--split-block`"}}
15+
An option where the description has a `block statement
16+
that is split across multiple lines`
17+
{{/option}}
18+
1419
{{/options}}

0 commit comments

Comments
 (0)