Skip to content

Commit

Permalink
Moved to convert_case crate for kebab case conversions.
Browse files Browse the repository at this point in the history
  • Loading branch information
HU90m committed Jul 12, 2023
1 parent b03dcf4 commit 508f26e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lychee-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ version = "0.13.0"
async-stream = "0.3.5"
cached = "0.44.0"
check-if-email-exists = { version = "0.9.0", optional = true }
convert_case = "0.6.0"
email_address = "0.2.4"
futures = "0.3.27"
glob = "0.3.1"
Expand Down
19 changes: 2 additions & 17 deletions lychee-lib/src/extract/markdown.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Extract things from markdown documents
use std::collections::{HashMap, HashSet};

use convert_case::{Case, Casing};
use pulldown_cmark::{Event, Parser, Tag};

use crate::{extract::plaintext::extract_plaintext, types::uri::raw::RawUri};
Expand Down Expand Up @@ -98,7 +99,7 @@ pub(crate) fn extract_markdown_fragments(input: &str) -> HashSet<String> {
out.insert(frag.to_string());
}

let mut id = into_kebab_case(&heading);
let mut id = heading.to_case(Case::Kebab);

let k_id_count = kebab_id_counter.entry(id.clone()).or_insert(0);
if *k_id_count != 0 {
Expand All @@ -123,22 +124,6 @@ pub(crate) fn extract_markdown_fragments(input: &str) -> HashSet<String> {
out
}

/// Converts text into kebab case
#[must_use]
pub fn into_kebab_case(text: &str) -> String {
text.chars()
.filter_map(|ch| {
if ch.is_alphanumeric() || ch == '_' || ch == '-' {
Some(ch.to_ascii_lowercase())
} else if ch.is_whitespace() {
Some('-')
} else {
None
}
})
.collect::<String>()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 508f26e

Please sign in to comment.