Skip to content

Commit 79a361f

Browse files
authored
fix: should generate unique id with counter when using different syntax (#67)
1 parent f84b76d commit 79a361f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

crates/slugger/src/lib.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ impl Slugger {
5858
} else {
5959
value.to_lowercase()
6060
};
61+
62+
// Normalize the slug and use it as the base for counting
63+
result = normalize_slug(&result).to_string();
6164
let original_slug = result.clone();
6265

6366
while self.occurrences.contains_key(&result) {
@@ -68,7 +71,7 @@ impl Slugger {
6871

6972
self.occurrences.insert(result.clone(), 0);
7073

71-
normalize_slug(&result).to_string()
74+
result
7275
}
7376

7477
/**
@@ -140,4 +143,15 @@ mod tests {
140143
assert_eq!(slug("`Hello` **World**", false), "hello-world");
141144
assert_eq!(slug("export 'function'", false), "export-function");
142145
}
146+
147+
#[test]
148+
fn test_slugger_with_similar_inputs() {
149+
let mut slugger = Slugger::new();
150+
assert_eq!(slugger.slug("inline", false), "inline");
151+
assert_eq!(slugger.slug("**inline**", false), "inline-1");
152+
assert_eq!(slugger.slug("*inline*", false), "inline-2");
153+
assert_eq!(slugger.slug("Inline", false), "inline-3");
154+
assert_eq!(slugger.slug("inline", true), "inline-4");
155+
assert_eq!(slugger.slug("Inline", true), "Inline");
156+
}
143157
}

0 commit comments

Comments
 (0)