@@ -48,6 +48,8 @@ import Text.Pandoc.Options (ReaderOptions(readerExtensions))
4848import Text.Pandoc.Lua.StackInstances ()
4949import Text.Pandoc.Readers (Reader (..), getReader)
5050import Text.Pandoc.MIME (MimeType)
51+import Text.Pandoc.Process (pipeProcess)
52+import System.Exit (ExitCode(..))
5153import Data.Digest.Pure.SHA (sha1, showDigest)
5254
5355import qualified Foreign.Lua as Lua
@@ -66,6 +68,9 @@ pushPandocModule datadir = do
6668 Lua.push "sha1"
6769 Lua.pushHaskellFunction sha1HashFn
6870 Lua.rawset (-3)
71+ Lua.push "pipe"
72+ Lua.pushHaskellFunction pipeFn
73+ Lua.rawset (-3)
6974
7075-- | Get the string representation of the pandoc module
7176pandocModuleScript :: Maybe FilePath -> IO String
@@ -109,6 +114,18 @@ sha1HashFn contents = do
109114 Lua.push $ showDigest (sha1 contents)
110115 return 1
111116
117+pipeFn :: String
118+ -> [String]
119+ -> BL.ByteString
120+ -> Lua NumResults
121+pipeFn command args input = do
122+ (ec, output) <- liftIO $ pipeProcess Nothing command args input
123+ Lua.push $ case ec of
124+ ExitSuccess -> 0
125+ ExitFailure n -> n
126+ Lua.push output
127+ return 2
128+
112129insertMediaFn :: IORef MB.MediaBag
113130 -> FilePath
114131 -> OrNil MimeType