diff options
-rw-r--r-- | src/Text/Pandoc.hs | 9 | ||||
-rw-r--r-- | src/Text/Pandoc/Options.hs | 5 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/EPUB.hs | 16 |
3 files changed, 14 insertions, 16 deletions
diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs index ca4a1e02b..91fbe0893 100644 --- a/src/Text/Pandoc.hs +++ b/src/Text/Pandoc.hs @@ -92,8 +92,7 @@ module Text.Pandoc , writeRTF , writeODT , writeDocx - , writeEPUB2 - , writeEPUB3 + , writeEPUB , writeFB2 , writeOrg , writeAsciiDoc @@ -207,8 +206,10 @@ writers = [ ,("json" , PureStringWriter $ \_ -> encodeJSON) ,("docx" , IOByteStringWriter writeDocx) ,("odt" , IOByteStringWriter writeODT) - ,("epub" , IOByteStringWriter writeEPUB2) - ,("epub3" , IOByteStringWriter writeEPUB3) + ,("epub" , IOByteStringWriter $ \o -> + writeEPUB o{ writerEpubVersion = Just EPUB2 }) + ,("epub3" , IOByteStringWriter $ \o -> + writeEPUB o{ writerEpubVersion = Just EPUB3 }) ,("fb2" , IOStringWriter writeFB2) ,("html" , PureStringWriter writeHtmlString) ,("html5" , PureStringWriter $ \o -> diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs index d0801da3f..f4ab0d2b4 100644 --- a/src/Text/Pandoc/Options.hs +++ b/src/Text/Pandoc/Options.hs @@ -36,6 +36,7 @@ module Text.Pandoc.Options ( Extension(..) , CiteMethod (..) , ObfuscationMethod (..) , HTMLSlideVariant (..) + , EPUBVersion (..) , WriterOptions (..) , def , isEnabled @@ -173,6 +174,8 @@ instance Default ReaderOptions -- Writer options -- +data EPUBVersion = EPUB2 | EPUB3 deriving (Eq, Show, Read) + data HTMLMathMethod = PlainMath | LaTeXMathML (Maybe String) -- url of LaTeXMathML.js | JsMath (Maybe String) -- url of jsMath load script @@ -234,6 +237,7 @@ data WriterOptions = WriterOptions , writerHighlightStyle :: Style -- ^ Style to use for highlighting , writerSetextHeaders :: Bool -- ^ Use setext headers for levels 1-2 in markdown , writerTeXLigatures :: Bool -- ^ Use tex ligatures quotes, dashes in latex + , writerEpubVersion :: Maybe EPUBVersion -- ^ Nothing or EPUB version , writerEpubMetadata :: String -- ^ Metadata to include in EPUB , writerEpubStylesheet :: Maybe String -- ^ EPUB stylesheet specified at command line , writerEpubFonts :: [FilePath] -- ^ Paths to fonts to embed @@ -274,6 +278,7 @@ instance Default WriterOptions where , writerHighlightStyle = pygments , writerSetextHeaders = True , writerTeXLigatures = True + , writerEpubVersion = Nothing , writerEpubMetadata = "" , writerEpubStylesheet = Nothing , writerEpubFonts = [] diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index fc4df02b7..b8a4bf1c6 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Conversion of 'Pandoc' documents to EPUB. -} -module Text.Pandoc.Writers.EPUB ( writeEPUB2, writeEPUB3 ) where +module Text.Pandoc.Writers.EPUB ( writeEPUB ) where import Data.IORef import Data.Maybe ( fromMaybe, isNothing ) import Data.List ( isInfixOf, intercalate ) @@ -58,20 +58,12 @@ import Prelude hiding (catch) import Control.Exception (catch, SomeException) import Text.Blaze.Html.Renderer.Utf8 (renderHtml) -data EPUBVersion = EPUB2 | EPUB3 deriving Eq - -writeEPUB2, writeEPUB3 :: WriterOptions -- ^ Writer options - -> Pandoc -- ^ Document to convert - -> IO B.ByteString -writeEPUB2 = writeEPUB EPUB2 -writeEPUB3 = writeEPUB EPUB3 - -- | Produce an EPUB file from a Pandoc document. -writeEPUB :: EPUBVersion - -> WriterOptions -- ^ Writer options +writeEPUB :: WriterOptions -- ^ Writer options -> Pandoc -- ^ Document to convert -> IO B.ByteString -writeEPUB version opts doc@(Pandoc meta _) = do +writeEPUB opts doc@(Pandoc meta _) = do + let version = maybe EPUB2 id (writerEpubVersion opts) let epub3 = version == EPUB3 epochtime <- floor `fmap` getPOSIXTime let mkEntry path content = toEntry path epochtime content |