@@ -30,7 +30,7 @@ module Text.Pandoc.Lua.Module.Utils
32import Control.Applicative ((<|>))
32import Control.Applicative ((<|>))
33−import Foreign.Lua (FromLuaStack, Lua, NumResults)
33+import Foreign.Lua (FromLuaStack, Lua, LuaInteger, NumResults)
34import Text.Pandoc.Definition (Pandoc, Meta, Block, Inline)
34import Text.Pandoc.Definition (Pandoc, Meta, Block, Inline)
35import Text.Pandoc.Lua.StackInstances ()
35import Text.Pandoc.Lua.StackInstances ()
36import Text.Pandoc.Lua.Util (addFunction)
36import Text.Pandoc.Lua.Util (addFunction)
@@ -44,6 +44,7 @@ import qualified Text.Pandoc.Shared as Shared
44pushModule :: Lua NumResults
44pushModule :: Lua NumResults
45pushModule = do
45pushModule = do
46 Lua.newtable
46 Lua.newtable
47+ addFunction "to_roman_numeral" toRomanNumeral
47 addFunction "sha1" sha1
48 addFunction "sha1" sha1
48 addFunction "stringify" stringify
49 addFunction "stringify" stringify
@@ -53,6 +54,9 @@ sha1 :: BSL.ByteString
53 -> Lua String
54 -> Lua String
54sha1 = return . SHA.showDigest . SHA.sha1
55sha1 = return . SHA.showDigest . SHA.sha1
57+-- | Convert pandoc structure to a string with formatting removed.
58+-- Footnotes are skipped (since we don't want their contents in link
56stringify :: AstElement -> Lua String
60stringify :: AstElement -> Lua String
57stringify el = return $ case el of
61stringify el = return $ case el of
58 PandocElement pd -> Shared.stringify pd
62 PandocElement pd -> Shared.stringify pd
@@ -77,3 +81,7 @@ instance FromLuaStack AstElement where
77 Right x -> return x
81 Right x -> return x
78 Left _ -> Lua.throwLuaError
82 Left _ -> Lua.throwLuaError
79 "Expected an AST element, but could not parse value as such."
83 "Expected an AST element, but could not parse value as such."
85+-- | Convert a number < 4000 to uppercase roman numeral.
86+toRomanNumeral :: LuaInteger -> Lua String
87+toRomanNumeral = return . Shared.toRomanNumeral . fromIntegral