summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-09-30 23:15:43 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-09-30 23:15:43 -0700
commit8768f7e5b060b4024d88d12f4255d515dd4ca7fa (patch)
tree4328fd18fda9b3ddcfa76198d276479f151d043b /src/Text/Pandoc
parent9451d83058fa0b237514e618ebe6140a69fe13db (diff)
Lua: use sha1 instead of hashname.
Better to leave control over the extension to the user.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Lua/PandocModule.hs18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Lua/PandocModule.hs b/src/Text/Pandoc/Lua/PandocModule.hs
index a54e54c09..5d826883d 100644
--- a/src/Text/Pandoc/Lua/PandocModule.hs
+++ b/src/Text/Pandoc/Lua/PandocModule.hs
@@ -47,7 +47,7 @@ import Text.Pandoc.Class (readDataFile, runIO,
import Text.Pandoc.Options (ReaderOptions(readerExtensions))
import Text.Pandoc.Lua.StackInstances ()
import Text.Pandoc.Readers (Reader (..), getReader)
-import Text.Pandoc.MIME (MimeType, extensionFromMimeType)
+import Text.Pandoc.MIME (MimeType)
import Data.Digest.Pure.SHA (sha1, showDigest)
import qualified Foreign.Lua as Lua
@@ -93,7 +93,7 @@ pushMediaBagModule commonState mediaBagRef = do
addFunction "lookup" (lookupMediaFn mediaBagRef)
addFunction "list" (mediaDirectoryFn mediaBagRef)
addFunction "fetch" (fetch commonState mediaBagRef)
- addFunction "hashname" hashnameFn
+ addFunction "sha1" sha1HashFn
return ()
where
addFunction name fn = do
@@ -101,20 +101,12 @@ pushMediaBagModule commonState mediaBagRef = do
Lua.pushHaskellFunction fn
Lua.rawset (-3)
-hashnameFn :: OrNil MimeType
- -> BL.ByteString
+sha1HashFn :: BL.ByteString
-> Lua NumResults
-hashnameFn nilOrMime contents = do
- Lua.push (getHashname (toMaybe nilOrMime) contents)
+sha1HashFn contents = do
+ Lua.push $ showDigest (sha1 contents)
return 1
-getHashname :: Maybe MimeType -> BL.ByteString -> String
-getHashname mbMime bs =
- let ext = fromMaybe ""
- (('.':) <$> (mbMime >>= extensionFromMimeType))
- basename = showDigest $ sha1 bs
- in basename ++ ext
-
insertMediaFn :: IORef MB.MediaBag
-> FilePath
-> OrNil MimeType