@@ -47,7 +47,7 @@ import Text.Pandoc.Class (readDataFile, runIO,
47import Text.Pandoc.Options (ReaderOptions(readerExtensions))
47import Text.Pandoc.Options (ReaderOptions(readerExtensions))
48import Text.Pandoc.Lua.StackInstances ()
48import Text.Pandoc.Lua.StackInstances ()
49import Text.Pandoc.Readers (Reader (..), getReader)
49import Text.Pandoc.Readers (Reader (..), getReader)
50−import Text.Pandoc.MIME (MimeType, extensionFromMimeType)
50+import Text.Pandoc.MIME (MimeType)
51import Data.Digest.Pure.SHA (sha1, showDigest)
51import Data.Digest.Pure.SHA (sha1, showDigest)
53import qualified Foreign.Lua as Lua
53import qualified Foreign.Lua as Lua
@@ -93,7 +93,7 @@ pushMediaBagModule commonState mediaBagRef = do
93 addFunction "lookup" (lookupMediaFn mediaBagRef)
93 addFunction "lookup" (lookupMediaFn mediaBagRef)
94 addFunction "list" (mediaDirectoryFn mediaBagRef)
94 addFunction "list" (mediaDirectoryFn mediaBagRef)
95 addFunction "fetch" (fetch commonState mediaBagRef)
95 addFunction "fetch" (fetch commonState mediaBagRef)
96− addFunction "hashname" hashnameFn
96+ addFunction "sha1" sha1HashFn
99 addFunction name fn = do
99 addFunction name fn = do
@@ -101,20 +101,12 @@ pushMediaBagModule commonState mediaBagRef = do
101 Lua.pushHaskellFunction fn
101 Lua.pushHaskellFunction fn
102 Lua.rawset (-3)
102 Lua.rawset (-3)
104−hashnameFn :: OrNil MimeType
105− -> BL.ByteString
104+sha1HashFn :: BL.ByteString
106 -> Lua NumResults
105 -> Lua NumResults
107−hashnameFn nilOrMime contents = do
106+sha1HashFn contents = do
108− Lua.push (getHashname (toMaybe nilOrMime) contents)
107+ Lua.push $ showDigest (sha1 contents)
111−getHashname :: Maybe MimeType -> BL.ByteString -> String
112−getHashname mbMime bs =
113− let ext = fromMaybe ""
114− (('.':) <$> (mbMime >>= extensionFromMimeType))
115− basename = showDigest $ sha1 bs
118insertMediaFn :: IORef MB.MediaBag
110insertMediaFn :: IORef MB.MediaBag
119 -> FilePath
111 -> FilePath
120 -> OrNil MimeType
112 -> OrNil MimeType