Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ pub enum CacheMode {
Html,
#[default]
Text,
Markdown,
}

impl fmt::Display for CacheMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let cache_mode = match &self {
CacheMode::Html => "html",
CacheMode::Text => "text",
CacheMode::Markdown => "markdown",
};
write!(f, "{}", cache_mode)
}
Expand All @@ -47,13 +49,15 @@ impl CacheMode {
match self {
Self::Html => "html",
Self::Text => "txt",
Self::Markdown => "md",
}
}

pub fn suffix(&self) -> &str {
match self {
Self::Html => ".html",
Self::Text => ".txt",
Self::Markdown => ".md",
}
}
}
Expand Down Expand Up @@ -176,6 +180,7 @@ impl Caching for Cache {
let content = match self.mode {
CacheMode::Html => html,
CacheMode::Text => html::convert_to_text(&html, &bookmark.url)?,
CacheMode::Markdown => html::convert_to_markdown(&html),
};

if !cache_path.exists() {
Expand All @@ -199,6 +204,7 @@ impl Caching for Cache {
let content = match self.mode {
CacheMode::Html => html,
CacheMode::Text => html::convert_to_text(&html, &bookmark.url)?,
CacheMode::Markdown => html::convert_to_markdown(&html),
};

let mut cache_file = utils::create_file_async(&cache_path).await?;
Expand Down Expand Up @@ -310,6 +316,7 @@ impl Caching for MockCache {
let content = match self.mode {
CacheMode::Html => html,
CacheMode::Text => html::convert_to_text(&html, &bookmark.url)?,
CacheMode::Markdown => html::convert_to_markdown(&html),
};
cache_map.insert(bookmark.id.clone(), content.clone());
Ok(content)
Expand All @@ -324,6 +331,7 @@ impl Caching for MockCache {
let content = match self.mode {
CacheMode::Html => html,
CacheMode::Text => html::convert_to_text(&html, &bookmark.url)?,
CacheMode::Markdown => html::convert_to_markdown(&html),
};
cache_map.insert(bookmark.id.clone(), content.clone());
Ok(content)
Expand Down
8 changes: 5 additions & 3 deletions src/cmd/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ fn find_matches(reader: impl BufRead, regex: &Regex) -> Result<Vec<String>, anyh
end_index = line.len();
}

let truncated_line = &line[start_index..end_index];

matched_lines.push(truncated_line.to_owned());
if let Some(truncated_line) = line.get(start_index..end_index) {
matched_lines.push(truncated_line.to_owned());
} else {
matched_lines.push(line.to_owned());
}
}
}

Expand Down