git.iko.soy/typeable/pandoc
on master help sign in
Expose getDefaultDataFile in both Shared and Class.
commit6aaf8f4770916fcef433d0078502d674a1c97fc7 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 10 Aug 2017, 23:04 (9 years ago) parented4f6b3
4 files changed+18−7
src/Text/Pandoc/App.hs+3−3 src/Text/Pandoc/Class.hs+13−3 src/Text/Pandoc/Shared.hs+1 src/Text/Pandoc/Writers/Docx.hs+1−1
src/Text/Pandoc/App.hs+3−3
@@ -84,8 +84,8 @@ import Text.Pandoc.PDF (makePDF)
8484import Text.Pandoc.Process (pipeProcess)
8585import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
8686import Text.Pandoc.Shared (headerShift, isURI, openURL, readDataFile,
87− readDataFileUTF8, safeRead, tabFilter,
88− eastAsianLineBreakFilter)
87+ readDataFileUTF8, readDefaultDataFile,
88+ safeRead, tabFilter, eastAsianLineBreakFilter)
8989import qualified Text.Pandoc.UTF8 as UTF8
9090import Text.Pandoc.XML (toEntities)
9191import Text.Printf
@@ -1007,7 +1007,7 @@ options =
10071007 , Option "" ["print-default-data-file"]
10081008 (ReqArg
10091009 (\arg _ -> do
1010− readDataFile Nothing arg >>= BS.hPutStr stdout
1010+ readDefaultDataFile arg >>= BS.hPutStr stdout
10111011 exitSuccess)
10121012 "FILE")
10131013 "" -- "Print default data file"
src/Text/Pandoc/Class.hs+13−3
@@ -80,6 +80,7 @@ import Codec.Archive.Zip (Archive, fromArchive, emptyArchive)
8080import Data.Unique (hashUnique)
8181import qualified Data.Unique as IO (newUnique)
8282import qualified Text.Pandoc.Shared as IO ( readDataFile
83+ , readDefaultDataFile
8384 , openURL )
8485import qualified Text.Pandoc.UTF8 as UTF8
8586import Text.Pandoc.Compat.Time (UTCTime)
@@ -152,6 +153,8 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m)
152153 -- | Read the strict ByteString contents from a file path,
153154 -- raising an error on failure.
154155 readFileStrict :: FilePath -> m B.ByteString
156+ -- | Read file from from Cabal data directory.
157+ readDefaultDataFile :: FilePath -> m B.ByteString
155158 -- | Read file from specified user data directory or,
156159 -- if not found there, from Cabal data directory.
157160 readDataFile :: Maybe FilePath -> FilePath -> m B.ByteString
@@ -326,6 +329,7 @@ instance PandocMonad PandocIO where
326329 Left e -> throwError $ PandocHttpError u e
327330 readFileLazy s = liftIOError BL.readFile s
328331 readFileStrict s = liftIOError B.readFile s
332+ readDefaultDataFile fname = liftIOError IO.readDefaultDataFile fname
329333 readDataFile mfp fname = liftIOError (IO.readDataFile mfp) fname
330334 glob = liftIO . IO.glob
331335 getModificationTime fp = liftIOError IO.getModificationTime fp
@@ -602,11 +606,11 @@ instance PandocMonad PandocPure where
602606 case infoFileContents <$> getFileInfo fp fps of
603607 Just bs -> return bs
604608 Nothing -> throwError $ PandocResourceNotFound fp
605− readDataFile Nothing "reference.docx" =
609+ readDefaultDataFile "reference.docx" =
606610 (B.concat . BL.toChunks . fromArchive) <$> getsPureState stReferenceDocx
607− readDataFile Nothing "reference.odt" =
611+ readDefaultDataFile "reference.odt" =
608612 (B.concat . BL.toChunks . fromArchive) <$> getsPureState stReferenceODT
609− readDataFile Nothing fname = do
613+ readDefaultDataFile fname = do
610614 let fname' = if fname == "MANUAL.txt" then fname else "data" </> fname
611615 readFileStrict fname'
612616 readDataFile (Just userDir) fname = do
@@ -614,6 +618,7 @@ instance PandocMonad PandocPure where
614618 case infoFileContents <$> getFileInfo (userDir </> fname) userDirFiles of
615619 Just bs -> return bs
616620 Nothing -> readDataFile Nothing fname
621+ readDataFile Nothing fname = readDefaultDataFile fname
617622
618623 glob s = do
619624 FileTree ftmap <- getsPureState stFiles
@@ -640,6 +645,7 @@ instance PandocMonad m => PandocMonad (ParsecT s st m) where
640645 openURL = lift . openURL
641646 readFileLazy = lift . readFileLazy
642647 readFileStrict = lift . readFileStrict
648+ readDefaultDataFile = lift . readDefaultDataFile
643649 readDataFile mbuserdir = lift . readDataFile mbuserdir
644650 glob = lift . glob
645651 getModificationTime = lift . getModificationTime
@@ -668,6 +674,7 @@ instance PandocMonad m => PandocMonad (ReaderT r m) where
668674 openURL = lift . openURL
669675 readFileLazy = lift . readFileLazy
670676 readFileStrict = lift . readFileStrict
677+ readDefaultDataFile = lift . readDefaultDataFile
671678 readDataFile mbuserdir = lift . readDataFile mbuserdir
672679 glob = lift . glob
673680 getModificationTime = lift . getModificationTime
@@ -684,6 +691,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (WriterT w m) where
684691 openURL = lift . openURL
685692 readFileLazy = lift . readFileLazy
686693 readFileStrict = lift . readFileStrict
694+ readDefaultDataFile = lift . readDefaultDataFile
687695 readDataFile mbuserdir = lift . readDataFile mbuserdir
688696 glob = lift . glob
689697 getModificationTime = lift . getModificationTime
@@ -700,6 +708,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (RWST r w st m) where
700708 openURL = lift . openURL
701709 readFileLazy = lift . readFileLazy
702710 readFileStrict = lift . readFileStrict
711+ readDefaultDataFile = lift . readDefaultDataFile
703712 readDataFile mbuserdir = lift . readDataFile mbuserdir
704713 glob = lift . glob
705714 getModificationTime = lift . getModificationTime
@@ -716,6 +725,7 @@ instance PandocMonad m => PandocMonad (StateT st m) where
716725 openURL = lift . openURL
717726 readFileLazy = lift . readFileLazy
718727 readFileStrict = lift . readFileStrict
728+ readDefaultDataFile = lift . readDefaultDataFile
719729 readDataFile mbuserdir = lift . readDataFile mbuserdir
720730 glob = lift . glob
721731 getModificationTime = lift . getModificationTime
src/Text/Pandoc/Shared.hs+1
@@ -78,6 +78,7 @@ module Text.Pandoc.Shared (
7878 inDirectory,
7979 getDefaultReferenceDocx,
8080 getDefaultReferenceODT,
81+ readDefaultDataFile,
8182 readDataFile,
8283 readDataFileUTF8,
8384 openURL,
src/Text/Pandoc/Writers/Docx.hs+1−1
@@ -231,7 +231,7 @@ writeDocx opts doc@(Pandoc meta _) = do
231231 username <- P.lookupEnv "USERNAME"
232232 utctime <- P.getCurrentTime
233233 distArchive <- (toArchive . BL.fromStrict) <$>
234− P.readDataFile Nothing "reference.docx"
234+ P.readDefaultDataFile "reference.docx"
235235 refArchive <- case writerReferenceDoc opts of
236236 Just f -> toArchive <$> P.readFileLazy f
237237 Nothing -> (toArchive . BL.fromStrict) <$>