epub 0.0.3 → 0.0.4
raw patch · 5 files changed
+25/−16 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Codec.EBook: opsMediatype :: [Char]
+ Codec.EBook: opsMediatype :: String
- Codec.EBook.OCF: defaultMediatype :: [Char]
+ Codec.EBook.OCF: defaultMediatype :: String
- Codec.EBook.OCF: defaultMimetype :: [Char]
+ Codec.EBook.OCF: defaultMimetype :: String
Files
- epub.cabal +1/−2
- src/Codec/EBook.hs +2/−1
- src/Codec/EBook/OCF.hs +9/−6
- src/Codec/EBook/OPF.hs +5/−2
- src/xhtml2epub.hs +8/−5
epub.cabal view
@@ -1,5 +1,5 @@ Name: epub-Version: 0.0.3+Version: 0.0.4 License: BSD3 License-File: LICENSE Synopsis: EPUB E-Book construction support library@@ -31,7 +31,6 @@ xml, Cabal >= 1.5 && < 1.9 Hs-Source-Dirs: src- Extensions: CPP, PatternGuards Ghc-Options: -Wall -fno-warn-orphans Exposed-modules:
src/Codec/EBook.hs view
@@ -20,6 +20,7 @@ import qualified Data.ByteString.Lazy as B -- EPUB media type+opsMediatype :: String opsMediatype = "application/xhtml+xml" -- Serialize Book to binary EPUB Format@@ -44,7 +45,7 @@ opfFileName = "book.opf" mimeFile = mimetypeFile contFiles = bookFiles book- allFiles = mimeFile:conXMLFile:contFiles ++ opfFiles book opfFileName+ allFiles = conXMLFile:contFiles ++ opfFiles book opfFileName ++ [mimeFile] entries = map (\(n,c) -> toEntry n t c) allFiles arch = foldl (\a e -> addEntryToArchive e a) emptyArchive entries in arch
src/Codec/EBook/OCF.hs view
@@ -11,10 +11,12 @@ import Codec.EBook.Types import Text.XML.Light-import Codec.Archive.Zip import qualified Data.ByteString.Lazy as B +defaultMediatype :: String defaultMediatype = "application/oebps-package+xml"++defaultMimetype :: String defaultMimetype = "application/epub+zip" containerXMLFile' :: FilePath -> (FilePath, B.ByteString)@@ -28,8 +30,9 @@ where contTag = add_attrs contAttrs $ unode "container" rootfilesTag contAttrs = [ Attr (unqual "version") "1.0"- ,Attr (unqual "xmlns") "urn:oasis:names:tc:opendocument:xmlns:container" ] - rootfilesTag = unode "rootfiles" (rootfileTag p m)- rootfileTag p m = add_attrs (rfAttrs p m) $ unode "rootfile" ()- rfAttrs p m = [ Attr (unqual "full-path") p- ,Attr (unqual "media-type") m ] + , Attr (unqual "xmlns") "urn:oasis:names:tc:opendocument:xmlns:container" ]+ rootfilesTag = unode "rootfiles" rootfileTag+ rootfileTag = add_attrs rfAttrs $ unode "rootfile" ()+ rfAttrs = [ Attr (unqual "full-path") p+ , Attr (unqual "media-type") m+ ]
src/Codec/EBook/OPF.hs view
@@ -11,7 +11,10 @@ import Codec.EBook.Types import qualified Data.ByteString.Lazy as B +opfDefaultLang :: String opfDefaultLang = "en"++opfDefaultCreator :: String opfDefaultCreator = "Unknown" opfFiles :: Book -> FilePath -> [(FilePath, B.ByteString)] @@ -31,11 +34,11 @@ headT = unode "head" $ map (\(n,v) -> add_attrs [ Attr (unqual "name") n,Attr (unqual "content") v] $ unode "meta" ()) metaVals metaVals = [ ("dtb:uid",(bookID o)) ,("dtb:depth","1")- ,("dtb:totalPageCount","0") + ,("dtb:totalPageCount","0") ,("dtb:maxPageNumber","0") ] docTitleT = unode "docTitle" $ unode "text" (bookTitle o) docAuthorT = unode "docAuthor" $ unode "text" (bookAuthor o)- numChapterEnt = zip (chapterItems $ bookItems o) [1..]+ numChapterEnt = zip (chapterItems $ bookItems o) [(1::Int)..] navMapT = unode "navMap" (map navPointT numChapterEnt) navPointT (e,i) = add_attrs [ Attr (unqual "class") "chapter" ,Attr (unqual "id") (itemID e)
src/xhtml2epub.hs view
@@ -13,17 +13,20 @@ bookAuthor = "xhtml2epub", bookTitle = nameOfBook }- items <- mapM loadItems fileNames+ items <- mapM loadItems $ zip fileNames [1..] let bookFull = foldl' addItem2Book book items- let epubFName = nameOfBook++".epub"+ let epubFName = nameOfBook <.> "epub" outdata <- book2Bin' bookFull B.writeFile epubFName outdata putStrLn $ epubFName ++ " constructed." _ -> error "Usage: xhtml2epub <name of book> <xhtml file1> [<xhtml file2>,...]" -loadItems :: FilePath -> IO BookItem-loadItems p = do+-- | Constructs a book item from a given filename and item index. The+-- index is used to generate a unique item identifier.+loadItems :: (FilePath,Int) -> IO BookItem+loadItems (p,i) = do c <- B.readFile p- return (BookItem ("http://localhost/"++np) np c opsMediatype (Just (ChapterMetadata np))) + return (BookItem iid np c opsMediatype (Just (ChapterMetadata np))) where np = normalise p+ iid = takeBaseName p ++ "-" ++ show i