aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-08-10 23:04:14 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-08-10 23:04:14 -0700
commit6aaf8f4770916fcef433d0078502d674a1c97fc7 (patch)
tree047b72916bbd49414b9d316c0ef71b772fb45860 /src/Text
parented4f6b348a7a53900dbddadc6681bc7561661f36 (diff)
downloadpandoc-6aaf8f4770916fcef433d0078502d674a1c97fc7.tar.gz
Expose getDefaultDataFile in both Shared and Class.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/App.hs6
-rw-r--r--src/Text/Pandoc/Class.hs16
-rw-r--r--src/Text/Pandoc/Shared.hs1
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs2
4 files changed, 18 insertions, 7 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index 073b1f3ef..8a7947de6 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -84,8 +84,8 @@ import Text.Pandoc.PDF (makePDF)
import Text.Pandoc.Process (pipeProcess)
import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
import Text.Pandoc.Shared (headerShift, isURI, openURL, readDataFile,
- readDataFileUTF8, safeRead, tabFilter,
- eastAsianLineBreakFilter)
+ readDataFileUTF8, readDefaultDataFile,
+ safeRead, tabFilter, eastAsianLineBreakFilter)
import qualified Text.Pandoc.UTF8 as UTF8
import Text.Pandoc.XML (toEntities)
import Text.Printf
@@ -1007,7 +1007,7 @@ options =
, Option "" ["print-default-data-file"]
(ReqArg
(\arg _ -> do
- readDataFile Nothing arg >>= BS.hPutStr stdout
+ readDefaultDataFile arg >>= BS.hPutStr stdout
exitSuccess)
"FILE")
"" -- "Print default data file"
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs
index a8db05e5b..cefc8ee2c 100644
--- a/src/Text/Pandoc/Class.hs
+++ b/src/Text/Pandoc/Class.hs
@@ -80,6 +80,7 @@ import Codec.Archive.Zip (Archive, fromArchive, emptyArchive)
import Data.Unique (hashUnique)
import qualified Data.Unique as IO (newUnique)
import qualified Text.Pandoc.Shared as IO ( readDataFile
+ , readDefaultDataFile
, openURL )
import qualified Text.Pandoc.UTF8 as UTF8
import Text.Pandoc.Compat.Time (UTCTime)
@@ -152,6 +153,8 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m)
-- | Read the strict ByteString contents from a file path,
-- raising an error on failure.
readFileStrict :: FilePath -> m B.ByteString
+ -- | Read file from from Cabal data directory.
+ readDefaultDataFile :: FilePath -> m B.ByteString
-- | Read file from specified user data directory or,
-- if not found there, from Cabal data directory.
readDataFile :: Maybe FilePath -> FilePath -> m B.ByteString
@@ -326,6 +329,7 @@ instance PandocMonad PandocIO where
Left e -> throwError $ PandocHttpError u e
readFileLazy s = liftIOError BL.readFile s
readFileStrict s = liftIOError B.readFile s
+ readDefaultDataFile fname = liftIOError IO.readDefaultDataFile fname
readDataFile mfp fname = liftIOError (IO.readDataFile mfp) fname
glob = liftIO . IO.glob
getModificationTime fp = liftIOError IO.getModificationTime fp
@@ -602,11 +606,11 @@ instance PandocMonad PandocPure where
case infoFileContents <$> getFileInfo fp fps of
Just bs -> return bs
Nothing -> throwError $ PandocResourceNotFound fp
- readDataFile Nothing "reference.docx" =
+ readDefaultDataFile "reference.docx" =
(B.concat . BL.toChunks . fromArchive) <$> getsPureState stReferenceDocx
- readDataFile Nothing "reference.odt" =
+ readDefaultDataFile "reference.odt" =
(B.concat . BL.toChunks . fromArchive) <$> getsPureState stReferenceODT
- readDataFile Nothing fname = do
+ readDefaultDataFile fname = do
let fname' = if fname == "MANUAL.txt" then fname else "data" </> fname
readFileStrict fname'
readDataFile (Just userDir) fname = do
@@ -614,6 +618,7 @@ instance PandocMonad PandocPure where
case infoFileContents <$> getFileInfo (userDir </> fname) userDirFiles of
Just bs -> return bs
Nothing -> readDataFile Nothing fname
+ readDataFile Nothing fname = readDefaultDataFile fname
glob s = do
FileTree ftmap <- getsPureState stFiles
@@ -640,6 +645,7 @@ instance PandocMonad m => PandocMonad (ParsecT s st m) where
openURL = lift . openURL
readFileLazy = lift . readFileLazy
readFileStrict = lift . readFileStrict
+ readDefaultDataFile = lift . readDefaultDataFile
readDataFile mbuserdir = lift . readDataFile mbuserdir
glob = lift . glob
getModificationTime = lift . getModificationTime
@@ -668,6 +674,7 @@ instance PandocMonad m => PandocMonad (ReaderT r m) where
openURL = lift . openURL
readFileLazy = lift . readFileLazy
readFileStrict = lift . readFileStrict
+ readDefaultDataFile = lift . readDefaultDataFile
readDataFile mbuserdir = lift . readDataFile mbuserdir
glob = lift . glob
getModificationTime = lift . getModificationTime
@@ -684,6 +691,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (WriterT w m) where
openURL = lift . openURL
readFileLazy = lift . readFileLazy
readFileStrict = lift . readFileStrict
+ readDefaultDataFile = lift . readDefaultDataFile
readDataFile mbuserdir = lift . readDataFile mbuserdir
glob = lift . glob
getModificationTime = lift . getModificationTime
@@ -700,6 +708,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (RWST r w st m) where
openURL = lift . openURL
readFileLazy = lift . readFileLazy
readFileStrict = lift . readFileStrict
+ readDefaultDataFile = lift . readDefaultDataFile
readDataFile mbuserdir = lift . readDataFile mbuserdir
glob = lift . glob
getModificationTime = lift . getModificationTime
@@ -716,6 +725,7 @@ instance PandocMonad m => PandocMonad (StateT st m) where
openURL = lift . openURL
readFileLazy = lift . readFileLazy
readFileStrict = lift . readFileStrict
+ readDefaultDataFile = lift . readDefaultDataFile
readDataFile mbuserdir = lift . readDataFile mbuserdir
glob = lift . glob
getModificationTime = lift . getModificationTime
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 53fd38ffd..5503c96f1 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -78,6 +78,7 @@ module Text.Pandoc.Shared (
inDirectory,
getDefaultReferenceDocx,
getDefaultReferenceODT,
+ readDefaultDataFile,
readDataFile,
readDataFileUTF8,
openURL,
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index fb6b2013a..a60056845 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -231,7 +231,7 @@ writeDocx opts doc@(Pandoc meta _) = do
username <- P.lookupEnv "USERNAME"
utctime <- P.getCurrentTime
distArchive <- (toArchive . BL.fromStrict) <$>
- P.readDataFile Nothing "reference.docx"
+ P.readDefaultDataFile "reference.docx"
refArchive <- case writerReferenceDoc opts of
Just f -> toArchive <$> P.readFileLazy f
Nothing -> (toArchive . BL.fromStrict) <$>