git.iko.soy/typeable/pandoc
on master help sign in
Added parameter for user data directory to runLuaFilter.

in Text.Pandoc.Lua. Also to pushPandocModule. This change allows users to override pandoc.lua with a file in their local data directory, adding custom functions, etc. @tarleb, if you think this is a bad idea, you can revert this. But in general our data files are all overridable.

commit5e00cf8086e0960e81c31f7cd981ace646623f09 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 29 Jun 2017, 17:13 (9 years ago) parent0f658eb
4 files changed+11−11
src/Text/Pandoc/App.hs+1−1 src/Text/Pandoc/Lua.hs+3−3 src/Text/Pandoc/Lua/PandocModule.hs+5−5 test/Tests/Lua.hs+2−2
src/Text/Pandoc/App.hs+1−1
@@ -795,7 +795,7 @@ applyLuaFilters :: MonadIO m
795795applyLuaFilters mbDatadir filters args d = do
796796 expandedFilters <- mapM (expandFilterPath mbDatadir) filters
797797 let go f d' = liftIO $ do
798− res <- E.try (runLuaFilter f args d')
798+ res <- E.try (runLuaFilter mbDatadir f args d')
799799 case res of
800800 Right x -> return x
801801 Left (LuaException s) -> E.throw (PandocFilterError f s)
src/Text/Pandoc/Lua.hs+3−3
@@ -56,12 +56,12 @@ newtype LuaException = LuaException String
5656instance Exception LuaException
5757
5858runLuaFilter :: (MonadIO m)
59− => FilePath -> [String] -> Pandoc -> m Pandoc
60−runLuaFilter filterPath args pd = liftIO $ do
59+ => Maybe FilePath -> FilePath -> [String] -> Pandoc -> m Pandoc
60+runLuaFilter datadir filterPath args pd = liftIO $ do
6161 lua <- Lua.newstate
6262 Lua.openlibs lua
6363 -- store module in global "pandoc"
64− pushPandocModule lua
64+ pushPandocModule datadir lua
6565 Lua.setglobal lua "pandoc"
6666 top <- Lua.gettop lua
6767 status <- Lua.loadfile lua filterPath
src/Text/Pandoc/Lua/PandocModule.hs+5−5
@@ -41,9 +41,9 @@ import Text.Pandoc.Readers (Reader (..), getReader)
4141import Text.Pandoc.Shared (readDataFile)
4242
4343-- | Push the "pandoc" on the lua stack.
44−pushPandocModule :: LuaState -> IO ()
45−pushPandocModule lua = do
46− script <- pandocModuleScript
44+pushPandocModule :: Maybe FilePath -> LuaState -> IO ()
45+pushPandocModule datadir lua = do
46+ script <- pandocModuleScript datadir
4747 status <- loadstring lua script "pandoc.lua"
4848 unless (status /= 0) $ call lua 0 1
4949 push lua "__read"
@@ -51,8 +51,8 @@ pushPandocModule lua = do
5151 rawset lua (-3)
5252
5353-- | Get the string representation of the pandoc module
54−pandocModuleScript :: IO String
55−pandocModuleScript = unpack <$> readDataFile Nothing "pandoc.lua"
54+pandocModuleScript :: Maybe FilePath -> IO String
55+pandocModuleScript datadir = unpack <$> readDataFile datadir "pandoc.lua"
5656
5757read_doc :: String -> String -> IO (Either String Pandoc)
5858read_doc formatSpec content = do
test/Tests/Lua.hs+2−2
@@ -68,7 +68,7 @@ tests = map (localOption (QuickCheckTests 20))
6868
6969assertFilterConversion :: String -> FilePath -> Pandoc -> Pandoc -> Assertion
7070assertFilterConversion msg filterPath docIn docExpected = do
71− docRes <- runLuaFilter ("lua" </> filterPath) [] docIn
71+ docRes <- runLuaFilter Nothing ("lua" </> filterPath) [] docIn
7272 assertEqual msg docExpected docRes
7373
7474roundtripEqual :: (Eq a, Lua.StackValue a) => a -> IO Bool
@@ -78,7 +78,7 @@ roundtripEqual x = (x ==) <$> roundtripped
7878 roundtripped = do
7979 lua <- Lua.newstate
8080 Lua.openlibs lua
81− pushPandocModule lua
81+ pushPandocModule Nothing lua
8282 Lua.setglobal lua "pandoc"
8383 oldSize <- Lua.gettop lua
8484 Lua.push lua x