@@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29Conversion of 'Pandoc' documents to EPUB.
29Conversion of 'Pandoc' documents to EPUB.
31module Text.Pandoc.Writers.EPUB ( writeEPUB ) where
31module Text.Pandoc.Writers.EPUB ( writeEPUB ) where
32−import Data.IORef
32+import Data.IORef ( IORef, newIORef, readIORef, modifyIORef )
33import qualified Data.Map as M
33import qualified Data.Map as M
34import Data.Maybe ( fromMaybe )
34import Data.Maybe ( fromMaybe )
35import Data.List ( isPrefixOf, isInfixOf, intercalate )
35import Data.List ( isPrefixOf, isInfixOf, intercalate )
@@ -40,27 +40,35 @@ import qualified Data.ByteString.Lazy as B
40import qualified Data.ByteString.Lazy.Char8 as B8
40import qualified Data.ByteString.Lazy.Char8 as B8
41import qualified Text.Pandoc.UTF8 as UTF8
41import qualified Text.Pandoc.UTF8 as UTF8
42import Text.Pandoc.SelfContained ( makeSelfContained )
42import Text.Pandoc.SelfContained ( makeSelfContained )
43−import Codec.Archive.Zip
43+import Codec.Archive.Zip ( emptyArchive, addEntryToArchive, eRelativePath, fromEntry , Entry, toEntry, fromArchive)
44import Control.Applicative ((<$>))
44import Control.Applicative ((<$>))
45−import Data.Time.Clock.POSIX
45+import Data.Time.Clock.POSIX ( getPOSIXTime )
46−import Data.Time
46+import Data.Time (getCurrentTime,UTCTime, formatTime)
47−import System.Locale
47+import System.Locale ( defaultTimeLocale )
48−import Text.Pandoc.Shared hiding ( Element )
48+import Text.Pandoc.Shared ( trimr, renderTags', safeRead, uniqueIdent, trim
49+ , normalizeDate, readDataFile, stringify, warn
50+ , hierarchicalize, fetchItem' )
49−import qualified Text.Pandoc.Shared as Shared
51+import qualified Text.Pandoc.Shared as S (Element(..))
50import Text.Pandoc.Builder (fromList, setMeta)
52import Text.Pandoc.Builder (fromList, setMeta)
51−import Text.Pandoc.Options
53+import Text.Pandoc.Options ( WriterOptions(..)
56+ , ObfuscationMethod(NoObfuscation) )
52import Text.Pandoc.Definition
57import Text.Pandoc.Definition
53−import Text.Pandoc.Walk
58+import Text.Pandoc.Walk (walk, walkM)
54−import Control.Monad.State
59+import Control.Monad.State (modify, get, execState, State, put, evalState)
60+import Control.Monad (foldM, when, mplus, liftM)
55−import Text.XML.Light hiding (ppTopElement)
61+import Text.XML.Light ( unode, Element(..), unqual, Attr(..), add_attrs
62+ , strContent, lookupAttr, Node(..), QName(..), parseXML
63+ , onlyElems, node, ppElement)
56−import Text.Pandoc.UUID
64+import Text.Pandoc.UUID (getRandomUUID)
57−import Text.Pandoc.Writers.HTML
65+import Text.Pandoc.Writers.HTML (writeHtmlString, writeHtml)
58import Data.Char ( toLower, isDigit, isAlphaNum )
66import Data.Char ( toLower, isDigit, isAlphaNum )
59import Network.URI ( unEscapeString )
67import Network.URI ( unEscapeString )
60import Text.Pandoc.MIME (getMimeType)
68import Text.Pandoc.MIME (getMimeType)
61import qualified Control.Exception as E
69import qualified Control.Exception as E
62import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
70import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
63−import Text.HTML.TagSoup
71+import Text.HTML.TagSoup (Tag(TagOpen), fromAttrib, parseTags)
65-- A Chapter includes a list of blocks and maybe a section
73-- A Chapter includes a list of blocks and maybe a section
66-- number offset. Note, some chapters are unnumbered. The section
74-- number offset. Note, some chapters are unnumbered. The section
@@ -524,8 +532,8 @@ writeEPUB opts doc@(Pandoc meta _) = do
524 let tocLevel = writerTOCDepth opts
532 let tocLevel = writerTOCDepth opts
526 let navPointNode :: (Int -> String -> String -> [Element] -> Element)
534 let navPointNode :: (Int -> String -> String -> [Element] -> Element)
527− -> Shared.Element -> State Int Element
535+ -> S.Element -> State Int Element
528− navPointNode formatter (Sec _ nums (ident,_,_) ils children) = do
536+ navPointNode formatter (S.Sec _ nums (ident,_,_) ils children) = do
530 modify (+1)
538 modify (+1)
531 let showNums :: [Int] -> String
539 let showNums :: [Int] -> String
@@ -537,12 +545,12 @@ writeEPUB opts doc@(Pandoc meta _) = do
537 let src = case lookup ident reftable of
545 let src = case lookup ident reftable of
538 Just x -> x
546 Just x -> x
539 Nothing -> error (ident ++ " not found in reftable")
547 Nothing -> error (ident ++ " not found in reftable")
540− let isSec (Sec lev _ _ _ _) = lev <= tocLevel
548+ let isSec (S.Sec lev _ _ _ _) = lev <= tocLevel
541 isSec _ = False
549 isSec _ = False
542 let subsecs = filter isSec children
550 let subsecs = filter isSec children
543 subs <- mapM (navPointNode formatter) subsecs
551 subs <- mapM (navPointNode formatter) subsecs
544 return $ formatter n tit src subs
552 return $ formatter n tit src subs
545− navPointNode _ (Blk _) = error "navPointNode encountered Blk"
553+ navPointNode _ (S.Blk _) = error "navPointNode encountered Blk"
547 let navMapFormatter :: Int -> String -> String -> [Element] -> Element
555 let navMapFormatter :: Int -> String -> String -> [Element] -> Element
548 navMapFormatter n tit src subs = unode "navPoint" !
556 navMapFormatter n tit src subs = unode "navPoint" !