Skip to content

Commit 28b79ea

Browse files
authored
Fix mdman to not incorrectly strip <p> tags (#16158)
This fixes an issue with how mdman was generating HTML for command-line options. It was incorrectly stripping the `<p>` tag in the description of the flag when the description had multiple blocks. The code was assuming the description was just a single paragraph, but that isn't correct when there are multiple paragraphs or other block-level elements like lists. This resulted in broken HTML tags. The solution here is to stop stripping the `<p>` tags from the description, and instead to just use CSS to fix the spacing that it creates. (The specific CSS here will be part of mdbook 0.5.) This will be required for mdbook 0.5 because it is stricter about having properly balanced HTML tags.
2 parents 284eefc + 82061ca commit 28b79ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2194
-1339
lines changed

crates/mdman/doc/out/mdman.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,40 @@ man page:
5454
<dl>
5555

5656
<dt class="option-term" id="option-mdman--t"><a class="option-anchor" href="#option-mdman--t"></a><code>-t</code> <em>type</em></dt>
57-
<dd class="option-desc">Specifies the output type. The following output types are supported:</p>
57+
<dd class="option-desc"><p>Specifies the output type. The following output types are supported:</p>
5858
<ul>
5959
<li><code>man</code> — A troff-style man page. Outputs with a numbered extension (like
6060
<code>.1</code>) matching the man page section.</li>
6161
<li><code>md</code> — A markdown file, after all handlebars processing has been finished.
6262
Outputs with the <code>.md</code> extension.</li>
6363
<li><code>txt</code> — A text file, rendered for situations where a man page viewer isn’t
6464
available. Outputs with the <code>.txt</code> extension.</li>
65-
</ul></dd>
65+
</ul>
66+
</dd>
6667

6768

6869
<dt class="option-term" id="option-mdman--o"><a class="option-anchor" href="#option-mdman--o"></a><code>-o</code> <em>outdir</em></dt>
69-
<dd class="option-desc">Specifies the directory where to save the output.</dd>
70+
<dd class="option-desc"><p>Specifies the directory where to save the output.</p>
71+
</dd>
7072

7173

7274
<dt class="option-term" id="option-mdman---url"><a class="option-anchor" href="#option-mdman---url"></a><code>--url</code> <em>base_url</em></dt>
73-
<dd class="option-desc">Specifies a base URL to use for relative URLs within the document. Any
74-
relative URL will be joined with this URL.</dd>
75+
<dd class="option-desc"><p>Specifies a base URL to use for relative URLs within the document. Any
76+
relative URL will be joined with this URL.</p>
77+
</dd>
7578

7679

7780
<dt class="option-term" id="option-mdman---man"><a class="option-anchor" href="#option-mdman---man"></a><code>--man</code> <em>name</em><code>:</code><em>section</em><code>=</code><em>url</em></dt>
78-
<dd class="option-desc">Specifies a URL to use for the given man page. When the <code>{{man name section}}</code> expression is used, the given URL will be inserted as a link. This
81+
<dd class="option-desc"><p>Specifies a URL to use for the given man page. When the <code>{{man name section}}</code> expression is used, the given URL will be inserted as a link. This
7982
may be specified multiple times. If a man page reference does not have a
8083
matching <code>--man</code> entry, then a relative link to a file named <em>name</em><code>.md</code> will
81-
be used.</dd>
84+
be used.</p>
85+
</dd>
8286

8387

8488
<dt class="option-term" id="option-mdman-sources…"><a class="option-anchor" href="#option-mdman-sources…"></a><em>sources…</em></dt>
85-
<dd class="option-desc">The source input filename, may be specified multiple times.</dd>
89+
<dd class="option-desc"><p>The source input filename, may be specified multiple times.</p>
90+
</dd>
8691

8792

8893
</dl>

crates/mdman/src/format/md.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ impl super::Formatter for MdFormatter {
6767
let rendered_block = self.render_html(block)?;
6868
write!(
6969
result,
70-
"<dd class=\"option-desc\">{}</dd>\n\n",
71-
unwrap_p(&rendered_block)
70+
"<dd class=\"option-desc\">{rendered_block}</dd>\n\n",
7271
)?;
7372
Ok(result)
7473
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Shortcut unknown: [shortcut unknown]
3434

3535
<dl>
3636
<dt class="option-term" id="option-links---include"><a class="option-anchor" href="#option-links---include"></a><code>--include</code></dt>
37-
<dd class="option-desc">Testing an <a href="included_link.html">included link</a>.</dd>
37+
<dd class="option-desc"><p>Testing an <a href="included_link.html">included link</a>.</p>
38+
</dd>
3839

3940
</dl>
4041

@@ -44,8 +45,9 @@ Shortcut unknown: [shortcut unknown]
4445
<dl>
4546

4647
<dt class="option-term" id="option-links---foo-bar"><a class="option-anchor" href="#option-links---foo-bar"></a><code>--foo-bar</code></dt>
47-
<dd class="option-desc">Example <a href="bar.html">link</a>.
48-
See <a href="https://example.org/commands/other-cmd.html">other-cmd(1)</a>, <a href="local-cmd.html">local-cmd(1)</a></dd>
48+
<dd class="option-desc"><p>Example <a href="bar.html">link</a>.
49+
See <a href="https://example.org/commands/other-cmd.html">other-cmd(1)</a>, <a href="local-cmd.html">local-cmd(1)</a></p>
50+
</dd>
4951

5052

5153
</dl>

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ This has multiple flags.
5353
.RS 4
5454
A named argument.
5555
.RE
56+
.sp
57+
\fB\-\-complex\fR
58+
.RS 4
59+
This option has a list.
60+
.sp
61+
.RS 4
62+
\h'-04'\(bu\h'+03'alpha
63+
.RE
64+
.sp
65+
.RS 4
66+
\h'-04'\(bu\h'+03'beta
67+
.RE
68+
.sp
69+
.RS 4
70+
\h'-04'\(bu\h'+03'gamma
71+
.RE
72+
.sp
73+
Then text continues here.
74+
.RE
5675
.SS "Common Options"
5776
.sp
5877
\fB@\fR\fIfilename\fR

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,30 @@ A description of the command.
2929
<dl>
3030

3131
<dt class="option-term" id="option-options---foo-bar"><a class="option-anchor" href="#option-options---foo-bar"></a><code>--foo-bar</code></dt>
32-
<dd class="option-desc">Demo <em>emphasis</em>, <strong>strong</strong>, <del>strike</del></dd>
32+
<dd class="option-desc"><p>Demo <em>emphasis</em>, <strong>strong</strong>, <del>strike</del></p>
33+
</dd>
3334

3435

3536
<dt class="option-term" id="option-options--p"><a class="option-anchor" href="#option-options--p"></a><code>-p</code> <em>spec</em></dt>
3637
<dt class="option-term" id="option-options---package"><a class="option-anchor" href="#option-options---package"></a><code>--package</code> <em>spec</em></dt>
37-
<dd class="option-desc">This has multiple flags.</dd>
38+
<dd class="option-desc"><p>This has multiple flags.</p>
39+
</dd>
3840

3941

4042
<dt class="option-term" id="option-options-named-arg…"><a class="option-anchor" href="#option-options-named-arg…"></a><em>named-arg…</em></dt>
41-
<dd class="option-desc">A named argument.</dd>
43+
<dd class="option-desc"><p>A named argument.</p>
44+
</dd>
45+
46+
47+
<dt class="option-term" id="option-options---complex"><a class="option-anchor" href="#option-options---complex"></a><code>--complex</code></dt>
48+
<dd class="option-desc"><p>This option has a list.</p>
49+
<ul>
50+
<li>alpha</li>
51+
<li>beta</li>
52+
<li>gamma</li>
53+
</ul>
54+
<p>Then text continues here.</p>
55+
</dd>
4256

4357

4458
</dl>
@@ -47,19 +61,23 @@ A description of the command.
4761

4862
<dl>
4963
<dt class="option-term" id="option-options-@filename"><a class="option-anchor" href="#option-options-@filename"></a><code>@</code><em>filename</em></dt>
50-
<dd class="option-desc">Load from filename.</dd>
64+
<dd class="option-desc"><p>Load from filename.</p>
65+
</dd>
5166

5267

5368
<dt class="option-term" id="option-options---foo"><a class="option-anchor" href="#option-options---foo"></a><code>--foo</code> [<em>bar</em>]</dt>
54-
<dd class="option-desc">Flag with optional value.</dd>
69+
<dd class="option-desc"><p>Flag with optional value.</p>
70+
</dd>
5571

5672

5773
<dt class="option-term" id="option-options---foo[=bar]"><a class="option-anchor" href="#option-options---foo[=bar]"></a><code>--foo</code>[<code>=</code><em>bar</em>]</dt>
58-
<dd class="option-desc">Alternate syntax for optional value (with required = for disambiguation).</dd>
74+
<dd class="option-desc"><p>Alternate syntax for optional value (with required = for disambiguation).</p>
75+
</dd>
5976

6077

6178
<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>
79+
<dd class="option-desc"><p>An option where the description has a <code>block statement that is split across multiple lines</code></p>
80+
</dd>
6381

6482

6583
</dl>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ OPTIONS
3232
named-arg…
3333
A named argument.
3434

35+
--complex
36+
This option has a list.
37+
38+
o alpha
39+
40+
o beta
41+
42+
o gamma
43+
44+
Then text continues here.
45+
3546
Common Options
3647
@filename
3748
Load from filename.

crates/mdman/tests/compare/options.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ This has multiple flags.
4040
A named argument.
4141
{{/option}}
4242

43+
{{#option "`--complex`"}}
44+
This option has a list.
45+
46+
- alpha
47+
- beta
48+
- gamma
49+
50+
Then text continues here.
51+
{{/option}}
52+
4353
{{/options}}
4454

4555
### Common Options

src/doc/book.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title = "The Cargo Book"
33
authors = ["Alex Crichton", "Steve Klabnik", "Carol Nichols", "with contributions from the Rust community"]
44

55
[output.html]
6+
additional-css = ["theme/cargo.css"]
67
smart-punctuation = true # Enable smart-punctuation feature for more than quotes.
78
git-repository-url = "https://github.com/rust-lang/cargo/tree/master/src/doc/src"
89
edit-url-template = "https://github.com/rust-lang/cargo/edit/master/src/doc/{path}"

0 commit comments

Comments
 (0)