aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-09-30 21:58:35 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-09-30 21:58:35 -0700
commit73c47a44d86f5075e3635e90574de12ac5f0b2eb (patch)
treea91cd0e30727c2e0c8b3cec4c7092abea7732712
parent896c288625a8c48e290fe86e90b65109bd4fce9f (diff)
downloadpandoc-73c47a44d86f5075e3635e90574de12ac5f0b2eb.tar.gz
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.
-rw-r--r--doc/lua-filters.md4
-rw-r--r--src/Text/Pandoc/Lua/PandocModule.hs4
2 files changed, 7 insertions, 1 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md
index d17c44adf..e1007f452 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -1133,7 +1133,9 @@ storage. The "media bag" is used when pandoc is called with the
[`fetch (source, base_url)`]{#mediabag-fetch}
: Fetches the given source and inserts it into the media bag
- using a SHA1 hash of the content as filename.
+ using a SHA1 hash of the content as filename. Returns two
+ values: the filename (based on SHA1 hash) and the mime
+ type (or an empty string).
Usage:
diff --git a/src/Text/Pandoc/Lua/PandocModule.hs b/src/Text/Pandoc/Lua/PandocModule.hs
index bf45cab17..a110905e5 100644
--- a/src/Text/Pandoc/Lua/PandocModule.hs
+++ b/src/Text/Pandoc/Lua/PandocModule.hs
@@ -38,6 +38,7 @@ import Control.Monad (unless, zipWithM_)
import Data.ByteString.Char8 (unpack)
import Data.Default (Default (..))
import Data.IORef
+import Data.Maybe (fromMaybe)
import Data.Text (pack)
import Foreign.Lua (Lua, FromLuaStack, ToLuaStack, NumResults, liftIO)
import Text.Pandoc.Class (fetchMediaResource, readDataFile, runIO,
@@ -146,6 +147,9 @@ insertResource commonState mbRef src = do
fetchMediaResource src
liftIO $ print (fp, mimeType) -- TODO DEBUG
insertMediaFn mbRef fp (OrNil mimeType) bs
+ Lua.push fp
+ Lua.push $ fromMaybe "" mimeType
+ return 2 -- returns 2 values: name in mediabag, mimetype
--
-- Helper types and orphan instances