Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
Ran cargo check, and tidied up whatever was an issue. Mainly changing
double for single quotes, and defining a type to clear up a long type.
  • Loading branch information
ChrisDavison committed Jul 14, 2024
1 parent e498d04 commit eec15f9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/my_clippings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::note::*;
use anyhow::{anyhow, Result};
use std::collections::HashMap;

pub fn parse(data: &str) -> Result<(HashMap<String, Vec<Highlight>>, Vec<String>)> {

pub fn parse(data: &str) -> Result<(BookNotes, Vec<String>)> {
let mut output: HashMap<String, Vec<Highlight>> = HashMap::new();
let mut titles_last_seen_indice: HashMap<String, usize> = HashMap::new();
for (i, note) in data.split("==========\r\n").enumerate() {
Expand All @@ -14,13 +15,13 @@ pub fn parse(data: &str) -> Result<(HashMap<String, Vec<Highlight>>, Vec<String>
titles_last_seen_indice.insert(highlight.name.to_string(), to_insert);
let entry = output
.entry(highlight.name.to_string())
.or_insert_with(Vec::new);
.or_default();
entry.push(highlight);
}
}
let mut ordered_titles: Vec<(usize, String)> = titles_last_seen_indice
.iter()
.map(|(k, v)| (v.clone(), k.clone()))
.map(|(k, v)| (*v, k.clone()))
.collect();
ordered_titles.sort();
let only_ordered_titles: Vec<String> = ordered_titles.iter().map(|(_, k)| k.clone()).collect();
Expand Down
6 changes: 4 additions & 2 deletions src/note.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub type BookNotes<'a> = std::collections::HashMap<String, Vec<Highlight<'a>>>;

#[derive(Debug)]
pub struct Highlight<'a> {
pub name: &'a str,
Expand All @@ -19,13 +21,13 @@ impl<'a> std::fmt::Display for Highlight<'a> {
HighlightType::Highlight => "",
HighlightType::Comment => "NOTE: ",
};
write!(f, "{}{}", prefix, self.highlight.replace("\r", ""))
write!(f, "{}{}", prefix, self.highlight.replace('\r', ""))
}
}

impl<'a> Highlight<'a> {
pub fn filestem(&self) -> String {
let bad_chars = vec!['(', ')', ',', ':'];
let bad_chars = ['(', ')', ',', ':'];
let letter_tidier = |letter| {
if bad_chars.contains(&letter) {
"".to_string()
Expand Down
6 changes: 3 additions & 3 deletions src/web_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ fn get_h3_title(data: &str) -> Result<&str> {
Ok(title)
}

pub fn parse(data: &str) -> Result<(HashMap<String, Vec<Highlight>>, Vec<String>)> {
pub fn parse(data: &str) -> Result<(BookNotes, Vec<String>)> {
let title = get_h3_title(data)?;
let re_hi_or_note = Regex::new(r#"(?s)<span.*?id="(highlight|note)".*?>(.*?)</span>"#)
.with_context(|| "Failed to create regex for webexport highlight/note")?;
let mut output: HashMap<String, Vec<Highlight>> = HashMap::new();
for cap in re_hi_or_note.captures_iter(data) {
let entry = output.entry(title.to_string()).or_insert_with(Vec::new);
let tidy_entry = cap[2].replace("\r", "").replace("\n", "");
let entry = output.entry(title.to_string()).or_default();
let tidy_entry = cap[2].replace(['\r', '\n'], " ");
if !tidy_entry.is_empty() {
let highlight_type = match &cap[1] {
"highlight" => HighlightType::Highlight,
Expand Down

0 comments on commit eec15f9

Please sign in to comment.