Skip to content

Commit

Permalink
Add support for more recent clippings format
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Bruchez committed Nov 13, 2016
1 parent f14a516 commit 160883e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name := "Kindle clippings to Markdown"

version := "1.0"
version := "1.1"

scalaVersion := "2.10.3"
scalaVersion := "2.12.0"
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ object KindleClippings {

for {
title :: pageOrlocation :: empty :: clippingContents :: separator :: Nil <- lines.grouped(5)
trimmedTitle = title.trim.replaceAll("\uFEFF", "")
trimmedClippingContents = clippingContents.trim
if trimmedClippingContents.nonEmpty
book = Book(title)
book = Book(trimmedTitle)
clippingsForBook = clippingsByBook.getOrElse(book, Vector[Clipping]())
pageOption = pageOrlocation match {
case Page(page) => Try(page.toInt).toOption
Expand All @@ -66,9 +67,9 @@ object KindleClippings {
KindleClippings(Map(clippingsByBook.toSeq.map(kv => kv._1 -> kv._2.toSeq): _*))
}

private val Page = """.*Page (\d+) .*""".r
private val Page = """.*[Pp]age (\d+) .*""".r

private val Location = """.*Loc. ([^ ]+) .*""".r
private val Location = """.*Loc(?:\.|ation) ([^ ]+) .*""".r

private def lines(filename: String): Try[List[String]] =
Try(Source.fromFile(filename)(scala.io.Codec.UTF8).getLines().toList)
Expand Down

0 comments on commit 160883e

Please sign in to comment.