diff options
author | James Campos <james.r.campos@gmail.com> | 2020-05-17 02:04:25 -0700 |
---|---|---|
committer | James Campos <james.r.campos@gmail.com> | 2020-05-17 02:04:25 -0700 |
commit | 6100ffbfab86081fa1e9e033717c54b0edc99d08 (patch) | |
tree | eb8d47e8d934f5fb575386377e9af0a552d6fc67 | |
parent | d7ce4bdadb10ea4e70f8e48e2ddb990cf3087c49 (diff) | |
download | bk-6100ffbfab86081fa1e9e033717c54b0edc99d08.tar.gz |
readme, fmt
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | src/epub.rs | 35 |
2 files changed, 25 insertions, 19 deletions
@@ -1,5 +1,7 @@ # bk -bk is a terminal Epub reader. Currently only Linux is tested, but macOS and Windows support is planned. +bk is a WIP terminal Epub reader, written in Rust. + +bk supports Linux and macOS. Windows runs but doesn't save position on exit. # Usage @@ -17,14 +19,15 @@ Running `bk` without an argument will load the most recent Epub. - Vim bindings # TODO -- macOS, Windows +- fix Windows - configuration - links - better unicode support - better html rendering - mobi? +- images? - css? - gui? -# inspiration +# Inspiration <https://github.com/wustho/epr> diff --git a/src/epub.rs b/src/epub.rs index fa5f33f..48263c2 100644 --- a/src/epub.rs +++ b/src/epub.rs @@ -18,21 +18,24 @@ impl Epub { nav: Vec::new(), chapters: Vec::new(), }; - let (nav, chapters) = epub.get_nav().into_iter().filter_map(|(path, label)| { - let xml = epub.get_text(&path); - // https://github.com/RazrFalcon/roxmltree/issues/12 - // UnknownEntityReference for HTML entities - let doc = Document::parse(&xml).unwrap(); - let body = doc.root_element().last_element_child().unwrap(); - let mut chapter = String::new(); - Epub::render(&mut chapter, body); - if chapter.is_empty() { - None - } else { - Some((label, chapter)) - } - }) - .unzip(); + let (nav, chapters) = epub + .get_nav() + .into_iter() + .filter_map(|(path, label)| { + let xml = epub.get_text(&path); + // https://github.com/RazrFalcon/roxmltree/issues/12 + // UnknownEntityReference for HTML entities + let doc = Document::parse(&xml).unwrap(); + let body = doc.root_element().last_element_child().unwrap(); + let mut chapter = String::new(); + Epub::render(&mut chapter, body); + if chapter.is_empty() { + None + } else { + Some((label, chapter)) + } + }) + .unzip(); epub.nav = nav; epub.chapters = chapters; Ok(epub) @@ -99,7 +102,7 @@ impl Epub { let doc = Document::parse(&xml).unwrap(); // zip expects unix path even on windows let rootdir = match path.rfind('/') { - Some(n) => &path[..n+1], + Some(n) => &path[..n + 1], None => "", }; |