@@ -0,0 +1,50 @@
1+{-
2+Copyright © 2017 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
3+
4+This program is free software; you can redistribute it and/or modify
5+it under the terms of the GNU General Public License as published by
6+the Free Software Foundation; either version 2 of the License, or
7+(at your option) any later version.
8+
9+This program is distributed in the hope that it will be useful,
10+but WITHOUT ANY WARRANTY; without even the implied warranty of
11+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+GNU General Public License for more details.
13+
14+You should have received a copy of the GNU General Public License
15+along with this program; if not, write to the Free Software
16+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+-}
18+{- |
19+ Module : Text.Pandoc.Lua.Module.Utils
20+ Copyright : Copyright © 2017 Albert Krewinkel
21+ License : GNU GPL, version 2 or above
22+
23+ Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
24+ Stability : alpha
25+
26+Utility module for lua, exposing internal helper functions.
27+-}
28+module Text.Pandoc.Lua.Module.Utils
29+ ( pushModule
30+ ) where
31+
32+import Data.Digest.Pure.SHA (sha1, showDigest)
33+import Foreign.Lua (Lua, NumResults)
34+import Text.Pandoc.Lua.StackInstances ()
35+import Text.Pandoc.Lua.Util (addFunction)
36+
37+import qualified Data.ByteString.Lazy as BSL
38+import qualified Foreign.Lua as Lua
39+
40+-- | Push the "pandoc.utils" module to the lua stack.
41+pushModule :: Lua NumResults
42+pushModule = do
43+ Lua.newtable
44+ addFunction "sha1" sha1HashFn
45+ return 1
46+
47+-- | Calculate the hash of the given contents.
48+sha1HashFn :: BSL.ByteString
49+ -> Lua String
50+sha1HashFn = return . showDigest . sha1