Skip to content

Commit

Permalink
fix: should generate unique id with counter when using different synt…
Browse files Browse the repository at this point in the history
…ax (#67)
  • Loading branch information
Timeless0911 authored Nov 18, 2024
1 parent f84b76d commit 79a361f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/slugger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ impl Slugger {
} else {
value.to_lowercase()
};

// Normalize the slug and use it as the base for counting
result = normalize_slug(&result).to_string();
let original_slug = result.clone();

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

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

normalize_slug(&result).to_string()
result
}

/**
Expand Down Expand Up @@ -140,4 +143,15 @@ mod tests {
assert_eq!(slug("`Hello` **World**", false), "hello-world");
assert_eq!(slug("export 'function'", false), "export-function");
}

#[test]
fn test_slugger_with_similar_inputs() {
let mut slugger = Slugger::new();
assert_eq!(slugger.slug("inline", false), "inline");
assert_eq!(slugger.slug("**inline**", false), "inline-1");
assert_eq!(slugger.slug("*inline*", false), "inline-2");
assert_eq!(slugger.slug("Inline", false), "inline-3");
assert_eq!(slugger.slug("inline", true), "inline-4");
assert_eq!(slugger.slug("Inline", true), "Inline");
}
}

0 comments on commit 79a361f

Please sign in to comment.