Skip to content

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

Merged
merged 2 commits into from
Apr 1, 2025

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Mar 30, 2025

This adds the ability to link to rules from a link definition. For example:

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.

I don't have an immediate need for this, but I have wanted this a few times in the past.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Mar 30, 2025
Comment on lines 136 to 144
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();
}
Copy link
Contributor

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.

Copy link
Contributor

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.

Comment on lines +133 to +134
MD_LINK_REFERENCE_DEFINITION
.replace_all(&chapter.content, |caps: &Captures<'_>| {
Copy link
Contributor

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.

Comment on lines +123 to +128
/// For example:
/// ```markdown
/// See [this rule].
///
/// [this rule]: expr.array
/// ```
Copy link
Contributor

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.

ehuss and others added 2 commits April 1, 2025 22:31
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.
@traviscross traviscross added this pull request to the merge queue Apr 1, 2025
Merged via the queue into rust-lang:master with commit e665505 Apr 1, 2025
5 checks passed
Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 8, 2025
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)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 8, 2025
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)
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 9, 2025
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)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-review Status: The marked PR is awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants