@@ -30,7 +30,7 @@ module Text.Pandoc.Lua.Module.Utils
3030 ) where
3131
3232import Control.Applicative ((<|>))
33−import Foreign.Lua (FromLuaStack, Lua, NumResults)
33+import Foreign.Lua (FromLuaStack, Lua, LuaInteger, NumResults)
3434import Text.Pandoc.Definition (Pandoc, Meta, Block, Inline)
3535import Text.Pandoc.Lua.StackInstances ()
3636import Text.Pandoc.Lua.Util (addFunction)
@@ -44,6 +44,7 @@ import qualified Text.Pandoc.Shared as Shared
4444pushModule :: Lua NumResults
4545pushModule = do
4646 Lua.newtable
47+ addFunction "to_roman_numeral" toRomanNumeral
4748 addFunction "sha1" sha1
4849 addFunction "stringify" stringify
4950 return 1
@@ -53,6 +54,9 @@ sha1 :: BSL.ByteString
5354 -> Lua String
5455sha1 = return . SHA.showDigest . SHA.sha1
5556
57+-- | Convert pandoc structure to a string with formatting removed.
58+-- Footnotes are skipped (since we don't want their contents in link
59+-- labels).
5660stringify :: AstElement -> Lua String
5761stringify el = return $ case el of
5862 PandocElement pd -> Shared.stringify pd
@@ -77,3 +81,7 @@ instance FromLuaStack AstElement where
7781 Right x -> return x
7882 Left _ -> Lua.throwLuaError
7983 "Expected an AST element, but could not parse value as such."
84+
85+-- | Convert a number < 4000 to uppercase roman numeral.
86+toRomanNumeral :: LuaInteger -> Lua String
87+toRomanNumeral = return . Shared.toRomanNumeral . fromIntegral