diff options
| author | despresc <[email protected]> | 2019-11-07 09:41:29 -0500 |
|---|---|---|
| committer | despresc <[email protected]> | 2019-11-08 15:45:02 -0500 |
| commit | b0e46f4c82bdedb5bb51ec2cdbe1dad253f81946 (patch) | |
| tree | ab180052e5c1b4c93624de4a66b23932192dc066 | |
| parent | e6142fd749b5f58d9224a46c1b2169f855a5ec07 (diff) | |
Switch Filter to Text
| -rw-r--r-- | src/Text/Pandoc/Filter.hs | 6 | ||||
| -rw-r--r-- | src/Text/Pandoc/Filter/JSON.hs | 52 | ||||
| -rw-r--r-- | src/Text/Pandoc/Filter/Path.hs | 2 | ||||
| -rw-r--r-- | src/Text/Pandoc/Lua/Module/Utils.hs | 2 |
4 files changed, 31 insertions, 31 deletions
diff --git a/src/Text/Pandoc/Filter.hs b/src/Text/Pandoc/Filter.hs index 6ba37f5a1..e33b234bf 100644 --- a/src/Text/Pandoc/Filter.hs +++ b/src/Text/Pandoc/Filter.hs @@ -22,9 +22,9 @@ module Text.Pandoc.Filter import Prelude import Data.Aeson.TH (deriveJSON, defaultOptions) import GHC.Generics (Generic) -import Text.Pandoc.Legacy.Class (PandocIO) +import Text.Pandoc.Class (PandocIO) import Text.Pandoc.Definition (Pandoc) -import Text.Pandoc.Legacy.Options (ReaderOptions) +import Text.Pandoc.Options (ReaderOptions) import qualified Text.Pandoc.Filter.JSON as JSONFilter import qualified Text.Pandoc.Filter.Lua as LuaFilter import qualified Text.Pandoc.Filter.Path as Path @@ -65,7 +65,7 @@ applyFilters ropts filters args d = do expandedFilters <- mapM expandFilterPath filters foldM applyFilter d expandedFilters where - applyFilter doc (JSONFilter f) = JSONFilter.apply ropts (T.unpack <$> args) f doc -- TODO text: refactor + applyFilter doc (JSONFilter f) = JSONFilter.apply ropts args f doc applyFilter doc (LuaFilter f) = LuaFilter.apply ropts args f doc -- | Expand paths of filters, searching the data directory. diff --git a/src/Text/Pandoc/Filter/JSON.hs b/src/Text/Pandoc/Filter/JSON.hs index f92ebe012..029239d6a 100644 --- a/src/Text/Pandoc/Filter/JSON.hs +++ b/src/Text/Pandoc/Filter/JSON.hs @@ -1,4 +1,5 @@ {-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedStrings #-} {- | Module : Text.Pandoc.Filter Copyright : Copyright (C) 2006-2019 John MacFarlane @@ -18,33 +19,30 @@ import Control.Monad.Trans (MonadIO (liftIO)) import Data.Aeson (eitherDecode', encode) import Data.Char (toLower) import Data.Maybe (isNothing) +import qualified Data.Text as T import System.Directory (executable, doesFileExist, findExecutable, getPermissions) import System.Environment (getEnvironment) import System.Exit (ExitCode (..)) import System.FilePath ((</>), takeExtension) -import Text.Pandoc.Legacy.Class (PandocIO) --- import Text.Pandoc.Error (PandocError (PandocFilterError)) TODO text: restore +import Text.Pandoc.Class (PandocIO) +import Text.Pandoc.Error (PandocError (PandocFilterError)) import Text.Pandoc.Definition (Pandoc) -import Text.Pandoc.Legacy.Options (ReaderOptions) -import Text.Pandoc.Legacy.Process (pipeProcess) -import Text.Pandoc.Legacy.Shared (pandocVersion) +import Text.Pandoc.Options (ReaderOptions) +import Text.Pandoc.Process (pipeProcess) +import Text.Pandoc.Shared (pandocVersion) import qualified Control.Exception as E import qualified Text.Pandoc.UTF8 as UTF8 --- TODO text: remove -import Text.Pandoc.Legacy.Error --- - apply :: ReaderOptions - -> [String] + -> [T.Text] -> FilePath -> Pandoc -> PandocIO Pandoc apply ropts args f = liftIO . externalFilter ropts f args externalFilter :: MonadIO m - => ReaderOptions -> FilePath -> [String] -> Pandoc -> m Pandoc + => ReaderOptions -> FilePath -> [T.Text] -> Pandoc -> m Pandoc externalFilter ropts f args' d = liftIO $ do exists <- doesFileExist f isExecutable <- if exists @@ -53,30 +51,32 @@ externalFilter ropts f args' d = liftIO $ do let (f', args'') = if exists then case map toLower (takeExtension f) of _ | isExecutable -> ("." </> f, args') - ".py" -> ("python", f:args') - ".hs" -> ("runhaskell", f:args') - ".pl" -> ("perl", f:args') - ".rb" -> ("ruby", f:args') - ".php" -> ("php", f:args') - ".js" -> ("node", f:args') - ".r" -> ("Rscript", f:args') + ".py" -> ("python", fText:args') + ".hs" -> ("runhaskell", fText:args') + ".pl" -> ("perl", fText:args') + ".rb" -> ("ruby", fText:args') + ".php" -> ("php", fText:args') + ".js" -> ("node", fText:args') + ".r" -> ("Rscript", fText:args') _ -> (f, args') else (f, args') unless (exists && isExecutable) $ do mbExe <- findExecutable f' when (isNothing mbExe) $ - E.throwIO $ PandocFilterError f ("Could not find executable " ++ f') + E.throwIO $ PandocFilterError fText (T.pack $ "Could not find executable " <> f') env <- getEnvironment let env' = Just ( ("PANDOC_VERSION", pandocVersion) - : ("PANDOC_READER_OPTIONS", UTF8.toStringLazy (encode ropts)) - : env ) + : ("PANDOC_READER_OPTIONS", (T.pack . UTF8.toStringLazy) (encode ropts)) + : map (\(x, y) -> (T.pack x, T.pack y)) env ) (exitcode, outbs) <- E.handle filterException $ pipeProcess env' f' args'' $ encode d case exitcode of - ExitSuccess -> either (E.throwIO . PandocFilterError f) + ExitSuccess -> either (E.throwIO . PandocFilterError fText . T.pack) return $ eitherDecode' outbs - ExitFailure ec -> E.throwIO $ PandocFilterError f - ("Filter returned error status " ++ show ec) - where filterException :: E.SomeException -> IO a - filterException e = E.throwIO $ PandocFilterError f (show e) + ExitFailure ec -> E.throwIO $ PandocFilterError fText + ("Filter returned error status " <> T.pack (show ec)) + where fText = T.pack f + + filterException :: E.SomeException -> IO a + filterException e = E.throwIO $ PandocFilterError fText (T.pack $ show e) diff --git a/src/Text/Pandoc/Filter/Path.hs b/src/Text/Pandoc/Filter/Path.hs index 8e58bcc43..ef2e16b63 100644 --- a/src/Text/Pandoc/Filter/Path.hs +++ b/src/Text/Pandoc/Filter/Path.hs @@ -15,7 +15,7 @@ module Text.Pandoc.Filter.Path ) where import Prelude -import Text.Pandoc.Legacy.Class (PandocMonad, fileExists, getUserDataDir) +import Text.Pandoc.Class (PandocMonad, fileExists, getUserDataDir) import System.FilePath ((</>), isRelative) -- First we check to see if a filter is found. If not, and if it's diff --git a/src/Text/Pandoc/Lua/Module/Utils.hs b/src/Text/Pandoc/Lua/Module/Utils.hs index 0979dfda1..44e7729ec 100644 --- a/src/Text/Pandoc/Lua/Module/Utils.hs +++ b/src/Text/Pandoc/Lua/Module/Utils.hs @@ -82,7 +82,7 @@ runJSONFilter mbDatadir doc filterFile optArgs = do (:[]) <$> Lua.popValue filterRes <- Lua.liftIO . runIO $ do setUserDataDir mbDatadir - JSONFilter.apply def (T.unpack <$> args) filterFile doc -- TODO text: refactor + JSONFilter.apply def args filterFile doc case filterRes of Left err -> Lua.raiseError (show err) Right d -> (1 :: NumResults) <$ Lua.push d |
