Library for parsing epub document metadata (Haskell)

root / src / Codec / Epub.hs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- License: BSD3 (see LICENSE)
-- Author: Dino Morelli <dino@ui3.info>

{- |
   This is a library for parsing and manipulating epub document metadata. Almost all of the data stored in the epub Package Document can be worked with using this API. This includes the most useful block of data, the epub metadata. This library supports epub versions 2 and 3.

   This library was constructed by studying the IDPF specifications for epub documents found here <http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm> and here <http://www.idpf.org/epub/30/spec/epub30-publications.html>

   Consumers of epub-metadata will likely need this module, which re-exports the most useful parts concerning disk IO, parsing of the XML into Codec.Epub.Data.* data structures and formatting these data structures to be pretty-printed. Please also see Codec.Epub.Data.Metadata etc.
-}
module Codec.Epub (
   -- * Epub
   module Codec.Epub.Format,
   module Codec.Epub.IO,
   module Codec.Epub.Parse

   -- * Example
   -- $example1
   )
   where

import Codec.Epub.Format
import Codec.Epub.IO
import Codec.Epub.Parse


{- $example1
>  import Codec.Epub
>  import Codec.Epub.Data.Package
>  import Control.Monad.Error
>  
>  
>  main :: IO ()
>  main = do
>     -- epub-metadata actions are in MonadIO and MonadError, so we're
>     -- using ErrorT here
>  
>     result <- runErrorT $ do
>  
>        -- Use the getPkgXmlFromZip action to extract the Package
>        -- Document as an XML string. There are also other actions
>        -- for reading from ByteStringS and directories.
>        --
>        -- See Codec.Epub.IO
>  
>        xmlString <- getPkgXmlFromZip "/path/to/book.epub"
>  
>        -- Now the sections of meta-information about the book can
>        -- be extracted from that XML using functions like getPackage,
>        -- getMetadata, etc.
>        --
>        -- See Codec.Epub.Parse
>  
>        pkg <- getPackage xmlString  -- :: Codec.Epub.Data.Package
>        meta <- getMetadata xmlString  -- :: Codec.Epub.Data.Metadata
>  
>        -- Parts of these data structures can be used from here
>        -- as needed
>        --
>        -- See Codec.Epub.Data.Package for pkgVersion below
>        -- and the others in Codec.Epub.Data.*
>  
>        liftIO $ putStrLn $ pkgVersion pkg
>  
>        -- There is also pretty-print formatting of these data types
>        -- in Codec.Epub.Data through the Formattable typeclass
>        --
>        -- See Codec.Epub.Format
>  
>        liftIO $ putStr $ format meta
>  
>     either putStrLn return result
-}