git.iko.soy/typeable/pandoc
on master help sign in
Lua: make lua.mediabag.fetch return filename and mime type.

This is necessary because you may need to insert the filename into an image or link element.

commit73c47a44d86f5075e3635e90574de12ac5f0b2eb authorJohn MacFarlane <jgm@berkeley.edu> dateSat 30 Sep 2017, 21:58 (9 years ago) parent896c288
2 files changed+7−1
doc/lua-filters.md+3−1 src/Text/Pandoc/Lua/PandocModule.hs+4
doc/lua-filters.md+3−1
@@ -1133,7 +1133,9 @@ storage. The "media bag" is used when pandoc is called with the
11331133[`fetch (source, base_url)`]{#mediabag-fetch}
11341134
11351135: 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).
11371139
11381140 Usage:
11391141
src/Text/Pandoc/Lua/PandocModule.hs+4
@@ -38,6 +38,7 @@ import Control.Monad (unless, zipWithM_)
3838import Data.ByteString.Char8 (unpack)
3939import Data.Default (Default (..))
4040import Data.IORef
41+import Data.Maybe (fromMaybe)
4142import Data.Text (pack)
4243import Foreign.Lua (Lua, FromLuaStack, ToLuaStack, NumResults, liftIO)
4344import Text.Pandoc.Class (fetchMediaResource, readDataFile, runIO,
@@ -146,6 +147,9 @@ insertResource commonState mbRef src = do
146147 fetchMediaResource src
147148 liftIO $ print (fp, mimeType) -- TODO DEBUG
148149 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
149153
150154--
151155-- Helper types and orphan instances