git.iko.soy/typeable/pandoc
on master help sign in
Added parameter for user data directory to runLuaFilter.
5e00cf8John MacFarlane
src/Text/Pandoc/App.hs+1−1
@@ -795,7 +795,7 @@ applyLuaFilters :: MonadIO m
795applyLuaFilters mbDatadir filters args d = do
795applyLuaFilters mbDatadir filters args d = do
796 expandedFilters <- mapM (expandFilterPath mbDatadir) filters
796 expandedFilters <- mapM (expandFilterPath mbDatadir) filters
797 let go f d' = liftIO $ do
797 let go f d' = liftIO $ do
798− res <- E.try (runLuaFilter f args d')
798+ res <- E.try (runLuaFilter mbDatadir f args d')
799 case res of
799 case res of
800 Right x -> return x
800 Right x -> return x
801 Left (LuaException s) -> E.throw (PandocFilterError f s)
801 Left (LuaException s) -> E.throw (PandocFilterError f s)
src/Text/Pandoc/Lua.hs+3−3
@@ -56,12 +56,12 @@ newtype LuaException = LuaException String
56instance Exception LuaException
56instance Exception LuaException
57
57
58runLuaFilter :: (MonadIO m)
58runLuaFilter :: (MonadIO m)
59− => FilePath -> [String] -> Pandoc -> m Pandoc
59+ => Maybe FilePath -> FilePath -> [String] -> Pandoc -> m Pandoc
60−runLuaFilter filterPath args pd = liftIO $ do
60+runLuaFilter datadir filterPath args pd = liftIO $ do
61 lua <- Lua.newstate
61 lua <- Lua.newstate
62 Lua.openlibs lua
62 Lua.openlibs lua
63 -- store module in global "pandoc"
63 -- store module in global "pandoc"
64− pushPandocModule lua
64+ pushPandocModule datadir lua
65 Lua.setglobal lua "pandoc"
65 Lua.setglobal lua "pandoc"
66 top <- Lua.gettop lua
66 top <- Lua.gettop lua
67 status <- Lua.loadfile lua filterPath
67 status <- Lua.loadfile lua filterPath
src/Text/Pandoc/Lua/PandocModule.hs+5−5
@@ -41,9 +41,9 @@ import Text.Pandoc.Readers (Reader (..), getReader)
41import Text.Pandoc.Shared (readDataFile)
41import Text.Pandoc.Shared (readDataFile)
42
42
43-- | Push the "pandoc" on the lua stack.
43-- | Push the "pandoc" on the lua stack.
44−pushPandocModule :: LuaState -> IO ()
44+pushPandocModule :: Maybe FilePath -> LuaState -> IO ()
45−pushPandocModule lua = do
45+pushPandocModule datadir lua = do
46− script <- pandocModuleScript
46+ script <- pandocModuleScript datadir
47 status <- loadstring lua script "pandoc.lua"
47 status <- loadstring lua script "pandoc.lua"
48 unless (status /= 0) $ call lua 0 1
48 unless (status /= 0) $ call lua 0 1
49 push lua "__read"
49 push lua "__read"
@@ -51,8 +51,8 @@ pushPandocModule lua = do
51 rawset lua (-3)
51 rawset lua (-3)
52
52
53-- | Get the string representation of the pandoc module
53-- | Get the string representation of the pandoc module
54−pandocModuleScript :: IO String
54+pandocModuleScript :: Maybe FilePath -> IO String
55−pandocModuleScript = unpack <$> readDataFile Nothing "pandoc.lua"
55+pandocModuleScript datadir = unpack <$> readDataFile datadir "pandoc.lua"
56
56
57read_doc :: String -> String -> IO (Either String Pandoc)
57read_doc :: String -> String -> IO (Either String Pandoc)
58read_doc formatSpec content = do
58read_doc formatSpec content = do
test/Tests/Lua.hs+2−2
@@ -68,7 +68,7 @@ tests = map (localOption (QuickCheckTests 20))
68
68
69assertFilterConversion :: String -> FilePath -> Pandoc -> Pandoc -> Assertion
69assertFilterConversion :: String -> FilePath -> Pandoc -> Pandoc -> Assertion
70assertFilterConversion msg filterPath docIn docExpected = do
70assertFilterConversion msg filterPath docIn docExpected = do
71− docRes <- runLuaFilter ("lua" </> filterPath) [] docIn
71+ docRes <- runLuaFilter Nothing ("lua" </> filterPath) [] docIn
72 assertEqual msg docExpected docRes
72 assertEqual msg docExpected docRes
73
73
74roundtripEqual :: (Eq a, Lua.StackValue a) => a -> IO Bool
74roundtripEqual :: (Eq a, Lua.StackValue a) => a -> IO Bool
@@ -78,7 +78,7 @@ roundtripEqual x = (x ==) <$> roundtripped
78 roundtripped = do
78 roundtripped = do
79 lua <- Lua.newstate
79 lua <- Lua.newstate
80 Lua.openlibs lua
80 Lua.openlibs lua
81− pushPandocModule lua
81+ pushPandocModule Nothing lua
82 Lua.setglobal lua "pandoc"
82 Lua.setglobal lua "pandoc"
83 oldSize <- Lua.gettop lua
83 oldSize <- Lua.gettop lua
84 Lua.push lua x
84 Lua.push lua x