Skip to content

Commit af64bd6

Browse files
committed
Auto merge of #8793 - ehuss:fix-man-links, r=alexcrichton
Fix man page links inside `option` blocks. Links inside `{{#option}}` blocks were erroneously being converted to absolute links when emitting the `md` format because they were being rendered as HTML. This wasn't intended and caused some links to fail. It also causes problems for offline viewing (since the links are to an external website). Also, man-page links like `{{man "cargo-foo" 1}}` were linking to `.md` extension, but since they are processed as markdown into HTML, mdbook's `.md` to `.html` translation wasn't getting applied. The simple fix is to always use `.html`. This revealed a legitimate error in a link in `cargo-publish.md` which had the wrong anchor link (`#registrydefault`). This also revealed that the CI check that the man pages are in sync wasn't working quite right (it was not checking the `etc/man` directory for changes).
2 parents 79b397d + 1a86f23 commit af64bd6

Some content is hidden

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

45 files changed

+355
-291
lines changed

ci/validate-man.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55

66
cd src/doc
77

8-
changes=$(git status --porcelain .)
8+
changes=$(git status --porcelain)
99
if [ -n "$changes" ]
1010
then
1111
echo "git directory must be clean before running this script."
@@ -14,7 +14,7 @@ fi
1414

1515
./build-man.sh
1616

17-
changes=$(git status --porcelain .)
17+
changes=$(git status --porcelain)
1818
if [ -n "$changes" ]
1919
then
2020
echo "Detected changes in man pages:"

crates/mdman/src/format/md.rs

Lines changed: 4 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 22 additions & 1 deletion
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)
Lines changed: 7 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)