-
Notifications
You must be signed in to change notification settings - Fork 530
Add the ability for rules to be specified in link definitions #1775
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
mdbook-spec/src/lib.rs
Outdated
if let Some((_source_path, path)) = rules.def_paths.get(dest) { | ||
let label = &caps["label"]; | ||
let relative = pathdiff::diff_paths(path, current_path).unwrap(); | ||
// Adjust paths for Windows. | ||
let relative = relative.display().to_string().replace('\\', "/"); | ||
return format!("[{label}]: {relative}#r-{dest}"); | ||
} else { | ||
return caps.get(0).unwrap().as_str().to_string(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since all branches diverge, it makes sense to move the return
outward. Will update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, of course, here we don't need the return
at all.
MD_LINK_REFERENCE_DEFINITION | ||
.replace_all(&chapter.content, |caps: &Captures<'_>| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is OK of course, but as you mention, it'd be better to do it otherwise. Remind me to ask you sometime about what the challenges are here.
/// For example: | ||
/// ```markdown | ||
/// See [this rule]. | ||
/// | ||
/// [this rule]: expr.array | ||
/// ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm adding an example use of this to introduction page also.
0c55417
to
f44f16e
Compare
This adds the ability to link to rules from a link definition. For example: ```markdown See [this rule]. [this rule]: expr.array ``` This will convert `[this rule]` to point to the link of the file for that rule. This is somewhat hacky, as parsing markdown with regex is unwise (and this is intentionally incomplete), and could maybe be done more efficiently.
On the introduction page, where we talk about rule identifiers, let's add an example use of putting the rule identifier in the link definition so that we have an easy way of verifying that this mechanism works as intended.
f44f16e
to
f37173d
Compare
Update books ## rust-lang/reference 12 commits in e95ebdfee02514d93f79ec92ae310a804e87f01f..46435cd4eba11b66acaa42c01da5c80ad88aee4b 2025-04-07 14:21:21 UTC to 2025-03-25 20:13:17 UTC - Update book.toml fix the authors field (rust-lang/reference#1780) - Update precedence table for borrow operators (rust-lang/reference#1776) - Add the ability for rules to be specified in link definitions (rust-lang/reference#1775) - Rework trait parameter patterns (rust-lang/reference#1771) - Fix header rules (rust-lang/reference#1770) - Add test wrappers (rust-lang/reference#1774) - Update tools to Rust 2024 (rust-lang/reference#1773) - Define byte (rust-lang/reference#1772) - Fix CSS for new footnote style (rust-lang/reference#1777) - do not reference LLVM in our definition of UB (rust-lang/reference#1750) - Tweak reference for precise capturing in traits (rust-lang/reference#1769) - Add edition admonitions (rust-lang/reference#1764) ## rust-lang/rust-by-example 2 commits in 6f69823c28ae8d929d6c815181c73d3e99ef16d3..0d7964d5b22cf920237ef1282d869564b4883b88 2025-04-07 11:19:31 UTC to 2025-03-29 02:25:52 UTC - Rename count to index for clarity (rust-lang/rust-by-example#1920) - Fixing grammar in panic section (rust-lang/rust-by-example#1916)
Update books ## rust-lang/reference 12 commits in e95ebdfee02514d93f79ec92ae310a804e87f01f..46435cd4eba11b66acaa42c01da5c80ad88aee4b 2025-04-07 14:21:21 UTC to 2025-03-25 20:13:17 UTC - Update book.toml fix the authors field (rust-lang/reference#1780) - Update precedence table for borrow operators (rust-lang/reference#1776) - Add the ability for rules to be specified in link definitions (rust-lang/reference#1775) - Rework trait parameter patterns (rust-lang/reference#1771) - Fix header rules (rust-lang/reference#1770) - Add test wrappers (rust-lang/reference#1774) - Update tools to Rust 2024 (rust-lang/reference#1773) - Define byte (rust-lang/reference#1772) - Fix CSS for new footnote style (rust-lang/reference#1777) - do not reference LLVM in our definition of UB (rust-lang/reference#1750) - Tweak reference for precise capturing in traits (rust-lang/reference#1769) - Add edition admonitions (rust-lang/reference#1764) ## rust-lang/rust-by-example 2 commits in 6f69823c28ae8d929d6c815181c73d3e99ef16d3..0d7964d5b22cf920237ef1282d869564b4883b88 2025-04-07 11:19:31 UTC to 2025-03-29 02:25:52 UTC - Rename count to index for clarity (rust-lang/rust-by-example#1920) - Fixing grammar in panic section (rust-lang/rust-by-example#1916)
Rollup merge of rust-lang#139491 - rustbot:docs-update, r=ehuss Update books ## rust-lang/reference 12 commits in e95ebdfee02514d93f79ec92ae310a804e87f01f..46435cd4eba11b66acaa42c01da5c80ad88aee4b 2025-04-07 14:21:21 UTC to 2025-03-25 20:13:17 UTC - Update book.toml fix the authors field (rust-lang/reference#1780) - Update precedence table for borrow operators (rust-lang/reference#1776) - Add the ability for rules to be specified in link definitions (rust-lang/reference#1775) - Rework trait parameter patterns (rust-lang/reference#1771) - Fix header rules (rust-lang/reference#1770) - Add test wrappers (rust-lang/reference#1774) - Update tools to Rust 2024 (rust-lang/reference#1773) - Define byte (rust-lang/reference#1772) - Fix CSS for new footnote style (rust-lang/reference#1777) - do not reference LLVM in our definition of UB (rust-lang/reference#1750) - Tweak reference for precise capturing in traits (rust-lang/reference#1769) - Add edition admonitions (rust-lang/reference#1764) ## rust-lang/rust-by-example 2 commits in 6f69823c28ae8d929d6c815181c73d3e99ef16d3..0d7964d5b22cf920237ef1282d869564b4883b88 2025-04-07 11:19:31 UTC to 2025-03-29 02:25:52 UTC - Rename count to index for clarity (rust-lang/rust-by-example#1920) - Fixing grammar in panic section (rust-lang/rust-by-example#1916)
This adds the ability to link to rules from a link definition. For example:
This will convert
[this rule]
to point to the link of the file for that rule.This is somewhat hacky, as parsing markdown with regex is unwise (and this is intentionally incomplete), and could maybe be done more efficiently.
I don't have an immediate need for this, but I have wanted this a few times in the past.