pandoc-cli: support -E flag in pandoc-lua

This commit is contained in:
Albert Krewinkel
2022-09-27 08:42:27 -07:00
committed by John MacFarlane
parent 175b791529
commit efecff1f2f
4 changed files with 24 additions and 6 deletions
+1 -2
View File
@@ -7102,8 +7102,7 @@ Calling the pandoc executable under the name `pandoc-lua` or with
`lua` as the first argument will make it function as a standalone
Lua interpreter. The behavior is mostly identical to that of the
[standalone `lua` executable][lua standalone], version 5.4.
However, there is no REPL yet, and the options `-W`, `-E`, and
`-i` currently don't have any effect.
However, there is no REPL yet, and the `-i` option has no effect.
[lua standalone]: https://www.lua.org/manual/5.4/manual.html#7
+7 -3
View File
@@ -14,13 +14,13 @@ writers.
module Main where
import Control.Monad ((<=<))
import qualified Control.Exception as E
import HsLua.CLI (Settings (..), runStandalone)
import HsLua.CLI (EnvBehavior (..), Settings (..), runStandalone)
import System.Environment (getArgs, getProgName)
import Text.Pandoc.App ( convertWithOpts, defaultOpts, options
, parseOptionsFromArgs)
import Text.Pandoc.Class (runIOorExplode)
import Text.Pandoc.Error (handleError)
import Text.Pandoc.Lua (runLua)
import Text.Pandoc.Lua (runLua, runLuaNoEnv)
import Text.Pandoc.Shared (pandocVersion)
import qualified Text.Pandoc.UTF8 as UTF8
import PandocCLI.Server
@@ -50,4 +50,8 @@ runLuaInterpreter progName args = do
}
runStandalone settings progName args
where
runner _envBehavior = handleError <=< runIOorExplode . runLua
runner envBehavior =
let runLua' = case envBehavior of
IgnoreEnvVars -> runLuaNoEnv
ConsultEnvVars -> runLua
in handleError <=< runIOorExplode . runLua'
+2 -1
View File
@@ -20,11 +20,12 @@ module Text.Pandoc.Lua
, Global(..)
, setGlobals
, runLua
, runLuaNoEnv
) where
import Text.Pandoc.Lua.Filter (applyFilter)
import Text.Pandoc.Lua.Global (Global (..), setGlobals)
import Text.Pandoc.Lua.Init (runLua)
import Text.Pandoc.Lua.Init (runLua, runLuaNoEnv)
import Text.Pandoc.Lua.Reader (readCustom)
import Text.Pandoc.Lua.Writer (writeCustom)
import Text.Pandoc.Lua.Orphans ()
+14
View File
@@ -12,6 +12,7 @@ Functions to initialize the Lua interpreter.
-}
module Text.Pandoc.Lua.Init
( runLua
, runLuaNoEnv
) where
import Control.Monad (forM, forM_, when)
@@ -46,6 +47,19 @@ runLua action =
initLuaState
liftPandocLua action
-- | Like 'runLua', but ignores all environment variables like @LUA_PATH@.
runLuaNoEnv :: (PandocMonad m, MonadIO m)
=> LuaE PandocError a -> m (Either PandocError a)
runLuaNoEnv action =
runPandocLua . try $ do
liftPandocLua $ do
-- This is undocumented, but works -- the code is adapted from the
-- `lua.c` sources for the default interpreter.
Lua.pushboolean True
Lua.setfield Lua.registryindex "LUA_NOENV"
initLuaState
liftPandocLua action
-- | Modules that are loaded at startup and assigned to fields in the
-- pandoc module.
--