epub-metadata 4.0 → 4.1
raw patch · 5 files changed
+44/−27 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Codec.Epub.Util: removeDoctype :: String -> String
+ Codec.Epub.Util: removeEncoding :: String -> String
+ Codec.Epub.Util: removeIllegalStartChars :: String -> String
Files
- epub-metadata.cabal +5/−4
- src/Codec/Epub/Data/Metadata.hs +1/−1
- src/Codec/Epub/IO.hs +6/−1
- src/Codec/Epub/Parse.hs +1/−21
- src/Codec/Epub/Util.hs +31/−0
epub-metadata.cabal view
@@ -1,5 +1,5 @@ name: epub-metadata-version: 4.0+version: 4.1 cabal-version: >= 1.8 build-type: Simple license: BSD3@@ -9,7 +9,7 @@ maintainer: Dino Morelli <dino@ui3.info> stability: experimental homepage: http://ui3.info/d/proj/epub-metadata.html-synopsis: Library for parsing epub document metdata+synopsis: Library for parsing epub document metadata description: Library for parsing and manipulating epub document metadata. 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>@@ -55,6 +55,7 @@ Codec.Epub.Parse.Refinements Codec.Epub.Parse.Spine Codec.Epub.Parse.Util+ Codec.Epub.Util build-depends: base >= 3 && < 5, bytestring, containers,@@ -65,7 +66,7 @@ regex-compat, zip-archive hs-source-dirs: src- ghc-options: -Wall+ ghc-options: -Wall -fsimpl-tick-factor=200 test-suite test-epub-metadata type: exitcode-stdio-1.0@@ -80,4 +81,4 @@ regex-compat, zip-archive hs-source-dirs: src testsuite- ghc-options: -Wall+ ghc-options: -Wall -fsimpl-tick-factor=200
src/Codec/Epub/Data/Metadata.hs view
@@ -31,7 +31,7 @@ {- | Refinements represent meta tags within the metadata section that refine other tags. These are used during the parsing phase and are discarded as their information is slotted into the data- they refine (the types below like Creator, Title, etc..)+ they refine (CreatorS, TitleS, IdentifierS, etc..) This is specific to epub3 -}
src/Codec/Epub/IO.hs view
@@ -32,7 +32,9 @@ import Text.XML.HXT.Arrow.XmlArrow ( getAttrValue, hasName, isElem ) import Text.XML.HXT.Arrow.XmlState ( no, runX, withValidate ) +import Codec.Epub.Util + locateRootFile :: (MonadIO m, MonadError String m) => FilePath -> String -> m FilePath locateRootFile containerPath' containerDoc = do@@ -84,7 +86,10 @@ -} containerDoc <- fileFromArchive containerPath archive - rootPath <- locateRootFile containerPath containerDoc+ let cleanedContents = removeIllegalStartChars . removeEncoding+ . removeDoctype $ containerDoc++ rootPath <- locateRootFile containerPath cleanedContents -- Now that we have the path to the .opf file, extract it rootContents <- fileFromArchive rootPath archive
src/Codec/Epub/Parse.hs view
@@ -22,7 +22,6 @@ import Control.Arrow.ListArrows import Control.Monad.Error-import Text.Regex import Text.XML.HXT.Arrow.Namespace ( propagateNamespaces ) import Text.XML.HXT.Arrow.XmlState ( no, runX, withValidate ) import Text.XML.HXT.Arrow.XmlState.TypeDefs@@ -40,26 +39,7 @@ import Codec.Epub.Parse.Package import Codec.Epub.Parse.Refinements import Codec.Epub.Parse.Spine---{- An evil hack to remove *ILLEGAL* characters before the XML- declaration. Why do people write software that does this?- Can't they follow directions?--}-removeIllegalStartChars :: String -> String-removeIllegalStartChars = dropWhile (/= '<')----- An evil hack to remove encoding from the document-removeEncoding :: String -> String-removeEncoding = flip (subRegex - (mkRegexWithOpts " +encoding=\"UTF-8\"" False False)) ""----- An evil hack to remove any \<!DOCTYPE ...\> from the document-removeDoctype :: String -> String-removeDoctype = flip (subRegex - (mkRegexWithOpts "<!DOCTYPE [^>]*>" False True)) ""+import Codec.Epub.Util {- Extract the epub OPF Package data contained in the supplied
+ src/Codec/Epub/Util.hs view
@@ -0,0 +1,31 @@+-- Copyright: 2010-2013 Dino Morelli+-- License: BSD3 (see LICENSE)+-- Author: Dino Morelli <dino@ui3.info>++{- | Utility functions shared by modules that need to read the+ contents of XML documents.+-}+module Codec.Epub.Util+ where++import Text.Regex+++{- | An evil hack to remove *ILLEGAL* characters before the XML+ declaration. Why do people write software that does this?+ Can't they follow directions?+-}+removeIllegalStartChars :: String -> String+removeIllegalStartChars = dropWhile (/= '<')+++-- | An evil hack to remove encoding from the document+removeEncoding :: String -> String+removeEncoding = flip (subRegex + (mkRegexWithOpts " +encoding=\"UTF-8\"" False False)) ""+++-- | An evil hack to remove any \<!DOCTYPE ...\> from the document+removeDoctype :: String -> String+removeDoctype = flip (subRegex + (mkRegexWithOpts "<!DOCTYPE [^>]*>" False True)) ""