aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Class
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2020-04-17 17:28:55 -0700
committerJohn MacFarlane <[email protected]>2020-04-17 22:55:44 -0700
commit3eb9e1b8bd6eec9b96ab1da230b90d635970607e (patch)
treedab56cee01110319f9f981c55aeb9e0f9993cac0 /src/Text/Pandoc/Class
parent8f40b4ba14fce10199a059a281c9bd10c884241d (diff)
Fooling around with a new setup for Text.Pandoc.Data.initialize-data-files
It is Now an exported module, exporting initializeDataFiles which must be run in PandocMonad if you are going to be looking for any data files. The point of this is to decouple pandoc's data from "pandoc-core," including the infrastructure for PandocMonad.
Diffstat (limited to 'src/Text/Pandoc/Class')
-rw-r--r--src/Text/Pandoc/Class/CommonState.hs4
-rw-r--r--src/Text/Pandoc/Class/PandocMonad.hs6
2 files changed, 6 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Class/CommonState.hs b/src/Text/Pandoc/Class/CommonState.hs
index 7e1735c2b..b535e0c1d 100644
--- a/src/Text/Pandoc/Class/CommonState.hs
+++ b/src/Text/Pandoc/Class/CommonState.hs
@@ -19,6 +19,7 @@ where
import Data.Default (Default (def))
import Data.Text (Text)
+import qualified Data.ByteString as B
import Text.Pandoc.BCP47 (Lang)
import Text.Pandoc.MediaBag (MediaBag)
import Text.Pandoc.Logging (LogMessage, Verbosity (WARNING))
@@ -50,6 +51,8 @@ data CommonState = CommonState
, stResourcePath :: [FilePath]
-- ^ Path to search for resources like
-- included images
+ , stDataFiles :: [(FilePath, B.ByteString)]
+ -- ^ Data files baked into the binary if compiled with embed_data_files
, stVerbosity :: Verbosity
-- ^ Verbosity level
, stTrace :: Bool
@@ -75,6 +78,7 @@ defaultCommonState = CommonState
, stInputFiles = []
, stOutputFile = Nothing
, stResourcePath = ["."]
+ , stDataFiles = []
, stVerbosity = WARNING
, stTrace = False
}
diff --git a/src/Text/Pandoc/Class/PandocMonad.hs b/src/Text/Pandoc/Class/PandocMonad.hs
index 991aeed41..ec704935c 100644
--- a/src/Text/Pandoc/Class/PandocMonad.hs
+++ b/src/Text/Pandoc/Class/PandocMonad.hs
@@ -86,9 +86,6 @@ import qualified Debug.Trace
import qualified System.FilePath.Posix as Posix
import qualified Text.Pandoc.MediaBag as MB
import qualified Text.Pandoc.UTF8 as UTF8
-#ifdef EMBED_DATA_FILES
-import Text.Pandoc.Data (dataFiles)
-#endif
-- | The PandocMonad typeclass contains all the potentially
-- IO-related functions used in pandoc's readers and writers.
@@ -573,8 +570,9 @@ readDefaultDataFile "reference.pptx" =
(B.concat . BL.toChunks . fromArchive) <$> getDefaultReferencePptx
readDefaultDataFile "reference.odt" =
(B.concat . BL.toChunks . fromArchive) <$> getDefaultReferenceODT
-readDefaultDataFile fname =
+readDefaultDataFile fname = do
#ifdef EMBED_DATA_FILES
+ dataFiles <- stDataFiles <$> getCommonState
case lookup (makeCanonical fname) dataFiles of
Nothing -> throwError $ PandocCouldNotFindDataFileError $ T.pack fname
Just contents -> return contents