Skip to content

Commit 1a86f23

Browse files
committed
Fix man page links inside option blocks.
1 parent 77d71eb commit 1a86f23

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

+353
-289
lines changed

crates/mdman/src/format/md.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ use crate::util::unwrap;
44
use crate::ManMap;
55
use anyhow::{bail, format_err, Error};
66
use std::fmt::Write;
7-
use url::Url;
87

98
pub struct MdFormatter {
10-
url: Option<Url>,
119
man_map: ManMap,
1210
}
1311

1412
impl MdFormatter {
15-
pub fn new(url: Option<Url>, man_map: ManMap) -> MdFormatter {
16-
MdFormatter { url, man_map }
13+
pub fn new(man_map: ManMap) -> MdFormatter {
14+
MdFormatter { man_map }
1715
}
1816
}
1917

2018
impl MdFormatter {
2119
fn render_html(&self, input: &str) -> Result<String, Error> {
22-
let parser = crate::md_parser(input, self.url.clone());
20+
let parser = crate::md_parser(input, None);
2321
let mut html_output: String = String::with_capacity(input.len() * 3 / 2);
2422
pulldown_cmark::html::push_html(&mut html_output, parser.map(|(e, _r)| e));
2523
Ok(html_output)
@@ -78,7 +76,7 @@ impl super::Formatter for MdFormatter {
7876
fn linkify_man_to_md(&self, name: &str, section: u8) -> Result<String, Error> {
7977
let s = match self.man_map.get(&(name.to_string(), section)) {
8078
Some(link) => format!("[{}({})]({})", name, section, link),
81-
None => format!("[{}({})]({}.md)", name, section, name),
79+
None => format!("[{}({})]({}.html)", name, section, name),
8280
};
8381
Ok(s)
8482
}

crates/mdman/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn convert(
5050
) -> Result<String, Error> {
5151
let formatter: Box<dyn Formatter + Send + Sync> = match format {
5252
Format::Man => Box::new(format::man::ManFormatter::new(url)),
53-
Format::Md => Box::new(format::md::MdFormatter::new(url, man_map)),
53+
Format::Md => Box::new(format::md::MdFormatter::new(man_map)),
5454
Format::Text => Box::new(format::text::TextFormatter::new(url)),
5555
};
5656
let expanded = hbs::expand(file, &*formatter)?;

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

+14
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,17 @@ Shortcut unknown: [shortcut unknown]
2929
\fBother\-cmd\fR(1)
3030
.sp
3131
\fBlocal\-cmd\fR(1)
32+
.sp
33+
\fISome link\fR <https://example.org/foo.html>
34+
.sp
35+
\fB\-\-include\fR
36+
.RS 4
37+
Testing an \fIincluded link\fR <https://example.org/included_link.html>\&.
38+
.RE
39+
.SH "OPTIONS"
40+
.sp
41+
\fB\-\-foo\-bar\fR
42+
.RS 4
43+
Example \fIlink\fR <https://example.org/bar.html>\&.
44+
See \fBother\-cmd\fR(1), \fBlocal\-cmd\fR(1)
45+
.RE

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,28 @@ Shortcut unknown: [shortcut unknown]
2828

2929
[other-cmd(1)](https://example.org/commands/other-cmd.html)
3030

31-
[local-cmd(1)](local-cmd.md)
31+
[local-cmd(1)](local-cmd.html)
32+
33+
[Some link](foo.html)
34+
35+
<dl>
36+
<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>
38+
39+
</dl>
40+
41+
42+
## OPTIONS
43+
44+
<dl>
45+
46+
<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>
49+
50+
51+
</dl>
52+
3253

3354
[bar]: https://example.com/bar
3455
[collapsed]: https://example.com/collapsed

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

+10
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,13 @@ DESCRIPTION
2828

2929
local-cmd(1)
3030

31+
Some link <https://example.org/foo.html>
32+
33+
--include
34+
Testing an included link <https://example.org/included_link.html>.
35+
36+
OPTIONS
37+
--foo-bar
38+
Example link <https://example.org/bar.html>. See other-cmd(1),
39+
local-cmd(1)
40+

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ A description of the command.
7474
my-command --xyz
7575

7676
## SEE ALSO
77-
[other-command(1)](other-command.md) [abc(7)](abc.md)
77+
[other-command(1)](other-command.html) [abc(7)](abc.html)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[Some link](foo.html)
2+
3+
{{#options}}
4+
{{#option "`--include`"}}
5+
Testing an [included link](included_link.html).
6+
{{/option}}
7+
{{/options}}

crates/mdman/tests/compare/links.md

+14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ Shortcut unknown: [shortcut unknown]
3030

3131
{{man "local-cmd" 1}}
3232

33+
{{> links-include}}
34+
35+
## OPTIONS
36+
37+
{{#options}}
38+
39+
{{#option "`--foo-bar`"}}
40+
Example [link](bar.html).
41+
See {{man "other-cmd" 1}}, {{man "local-cmd" 1}}
42+
{{/option}}
43+
44+
{{/options}}
45+
46+
3347
[bar]: https://example.com/bar
3448
[collapsed]: https://example.com/collapsed
3549
[shortcut]: https://example.com/shortcut

src/doc/man/cargo-publish.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ config files](../reference/config.html). If not specified, and there is a
5757
[`package.publish`](../reference/manifest.html#the-publish-field) field in
5858
`Cargo.toml` with a single registry, then it will publish to that registry.
5959
Otherwise it will use the default registry, which is defined by the
60-
[`registry.default`](../reference/config.html#registry-default) config key
60+
[`registry.default`](../reference/config.html#registrydefault) config key
6161
which defaults to `crates-io`.
6262
{{/option}}
6363

src/doc/man/generated_txt/cargo-publish.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ OPTIONS
6464
field in Cargo.toml with a single registry, then it will publish to
6565
that registry. Otherwise it will use the default registry, which is
6666
defined by the registry.default
67-
<https://doc.rust-lang.org/cargo/reference/config.html#registry-default>
67+
<https://doc.rust-lang.org/cargo/reference/config.html#registrydefault>
6868
config key which defaults to crates-io.
6969

7070
Compilation Options

src/doc/src/commands/cargo-bench.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ virtual workspace will include all workspace members (equivalent to passing
8080

8181
<dt class="option-term" id="option-cargo-bench--p"><a class="option-anchor" href="#option-cargo-bench--p"></a><code>-p</code> <em>spec</em>...</dt>
8282
<dt class="option-term" id="option-cargo-bench---package"><a class="option-anchor" href="#option-cargo-bench---package"></a><code>--package</code> <em>spec</em>...</dt>
83-
<dd class="option-desc">Benchmark only the specified packages. See <a href="https://doc.rust-lang.org/cargo/commands/cargo-pkgid.md">cargo-pkgid(1)</a> for the
83+
<dd class="option-desc">Benchmark only the specified packages. See <a href="cargo-pkgid.html">cargo-pkgid(1)</a> for the
8484
SPEC format. This flag may be specified multiple times.</dd>
8585

8686

@@ -224,10 +224,10 @@ architecture. The general format of the triple is
224224
<code>&lt;arch&gt;&lt;sub&gt;-&lt;vendor&gt;-&lt;sys&gt;-&lt;abi&gt;</code>. Run <code>rustc --print target-list</code> for a
225225
list of supported targets.</p>
226226
<p>This may also be specified with the <code>build.target</code>
227-
<a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>.</p>
227+
<a href="../reference/config.html">config value</a>.</p>
228228
<p>Note that specifying this flag makes Cargo run in a different mode where the
229229
target artifacts are placed in a separate directory. See the
230-
<a href="https://doc.rust-lang.org/cargo/guide/build-cache.html">build cache</a> documentation for more details.</dd>
230+
<a href="../guide/build-cache.html">build cache</a> documentation for more details.</dd>
231231

232232

233233

@@ -239,7 +239,7 @@ target artifacts are placed in a separate directory. See the
239239
<dt class="option-term" id="option-cargo-bench---target-dir"><a class="option-anchor" href="#option-cargo-bench---target-dir"></a><code>--target-dir</code> <em>directory</em></dt>
240240
<dd class="option-desc">Directory for all generated artifacts and intermediate files. May also be
241241
specified with the <code>CARGO_TARGET_DIR</code> environment variable, or the
242-
<code>build.target-dir</code> <a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>. Defaults
242+
<code>build.target-dir</code> <a href="../reference/config.html">config value</a>. Defaults
243243
to <code>target</code> in the root of the workspace.</dd>
244244

245245

@@ -260,7 +260,7 @@ passing `--nocapture` to the benchmark binaries:
260260
<dd class="option-desc">Use verbose output. May be specified twice for &quot;very verbose&quot; output which
261261
includes extra output such as dependency warnings and build script output.
262262
May also be specified with the <code>term.verbose</code>
263-
<a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>.</dd>
263+
<a href="../reference/config.html">config value</a>.</dd>
264264

265265

266266
<dt class="option-term" id="option-cargo-bench--q"><a class="option-anchor" href="#option-cargo-bench--q"></a><code>-q</code></dt>
@@ -277,7 +277,7 @@ terminal.</li>
277277
<li><code>never</code>: Never display colors.</li>
278278
</ul>
279279
<p>May also be specified with the <code>term.color</code>
280-
<a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>.</dd>
280+
<a href="../reference/config.html">config value</a>.</dd>
281281

282282

283283

@@ -288,7 +288,7 @@ and consists of comma-separated values. Valid values:</p>
288288
<li><code>human</code> (default): Display in a human-readable text format.</li>
289289
<li><code>short</code>: Emit shorter, human-readable text messages.</li>
290290
<li><code>json</code>: Emit JSON messages to stdout. See
291-
<a href="https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages">the reference</a>
291+
<a href="../reference/external-tools.html#json-messages">the reference</a>
292292
for more details.</li>
293293
<li><code>json-diagnostic-short</code>: Ensure the <code>rendered</code> field of JSON messages contains
294294
the &quot;short&quot; rendering from rustc.</li>
@@ -333,9 +333,9 @@ proceed without the network if possible.</p>
333333
<p>Beware that this may result in different dependency resolution than online
334334
mode. Cargo will restrict itself to crates that are downloaded locally, even
335335
if there might be a newer version as indicated in the local copy of the index.
336-
See the <a href="https://doc.rust-lang.org/cargo/commands/cargo-fetch.md">cargo-fetch(1)</a> command to download dependencies before going
336+
See the <a href="cargo-fetch.html">cargo-fetch(1)</a> command to download dependencies before going
337337
offline.</p>
338-
<p>May also be specified with the <code>net.offline</code> <a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>.</dd>
338+
<p>May also be specified with the <code>net.offline</code> <a href="../reference/config.html">config value</a>.</dd>
339339

340340

341341
</dl>
@@ -374,7 +374,7 @@ Rust test harness runs benchmarks serially in a single thread.
374374
<dt class="option-term" id="option-cargo-bench--j"><a class="option-anchor" href="#option-cargo-bench--j"></a><code>-j</code> <em>N</em></dt>
375375
<dt class="option-term" id="option-cargo-bench---jobs"><a class="option-anchor" href="#option-cargo-bench---jobs"></a><code>--jobs</code> <em>N</em></dt>
376376
<dd class="option-desc">Number of parallel jobs to run. May also be specified with the
377-
<code>build.jobs</code> <a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>. Defaults to
377+
<code>build.jobs</code> <a href="../reference/config.html">config value</a>. Defaults to
378378
the number of CPUs.</dd>
379379

380380

@@ -393,7 +393,7 @@ are built with the `release` profiles when linked to binaries and benchmarks.
393393
Dependencies use the `release` profile.
394394

395395
If you need a debug build of a benchmark, try building it with
396-
[cargo-build(1)](cargo-build.md) which will use the `test` profile which is by default
396+
[cargo-build(1)](cargo-build.html) which will use the `test` profile which is by default
397397
unoptimized and includes debug information. You can then run the debug-enabled
398398
benchmark manually.
399399

@@ -420,4 +420,4 @@ details on environment variables that Cargo reads.
420420
cargo bench --bench bench_name -- modname::some_benchmark
421421

422422
## SEE ALSO
423-
[cargo(1)](cargo.md), [cargo-test(1)](cargo-test.md)
423+
[cargo(1)](cargo.html), [cargo-test(1)](cargo-test.html)

src/doc/src/commands/cargo-build.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ virtual workspace will include all workspace members (equivalent to passing
3232

3333
<dt class="option-term" id="option-cargo-build--p"><a class="option-anchor" href="#option-cargo-build--p"></a><code>-p</code> <em>spec</em>...</dt>
3434
<dt class="option-term" id="option-cargo-build---package"><a class="option-anchor" href="#option-cargo-build---package"></a><code>--package</code> <em>spec</em>...</dt>
35-
<dd class="option-desc">Build only the specified packages. See <a href="https://doc.rust-lang.org/cargo/commands/cargo-pkgid.md">cargo-pkgid(1)</a> for the
35+
<dd class="option-desc">Build only the specified packages. See <a href="cargo-pkgid.html">cargo-pkgid(1)</a> for the
3636
SPEC format. This flag may be specified multiple times.</dd>
3737

3838

@@ -163,10 +163,10 @@ architecture. The general format of the triple is
163163
<code>&lt;arch&gt;&lt;sub&gt;-&lt;vendor&gt;-&lt;sys&gt;-&lt;abi&gt;</code>. Run <code>rustc --print target-list</code> for a
164164
list of supported targets.</p>
165165
<p>This may also be specified with the <code>build.target</code>
166-
<a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>.</p>
166+
<a href="../reference/config.html">config value</a>.</p>
167167
<p>Note that specifying this flag makes Cargo run in a different mode where the
168168
target artifacts are placed in a separate directory. See the
169-
<a href="https://doc.rust-lang.org/cargo/guide/build-cache.html">build cache</a> documentation for more details.</dd>
169+
<a href="../guide/build-cache.html">build cache</a> documentation for more details.</dd>
170170

171171

172172

@@ -185,7 +185,7 @@ selection.</dd>
185185
<dt class="option-term" id="option-cargo-build---target-dir"><a class="option-anchor" href="#option-cargo-build---target-dir"></a><code>--target-dir</code> <em>directory</em></dt>
186186
<dd class="option-desc">Directory for all generated artifacts and intermediate files. May also be
187187
specified with the <code>CARGO_TARGET_DIR</code> environment variable, or the
188-
<code>build.target-dir</code> <a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>. Defaults
188+
<code>build.target-dir</code> <a href="../reference/config.html">config value</a>. Defaults
189189
to <code>target</code> in the root of the workspace.</dd>
190190

191191

@@ -208,7 +208,7 @@ See https://github.com/rust-lang/cargo/issues/6790 for more information.</dd>
208208
<dd class="option-desc">Use verbose output. May be specified twice for &quot;very verbose&quot; output which
209209
includes extra output such as dependency warnings and build script output.
210210
May also be specified with the <code>term.verbose</code>
211-
<a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>.</dd>
211+
<a href="../reference/config.html">config value</a>.</dd>
212212

213213

214214
<dt class="option-term" id="option-cargo-build--q"><a class="option-anchor" href="#option-cargo-build--q"></a><code>-q</code></dt>
@@ -225,7 +225,7 @@ terminal.</li>
225225
<li><code>never</code>: Never display colors.</li>
226226
</ul>
227227
<p>May also be specified with the <code>term.color</code>
228-
<a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>.</dd>
228+
<a href="../reference/config.html">config value</a>.</dd>
229229

230230

231231

@@ -236,7 +236,7 @@ and consists of comma-separated values. Valid values:</p>
236236
<li><code>human</code> (default): Display in a human-readable text format.</li>
237237
<li><code>short</code>: Emit shorter, human-readable text messages.</li>
238238
<li><code>json</code>: Emit JSON messages to stdout. See
239-
<a href="https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages">the reference</a>
239+
<a href="../reference/external-tools.html#json-messages">the reference</a>
240240
for more details.</li>
241241
<li><code>json-diagnostic-short</code>: Ensure the <code>rendered</code> field of JSON messages contains
242242
the &quot;short&quot; rendering from rustc.</li>
@@ -289,9 +289,9 @@ proceed without the network if possible.</p>
289289
<p>Beware that this may result in different dependency resolution than online
290290
mode. Cargo will restrict itself to crates that are downloaded locally, even
291291
if there might be a newer version as indicated in the local copy of the index.
292-
See the <a href="https://doc.rust-lang.org/cargo/commands/cargo-fetch.md">cargo-fetch(1)</a> command to download dependencies before going
292+
See the <a href="cargo-fetch.html">cargo-fetch(1)</a> command to download dependencies before going
293293
offline.</p>
294-
<p>May also be specified with the <code>net.offline</code> <a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>.</dd>
294+
<p>May also be specified with the <code>net.offline</code> <a href="../reference/config.html">config value</a>.</dd>
295295

296296

297297
</dl>
@@ -326,7 +326,7 @@ for more information about how toolchain overrides work.</dd>
326326
<dt class="option-term" id="option-cargo-build--j"><a class="option-anchor" href="#option-cargo-build--j"></a><code>-j</code> <em>N</em></dt>
327327
<dt class="option-term" id="option-cargo-build---jobs"><a class="option-anchor" href="#option-cargo-build---jobs"></a><code>--jobs</code> <em>N</em></dt>
328328
<dd class="option-desc">Number of parallel jobs to run. May also be specified with the
329-
<code>build.jobs</code> <a href="https://doc.rust-lang.org/cargo/reference/config.html">config value</a>. Defaults to
329+
<code>build.jobs</code> <a href="../reference/config.html">config value</a>. Defaults to
330330
the number of CPUs.</dd>
331331

332332

@@ -373,4 +373,4 @@ details on environment variables that Cargo reads.
373373
cargo build --release
374374

375375
## SEE ALSO
376-
[cargo(1)](cargo.md), [cargo-rustc(1)](cargo-rustc.md)
376+
[cargo(1)](cargo.html), [cargo-rustc(1)](cargo-rustc.html)

0 commit comments

Comments
 (0)