git.iko.soy/typeable/pandoc
on master help sign in
Lua: make lua.mediabag.fetch return filename and mime type.
73c47a4John MacFarlane
doc/lua-filters.md+3−1
@@ -1133,7 +1133,9 @@ storage. The "media bag" is used when pandoc is called with the
1133[`fetch (source, base_url)`]{#mediabag-fetch}
1133[`fetch (source, base_url)`]{#mediabag-fetch}
1134
1134
1135: Fetches the given source and inserts it into the media bag
1135: Fetches the given source and inserts it into the media bag
1136− using a SHA1 hash of the content as filename.
1136+ using a SHA1 hash of the content as filename. Returns two
1137+ values: the filename (based on SHA1 hash) and the mime
1138+ type (or an empty string).
1137
1139
1138 Usage:
1140 Usage:
1139
1141
src/Text/Pandoc/Lua/PandocModule.hs+4
@@ -38,6 +38,7 @@ import Control.Monad (unless, zipWithM_)
38import Data.ByteString.Char8 (unpack)
38import Data.ByteString.Char8 (unpack)
39import Data.Default (Default (..))
39import Data.Default (Default (..))
40import Data.IORef
40import Data.IORef
41+import Data.Maybe (fromMaybe)
41import Data.Text (pack)
42import Data.Text (pack)
42import Foreign.Lua (Lua, FromLuaStack, ToLuaStack, NumResults, liftIO)
43import Foreign.Lua (Lua, FromLuaStack, ToLuaStack, NumResults, liftIO)
43import Text.Pandoc.Class (fetchMediaResource, readDataFile, runIO,
44import Text.Pandoc.Class (fetchMediaResource, readDataFile, runIO,
@@ -146,6 +147,9 @@ insertResource commonState mbRef src = do
146 fetchMediaResource src
147 fetchMediaResource src
147 liftIO $ print (fp, mimeType) -- TODO DEBUG
148 liftIO $ print (fp, mimeType) -- TODO DEBUG
148 insertMediaFn mbRef fp (OrNil mimeType) bs
149 insertMediaFn mbRef fp (OrNil mimeType) bs
150+ Lua.push fp
151+ Lua.push $ fromMaybe "" mimeType
152+ return 2 -- returns 2 values: name in mediabag, mimetype
149
153
150--
154--
151-- Helper types and orphan instances
155-- Helper types and orphan instances