git.iko.soy/typeable/pandoc
on master help sign in
Removed datadir param from readDataFile and getDefaultTemplate.

In Text.Pandoc.Class and Text.Pandoc.Template, resp. We now get the datadir from CommonState.

commit737d09e325a65ad37f97b03371d1999c0360dea0 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 10 Aug 2017, 23:29 (9 years ago) parent13abd97
6 files changed+45−37
src/Text/Pandoc/App.hs+9−4 src/Text/Pandoc/Class.hs+20−14 src/Text/Pandoc/Templates.hs+13−14 src/Text/Pandoc/Writers/Docx.hs+1−1 src/Text/Pandoc/Writers/EPUB.hs+1−2 src/Text/Pandoc/Writers/ODT.hs+1−2
src/Text/Pandoc/App.hs+9−4
@@ -76,7 +76,8 @@ import System.IO.Error (isDoesNotExistError)
7676import Text.Pandoc
7777import Text.Pandoc.Builder (setMeta)
7878import Text.Pandoc.Class (PandocIO, extractMedia, fillMediaBag, getLog,
79− setResourcePath, getMediaBag, setTrace, report)
79+ setResourcePath, getMediaBag, setTrace, report,
80+ setUserDataDir)
8081import Text.Pandoc.Highlighting (highlightingStyles)
8182import Text.Pandoc.Lua (runLuaFilter, LuaException(..))
8283import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL)
@@ -218,8 +219,9 @@ convertWithOpts opts = do
218219 templ <- case optTemplate opts of
219220 _ | not standalone -> return Nothing
220221 Nothing -> do
221− deftemp <- runIO $
222− getDefaultTemplate datadir format
222+ deftemp <- runIO $ do
223+ setUserDataDir datadir
224+ getDefaultTemplate format
223225 case deftemp of
224226 Left e -> E.throwIO e
225227 Right t -> return (Just t)
@@ -444,6 +446,7 @@ convertWithOpts opts = do
444446 Native -> nativeNewline
445447
446448 runIO' $ do
449+ setUserDataDir datadir
447450 when (readerName == "markdown_github" ||
448451 writerName == "markdown_github") $
449452 report $ Deprecated "markdown_github" "Use gfm instead."
@@ -996,7 +999,9 @@ options =
996999 , Option "D" ["print-default-template"]
9971000 (ReqArg
9981001 (\arg _ -> do
999− templ <- runIO $ getDefaultTemplate Nothing arg
1002+ templ <- runIO $ do
1003+ setUserDataDir Nothing
1004+ getDefaultTemplate arg
10001005 case templ of
10011006 Right t -> UTF8.hPutStr stdout t
10021007 Left e -> E.throwIO e
src/Text/Pandoc/Class.hs+20−14
@@ -157,9 +157,9 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m)
157157 readFileStrict :: FilePath -> m B.ByteString
158158 -- | Read file from from Cabal data directory.
159159 readDefaultDataFile :: FilePath -> m B.ByteString
160− -- | Read file from specified user data directory or,
160+ -- | Read file from user data directory or,
161161 -- if not found there, from Cabal data directory.
162− readDataFile :: Maybe FilePath -> FilePath -> m B.ByteString
162+ readDataFile :: FilePath -> m B.ByteString
163163 -- | Return a list of paths that match a glob, relative to
164164 -- the working directory. See 'System.FilePath.Glob' for
165165 -- the glob syntax.
@@ -335,7 +335,9 @@ instance PandocMonad PandocIO where
335335 readFileLazy s = liftIOError BL.readFile s
336336 readFileStrict s = liftIOError B.readFile s
337337 readDefaultDataFile fname = liftIOError IO.readDefaultDataFile fname
338− readDataFile mfp fname = liftIOError (IO.readDataFile mfp) fname
338+ readDataFile fname = do
339+ datadir <- getUserDataDir
340+ liftIOError (IO.readDataFile datadir) fname
339341 glob = liftIO . IO.glob
340342 getModificationTime fp = liftIOError IO.getModificationTime fp
341343 getCommonState = PandocIO $ lift get
@@ -629,12 +631,16 @@ instance PandocMonad PandocPure where
629631 readDefaultDataFile fname = do
630632 let fname' = if fname == "MANUAL.txt" then fname else "data" </> fname
631633 readFileStrict fname'
632− readDataFile (Just userDir) fname = do
633− userDirFiles <- getsPureState stUserDataFiles
634− case infoFileContents <$> getFileInfo (userDir </> fname) userDirFiles of
635− Just bs -> return bs
636− Nothing -> readDataFile Nothing fname
637− readDataFile Nothing fname = readDefaultDataFile fname
634+ readDataFile fname = do
635+ datadir <- getUserDataDir
636+ case datadir of
637+ Just userDir -> do
638+ userDirFiles <- getsPureState stUserDataFiles
639+ case infoFileContents <$> getFileInfo (userDir </> fname)
640+ userDirFiles of
641+ Just bs -> return bs
642+ Nothing -> readDefaultDataFile fname
643+ Nothing -> readDefaultDataFile fname
638644
639645 glob s = do
640646 FileTree ftmap <- getsPureState stFiles
@@ -662,7 +668,7 @@ instance PandocMonad m => PandocMonad (ParsecT s st m) where
662668 readFileLazy = lift . readFileLazy
663669 readFileStrict = lift . readFileStrict
664670 readDefaultDataFile = lift . readDefaultDataFile
665− readDataFile mbuserdir = lift . readDataFile mbuserdir
671+ readDataFile = lift . readDataFile
666672 glob = lift . glob
667673 getModificationTime = lift . getModificationTime
668674 getCommonState = lift getCommonState
@@ -691,7 +697,7 @@ instance PandocMonad m => PandocMonad (ReaderT r m) where
691697 readFileLazy = lift . readFileLazy
692698 readFileStrict = lift . readFileStrict
693699 readDefaultDataFile = lift . readDefaultDataFile
694− readDataFile mbuserdir = lift . readDataFile mbuserdir
700+ readDataFile = lift . readDataFile
695701 glob = lift . glob
696702 getModificationTime = lift . getModificationTime
697703 getCommonState = lift getCommonState
@@ -708,7 +714,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (WriterT w m) where
708714 readFileLazy = lift . readFileLazy
709715 readFileStrict = lift . readFileStrict
710716 readDefaultDataFile = lift . readDefaultDataFile
711− readDataFile mbuserdir = lift . readDataFile mbuserdir
717+ readDataFile = lift . readDataFile
712718 glob = lift . glob
713719 getModificationTime = lift . getModificationTime
714720 getCommonState = lift getCommonState
@@ -725,7 +731,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (RWST r w st m) where
725731 readFileLazy = lift . readFileLazy
726732 readFileStrict = lift . readFileStrict
727733 readDefaultDataFile = lift . readDefaultDataFile
728− readDataFile mbuserdir = lift . readDataFile mbuserdir
734+ readDataFile = lift . readDataFile
729735 glob = lift . glob
730736 getModificationTime = lift . getModificationTime
731737 getCommonState = lift getCommonState
@@ -742,7 +748,7 @@ instance PandocMonad m => PandocMonad (StateT st m) where
742748 readFileLazy = lift . readFileLazy
743749 readFileStrict = lift . readFileStrict
744750 readDefaultDataFile = lift . readDefaultDataFile
745− readDataFile mbuserdir = lift . readDataFile mbuserdir
751+ readDataFile = lift . readDataFile
746752 glob = lift . glob
747753 getModificationTime = lift . getModificationTime
748754 getCommonState = lift getCommonState
src/Text/Pandoc/Templates.hs+13−14
@@ -50,28 +50,27 @@ import qualified Text.Pandoc.UTF8 as UTF8
5050
5151-- | Get default template for the specified writer.
5252getDefaultTemplate :: PandocMonad m
53− => (Maybe FilePath) -- ^ User data directory to search 1st
54− -> String -- ^ Name of writer
53+ => String -- ^ Name of writer
5554 -> m String
56−getDefaultTemplate user writer = do
55+getDefaultTemplate writer = do
5756 let format = takeWhile (`notElem` ("+-" :: String)) writer -- strip off extensions
5857 case format of
5958 "native" -> return ""
6059 "json" -> return ""
6160 "docx" -> return ""
6261 "fb2" -> return ""
63− "odt" -> getDefaultTemplate user "opendocument"
64− "html" -> getDefaultTemplate user "html5"
65− "docbook" -> getDefaultTemplate user "docbook5"
66− "epub" -> getDefaultTemplate user "epub3"
67− "markdown_strict" -> getDefaultTemplate user "markdown"
68− "multimarkdown" -> getDefaultTemplate user "markdown"
69− "markdown_github" -> getDefaultTemplate user "markdown"
70− "markdown_mmd" -> getDefaultTemplate user "markdown"
71− "markdown_phpextra" -> getDefaultTemplate user "markdown"
72− "gfm" -> getDefaultTemplate user "commonmark"
62+ "odt" -> getDefaultTemplate "opendocument"
63+ "html" -> getDefaultTemplate "html5"
64+ "docbook" -> getDefaultTemplate "docbook5"
65+ "epub" -> getDefaultTemplate "epub3"
66+ "markdown_strict" -> getDefaultTemplate "markdown"
67+ "multimarkdown" -> getDefaultTemplate "markdown"
68+ "markdown_github" -> getDefaultTemplate "markdown"
69+ "markdown_mmd" -> getDefaultTemplate "markdown"
70+ "markdown_phpextra" -> getDefaultTemplate "markdown"
71+ "gfm" -> getDefaultTemplate "commonmark"
7372 _ -> let fname = "templates" </> "default" <.> format
74− in UTF8.toString <$> readDataFile user fname
73+ in UTF8.toString <$> readDataFile fname
7574
7675-- | Like 'applyTemplate', but runs in PandocMonad and
7776-- raises an error if compilation fails.
src/Text/Pandoc/Writers/Docx.hs+1−1
@@ -235,7 +235,7 @@ writeDocx opts doc@(Pandoc meta _) = do
235235 refArchive <- case writerReferenceDoc opts of
236236 Just f -> toArchive <$> P.readFileLazy f
237237 Nothing -> (toArchive . BL.fromStrict) <$>
238− P.readDataFile datadir "reference.docx"
238+ P.readDataFile "reference.docx"
239239
240240 parsedDoc <- parseXml refArchive distArchive "word/document.xml"
241241 let wname f qn = qPrefix qn == Just "w" && f (qName qn)
src/Text/Pandoc/Writers/EPUB.hs+1−2
@@ -393,8 +393,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
393393 -- stylesheet
394394 stylesheets <- case epubStylesheets metadata of
395395 [] -> (\x -> [B.fromChunks [x]]) <$>
396− P.readDataFile (writerUserDataDir opts)
397− "epub.css"
396+ P.readDataFile "epub.css"
398397 fs -> mapM P.readFileLazy fs
399398 let stylesheetEntries = zipWith
400399 (\bs n -> mkEntry ("styles/stylesheet" ++ show n ++ ".css") bs)
src/Text/Pandoc/Writers/ODT.hs+1−2
@@ -78,14 +78,13 @@ pandocToODT :: PandocMonad m
7878 -> Pandoc -- ^ Document to convert
7979 -> O m B.ByteString
8080pandocToODT opts doc@(Pandoc meta _) = do
81− let datadir = writerUserDataDir opts
8281 let title = docTitle meta
8382 lang <- toLang (getLang opts meta)
8483 refArchive <-
8584 case writerReferenceDoc opts of
8685 Just f -> liftM toArchive $ lift $ P.readFileLazy f
8786 Nothing -> lift $ (toArchive . B.fromStrict) <$>
88− P.readDataFile datadir "reference.odt"
87+ P.readDataFile "reference.odt"
8988 -- handle formulas and pictures
9089 -- picEntriesRef <- P.newIORef ([] :: [Entry])
9190 doc' <- walkM (transformPicMath opts) $ walk fixDisplayMath doc