Skip to content

Commit

Permalink
Add a prefix to rule HTML IDs
Browse files Browse the repository at this point in the history
This adds the `r-` prefix to HTML IDs generated for rule names. This
fixes a problem where the HTML IDs may conflict with existing markdown
headers. For example, `## Crate` conflicts with `r[crate]`. This is done
with the expectation that no headers will start with just the letter
"r".
  • Loading branch information
ehuss committed Aug 28, 2024
1 parent 3e35b90 commit 6369458
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mdbook-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl Spec {
}
}
format!(
"<div class=\"rule\" id=\"{rule_id}\">\
<a class=\"rule-link\" href=\"#{rule_id}\">[{rule_id}]</a>\
"<div class=\"rule\" id=\"r-{rule_id}\">\
<a class=\"rule-link\" href=\"#r-{rule_id}\">[{rule_id}]</a>\
</div>\n"
)
})
Expand All @@ -104,7 +104,7 @@ impl Spec {
.iter()
.map(|(rule_id, (_, path))| {
let relative = pathdiff::diff_paths(path, current_path).unwrap();
format!("[{rule_id}]: {}#{rule_id}\n", relative.display())
format!("[{rule_id}]: {}#r-{rule_id}\n", relative.display())
})
.collect();
format!(
Expand Down

0 comments on commit 6369458

Please sign in to comment.