aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-10-01 15:23:20 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-10-01 15:23:20 -0700
commit3e77ea4792979879a80e67f20712766e4af2fdf5 (patch)
tree25288071a1b424628f3aedc947e24bfc4f4e8ad4 /src/Text
parent4c3b3bf65a769eaec4b8382d8ada4f28a3b91e04 (diff)
downloadpandoc-3e77ea4792979879a80e67f20712766e4af2fdf5.tar.gz
Lua: added 'pipe', which encapsulates Text.Pandoc.Process.pipeProcess.
This is hard to do in lua, so it's helpful to provide this.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Lua/PandocModule.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Lua/PandocModule.hs b/src/Text/Pandoc/Lua/PandocModule.hs
index ecb1c530f..6a84a4350 100644
--- a/src/Text/Pandoc/Lua/PandocModule.hs
+++ b/src/Text/Pandoc/Lua/PandocModule.hs
@@ -48,6 +48,8 @@ import Text.Pandoc.Options (ReaderOptions(readerExtensions))
import Text.Pandoc.Lua.StackInstances ()
import Text.Pandoc.Readers (Reader (..), getReader)
import Text.Pandoc.MIME (MimeType)
+import Text.Pandoc.Process (pipeProcess)
+import System.Exit (ExitCode(..))
import Data.Digest.Pure.SHA (sha1, showDigest)
import qualified Foreign.Lua as Lua
@@ -66,6 +68,9 @@ pushPandocModule datadir = do
Lua.push "sha1"
Lua.pushHaskellFunction sha1HashFn
Lua.rawset (-3)
+ Lua.push "pipe"
+ Lua.pushHaskellFunction pipeFn
+ Lua.rawset (-3)
-- | Get the string representation of the pandoc module
pandocModuleScript :: Maybe FilePath -> IO String
@@ -109,6 +114,18 @@ sha1HashFn contents = do
Lua.push $ showDigest (sha1 contents)
return 1
+pipeFn :: String
+ -> [String]
+ -> BL.ByteString
+ -> Lua NumResults
+pipeFn command args input = do
+ (ec, output) <- liftIO $ pipeProcess Nothing command args input
+ Lua.push $ case ec of
+ ExitSuccess -> 0
+ ExitFailure n -> n
+ Lua.push output
+ return 2
+
insertMediaFn :: IORef MB.MediaBag
-> FilePath
-> OrNil MimeType