Skip to content

Commit d0bde46

Browse files
committed
Lowercase heading IDs
This switches from ASCII lowercase to Unicode lowercase when generating heading IDs. This brings mdbook more in line with other tools and sites when they generate heading IDs. The generation still isn't 100% the same as other tools and sites, but it is usually the same in most cases. Closes #1059
1 parent 475951c commit d0bde46

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ The following is a summary of the changes that may require your attention when u
5858
[#2847](https://github.com/rust-lang/mdBook/pull/2847)
5959
- Added support for admonitions. These are enabled by default, with the option `output.html.admonitions` to disable it.
6060
[#2851](https://github.com/rust-lang/mdBook/pull/2851)
61-
- Headers that start or end with HTML characters like `<`, `&`, or `>` now replace those characters in the link ID with `-` instead of being stripped. This brings the header ID generation closer to other tools and sites.
62-
[#2844](https://github.com/rust-lang/mdBook/pull/2844)
61+
- Header ID generation has some minor changes to bring the ID generation closer to other tools and sites:
62+
- IDs now use Unicode lowercase instead of ASCII lowercase.
63+
[#2922](https://github.com/rust-lang/mdBook/pull/2922)
64+
- Headers that start or end with HTML characters like `<`, `&`, or `>` now replace those characters in the link ID with `-` instead of being stripped.
65+
[#2844](https://github.com/rust-lang/mdBook/pull/2844)
6366

6467
### CLI changes
6568

crates/mdbook-html/src/utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ pub(crate) fn unique_id(id: &str, used: &mut HashSet<String>) -> String {
7676
pub(crate) fn id_from_content(content: &str) -> String {
7777
content
7878
.trim()
79+
.to_lowercase()
7980
.chars()
8081
.filter_map(|ch| {
8182
if ch.is_alphanumeric() || ch == '_' || ch == '-' {
82-
Some(ch.to_ascii_lowercase())
83+
Some(ch)
8384
} else if ch.is_whitespace() {
8485
Some('-')
8586
} else {
@@ -120,6 +121,6 @@ mod tests {
120121
assert_eq!(id_from_content("한국어"), "한국어");
121122
assert_eq!(id_from_content(""), "");
122123
assert_eq!(id_from_content("中文標題 CJK title"), "中文標題-cjk-title");
123-
assert_eq!(id_from_content("Über"), "Über");
124+
assert_eq!(id_from_content("Über"), "über");
124125
}
125126
}

0 commit comments

Comments
 (0)