Skip to content

Commit 2cac9d0

Browse files
authored
Merge pull request #297 from kornelski/anchorize
Simplify anchorize()
2 parents 3aa4c74 + 73ae43a commit 2cac9d0

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/html.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,19 @@ impl Anchorizer {
105105
static REJECTED_CHARS: Lazy<Regex> =
106106
Lazy::new(|| Regex::new(r"[^\p{L}\p{M}\p{N}\p{Pc} -]").unwrap());
107107

108-
let mut id = header;
109-
id = id.to_lowercase();
110-
id = REJECTED_CHARS.replace_all(&id, "").to_string();
111-
id = id.replace(' ', "-");
108+
let mut id = header.to_lowercase();
109+
id = REJECTED_CHARS.replace_all(&id, "").replace(' ', "-");
112110

113111
let mut uniq = 0;
114112
id = loop {
115113
let anchor = if uniq == 0 {
116-
Cow::from(&*id)
114+
Cow::from(&id)
117115
} else {
118-
Cow::from(format!("{}-{}", &id, uniq))
116+
Cow::from(format!("{}-{}", id, uniq))
119117
};
120118

121119
if !self.0.contains(&*anchor) {
122-
break anchor.to_string();
120+
break anchor.into_owned();
123121
}
124122

125123
uniq += 1;

0 commit comments

Comments
 (0)