@@ -273,18 +273,22 @@ setRequestHeader name val = modifyCommonState $ \st ->
273setMediaBag :: PandocMonad m => MediaBag -> m ()
273setMediaBag :: PandocMonad m => MediaBag -> m ()
274setMediaBag mb = modifyCommonState $ \st -> st{stMediaBag = mb}
274setMediaBag mb = modifyCommonState $ \st -> st{stMediaBag = mb}
276+-- Retrieve the media bag.
276getMediaBag :: PandocMonad m => m MediaBag
277getMediaBag :: PandocMonad m => m MediaBag
277getMediaBag = getsCommonState stMediaBag
278getMediaBag = getsCommonState stMediaBag
280+-- Insert an item into the media bag.
279insertMedia :: PandocMonad m => FilePath -> Maybe MimeType -> BL.ByteString -> m ()
281insertMedia :: PandocMonad m => FilePath -> Maybe MimeType -> BL.ByteString -> m ()
280insertMedia fp mime bs = do
282insertMedia fp mime bs = do
281 mb <- getMediaBag
283 mb <- getMediaBag
282 let mb' = MB.insertMedia fp mime bs mb
284 let mb' = MB.insertMedia fp mime bs mb
283 setMediaBag mb'
285 setMediaBag mb'
287+-- Retrieve the input filenames.
285getInputFiles :: PandocMonad m => m [FilePath]
288getInputFiles :: PandocMonad m => m [FilePath]
286getInputFiles = getsCommonState stInputFiles
289getInputFiles = getsCommonState stInputFiles
291+-- Set the input filenames.
288setInputFiles :: PandocMonad m => [FilePath] -> m ()
292setInputFiles :: PandocMonad m => [FilePath] -> m ()
289setInputFiles fs = do
293setInputFiles fs = do
290 let sourceURL = case fs of
294 let sourceURL = case fs of
@@ -299,21 +303,27 @@ setInputFiles fs = do
299 modifyCommonState $ \st -> st{ stInputFiles = fs
303 modifyCommonState $ \st -> st{ stInputFiles = fs
300 , stSourceURL = sourceURL }
304 , stSourceURL = sourceURL }
306+-- Retrieve the output filename.
302getOutputFile :: PandocMonad m => m (Maybe FilePath)
307getOutputFile :: PandocMonad m => m (Maybe FilePath)
303getOutputFile = getsCommonState stOutputFile
308getOutputFile = getsCommonState stOutputFile
310+-- Set the output filename.
305setOutputFile :: PandocMonad m => Maybe FilePath -> m ()
311setOutputFile :: PandocMonad m => Maybe FilePath -> m ()
306setOutputFile mbf = modifyCommonState $ \st -> st{ stOutputFile = mbf }
312setOutputFile mbf = modifyCommonState $ \st -> st{ stOutputFile = mbf }
308−setResourcePath :: PandocMonad m => [FilePath] -> m ()
314+-- Retrieve the resource path searched by 'fetchItem'.
309−setResourcePath ps = modifyCommonState $ \st -> st{stResourcePath = ps}
311getResourcePath :: PandocMonad m => m [FilePath]
315getResourcePath :: PandocMonad m => m [FilePath]
312getResourcePath = getsCommonState stResourcePath
316getResourcePath = getsCommonState stResourcePath
318+-- Set the resource path searched by 'fetchItem'.
319+setResourcePath :: PandocMonad m => [FilePath] -> m ()
320+setResourcePath ps = modifyCommonState $ \st -> st{stResourcePath = ps}
322+-- Get the POSIX time.
314getPOSIXTime :: PandocMonad m => m POSIXTime
323getPOSIXTime :: PandocMonad m => m POSIXTime
315getPOSIXTime = utcTimeToPOSIXSeconds <$> getCurrentTime
324getPOSIXTime = utcTimeToPOSIXSeconds <$> getCurrentTime
326+-- Get the zoned time.
317getZonedTime :: PandocMonad m => m ZonedTime
327getZonedTime :: PandocMonad m => m ZonedTime
318getZonedTime = do
328getZonedTime = do
319 t <- getCurrentTime
329 t <- getCurrentTime
@@ -445,6 +455,8 @@ translateTerm term = do
445runIO :: PandocIO a -> IO (Either PandocError a)
455runIO :: PandocIO a -> IO (Either PandocError a)
446runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma
456runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma
458+-- | Evaluate a 'PandocIO' operation, handling any errors
459+-- by exiting with an appropriate message and error status.
448runIOorExplode :: PandocIO a -> IO a
460runIOorExplode :: PandocIO a -> IO a
449runIOorExplode ma = runIO ma >>= handleError
461runIOorExplode ma = runIO ma >>= handleError
@@ -457,6 +469,7 @@ newtype PandocIO a = PandocIO {
457 , MonadError PandocError
469 , MonadError PandocError
472+-- | Utility function to lift IO errors into 'PandocError's.
460liftIOError :: (String -> IO a) -> String -> PandocIO a
473liftIOError :: (String -> IO a) -> String -> PandocIO a
461liftIOError f u = do
474liftIOError f u = do
462 res <- liftIO $ tryIOError $ f u
475 res <- liftIO $ tryIOError $ f u
@@ -600,6 +613,7 @@ downloadOrRead s = do
600 convertSlash '\\' = '/'
613 convertSlash '\\' = '/'
601 convertSlash x = x
614 convertSlash x = x
616+-- Retrieve default reference.docx.
603getDefaultReferenceDocx :: PandocMonad m => m Archive
617getDefaultReferenceDocx :: PandocMonad m => m Archive
604getDefaultReferenceDocx = do
618getDefaultReferenceDocx = do
605 let paths = ["[Content_Types].xml",
619 let paths = ["[Content_Types].xml",
@@ -634,6 +648,7 @@ getDefaultReferenceDocx = do
634 Nothing -> foldr addEntryToArchive emptyArchive <$>
648 Nothing -> foldr addEntryToArchive emptyArchive <$>
635 mapM pathToEntry paths
649 mapM pathToEntry paths
651+-- Retrieve default reference.odt.
637getDefaultReferenceODT :: PandocMonad m => m Archive
652getDefaultReferenceODT :: PandocMonad m => m Archive
638getDefaultReferenceODT = do
653getDefaultReferenceODT = do
639 let paths = ["mimetype",
654 let paths = ["mimetype",
@@ -760,6 +775,7 @@ extractMedia dir d = do
760 mapM_ (writeMedia dir media) fps
775 mapM_ (writeMedia dir media) fps
761 return $ walk (adjustImagePath dir fps) d
776 return $ walk (adjustImagePath dir fps) d
778+-- Write the contents of a media bag to a path.
763writeMedia :: FilePath -> MediaBag -> FilePath -> PandocIO ()
779writeMedia :: FilePath -> MediaBag -> FilePath -> PandocIO ()
764writeMedia dir mediabag subpath = do
780writeMedia dir mediabag subpath = do
765 -- we join and split to convert a/b/c to a\b\c on Windows;
781 -- we join and split to convert a/b/c to a\b\c on Windows;
@@ -778,6 +794,8 @@ adjustImagePath dir paths (Image attr lab (src, tit))
778 | src `elem` paths = Image attr lab (dir ++ "/" ++ src, tit)
794 | src `elem` paths = Image attr lab (dir ++ "/" ++ src, tit)
779adjustImagePath _ _ x = x
795adjustImagePath _ _ x = x
797+-- | The 'PureState' contains ersatz representations
798+-- of things that would normally be obtained through IO.
781data PureState = PureState { stStdGen :: StdGen
799data PureState = PureState { stStdGen :: StdGen
782 , stWord8Store :: [Word8] -- should be
800 , stWord8Store :: [Word8] -- should be
783 -- inifinite,
801 -- inifinite,
@@ -863,6 +881,7 @@ newtype PandocPure a = PandocPure {
863 , MonadError PandocError
881 , MonadError PandocError
884+-- Run a 'PandocPure' operation.
866runPure :: PandocPure a -> Either PandocError a
885runPure :: PandocPure a -> Either PandocError a
867runPure x = flip evalState def $
886runPure x = flip evalState def $
868 flip evalStateT def $
887 flip evalStateT def $