Skip to content

Commit 7f2810f

Browse files
committed
Rewrite std_links
This rewrites std_links for two major changes: - Uses pulldown_cmark to parse the markdown instead of using regular expressions. The RegEx approach was just too unreliable. - Call rustdoc only once, instead of once per chapter. The overhead of calling rustdoc is significant, and calling it for each chapter was extremely slow. Unfortunately the error messages are a little worse now, since it doesn't show which chapter a bad link came from. I'm uncertain how to make that better.
1 parent ecf7600 commit 7f2810f

File tree

4 files changed

+246
-120
lines changed

4 files changed

+246
-120
lines changed

mdbook-spec/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mdbook-spec/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ anyhow = "1.0.79"
1313
mdbook = { version = "0.4.36", default-features = false }
1414
once_cell = "1.19.0"
1515
pathdiff = "0.2.1"
16+
# Try to keep in sync with mdbook.
17+
pulldown-cmark = { version = "0.10.3", default-features = false }
1618
regex = "1.9.4"
1719
semver = "1.0.21"
1820
serde_json = "1.0.113"

mdbook-spec/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ impl Preprocessor for Spec {
154154
}
155155
ch.content = self.rule_definitions(&ch, &mut found_rules);
156156
ch.content = self.admonitions(&ch);
157-
ch.content = std_links::std_links(&ch);
158157
});
159158
// This is a separate pass because it relies on the modifications of
160159
// the previous passes.
@@ -167,6 +166,10 @@ impl Preprocessor for Spec {
167166
}
168167
ch.content = self.auto_link_references(&ch, &found_rules);
169168
});
169+
// Final pass will resolve everything as a std link (or error if the
170+
// link is unknown).
171+
std_links::std_links(&mut book);
172+
170173
Ok(book)
171174
}
172175
}

0 commit comments

Comments
 (0)