From 789196d2ed31b5a98fb98e4e5dc9778a7e28bb01 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 11 May 2025 16:00:31 +0200 Subject: trim surrounding whitespace of DOI, URL and FILE field: \#20 --- src/app.rs | 7 ++++--- src/bibiman/bibisetup.rs | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/app.rs b/src/app.rs index 24d9eed..88f37b0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -378,7 +378,7 @@ pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> { PathBuf::from(file) }; - let file = expand_home(&file); + let file = expand_home(&file).into_os_string(); // Pass filepath as argument, pipe stdout and stderr to /dev/null // to keep the TUI clean (where is it piped on Windows???) @@ -408,13 +408,14 @@ pub fn open_connected_link(cfg: &BibiConfig, link: &str) -> Result<()> { } pub fn prepare_weblink(url: &str) -> String { - if url.starts_with("10.") { + let url = if url.starts_with("10.") { "https://doi.org/".to_string() + url } else if url.starts_with("www.") { "https://".to_string() + url } else { url.to_string() - } + }; + url } /// Expand leading tilde (`~`) to `/home/user` diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs index 3f64d9c..cba1536 100644 --- a/src/bibiman/bibisetup.rs +++ b/src/bibiman/bibisetup.rs @@ -320,9 +320,9 @@ impl BibiSetup { pub fn get_weblink(citekey: &str, biblio: &Bibliography) -> Option { let bib = biblio.get(citekey).unwrap(); if bib.doi().is_ok() { - Some(bib.doi().unwrap()) + Some(bib.doi().unwrap().trim().into()) } else if bib.url().is_ok() { - Some(bib.url().unwrap()) + Some(bib.url().unwrap().trim().into()) } else { None } @@ -330,7 +330,7 @@ impl BibiSetup { pub fn get_filepath(citekey: &str, biblio: &Bibliography) -> Option { if biblio.get(citekey).unwrap().file().is_ok() { - Some(biblio.get(citekey).unwrap().file().unwrap().into()) + Some(biblio.get(citekey).unwrap().file().unwrap().trim().into()) } else { None } -- cgit v1.2.3