From de488516053f578d3ab2919e614de88cc45e443e Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 4 Feb 2017 22:56:23 +0100 Subject: More simplification of Opt in pandoc.hs. We defer file reading til after option parsing. --- pandoc.hs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'pandoc.hs') diff --git a/pandoc.hs b/pandoc.hs index 0dbafc9fd..715e0b888 100644 --- a/pandoc.hs +++ b/pandoc.hs @@ -137,8 +137,8 @@ convertWithOpts opts args = do , optTopLevelDivision = topLevelDivision , optHTMLMathMethod = mathMethod' , optReferenceDoc = referenceDoc - , optEpubStylesheet = epubStylesheet - , optEpubMetadata = epubMetadata + , optEpubStylesheet = mbEpubStylesheet + , optEpubMetadata = mbEpubMetadata , optEpubFonts = epubFonts , optEpubChapterLevel = epubChapterLevel , optTOCDepth = epubTOCDepth @@ -176,6 +176,14 @@ convertWithOpts opts args = do mapM_ (UTF8.hPutStrLn stdout) args exitSuccess + epubStylesheet <- case mbEpubStylesheet of + Nothing -> return Nothing + Just fp -> Just <$> UTF8.readFile fp + + epubMetadata <- case mbEpubMetadata of + Nothing -> return Nothing + Just fp -> Just <$> UTF8.readFile fp + let csscdn = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.css" let mathMethod = case (katexJS, katexStylesheet) of @@ -547,8 +555,8 @@ data Opt = Opt , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math , optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc - , optEpubStylesheet :: Maybe String -- ^ EPUB stylesheet - , optEpubMetadata :: String -- ^ EPUB metadata + , optEpubStylesheet :: Maybe FilePath -- ^ EPUB stylesheet + , optEpubMetadata :: Maybe FilePath -- ^ EPUB metadata , optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed , optEpubChapterLevel :: Int -- ^ Header level at which to split chapters , optTOCDepth :: Int -- ^ Number of levels to include in TOC @@ -607,7 +615,7 @@ defaultOpts = Opt , optHTMLMathMethod = PlainMath , optReferenceDoc = Nothing , optEpubStylesheet = Nothing - , optEpubMetadata = "" + , optEpubMetadata = Nothing , optEpubFonts = [] , optEpubChapterLevel = 1 , optTOCDepth = 3 @@ -1024,9 +1032,7 @@ options = , Option "" ["epub-stylesheet"] (ReqArg - (\arg opt -> do - text <- UTF8.readFile arg - return opt { optEpubStylesheet = Just text }) + (\arg opt -> return opt { optEpubStylesheet = Just arg }) "FILENAME") "" -- "Path of epub.css" @@ -1040,9 +1046,7 @@ options = , Option "" ["epub-metadata"] (ReqArg - (\arg opt -> do - text <- UTF8.readFile arg - return opt { optEpubMetadata = text }) + (\arg opt -> return opt { optEpubMetadata = Just arg }) "FILENAME") "" -- "Path of epub metadata file" -- cgit v1.2.3