diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2017-12-23 11:53:26 +0100 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2017-12-23 13:42:35 +0100 |
commit | 35f0567a8fe840ca65f8474d0293942c76a1220f (patch) | |
tree | 7664aec1683cdec1fbf7696e449a8512978fd21a /src | |
parent | ef4351c4d2dee9b392c80e439a3c0f0d60594a33 (diff) | |
download | pandoc-35f0567a8fe840ca65f8474d0293942c76a1220f.tar.gz |
Lua modules: add function pandoc.utils.to_roman_numeral
The function allows conversion of numbers below 4000 into roman
numerals.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Lua/Module/Utils.hs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Lua/Module/Utils.hs b/src/Text/Pandoc/Lua/Module/Utils.hs index 3a3727355..3c830a4bd 100644 --- a/src/Text/Pandoc/Lua/Module/Utils.hs +++ b/src/Text/Pandoc/Lua/Module/Utils.hs @@ -30,7 +30,7 @@ module Text.Pandoc.Lua.Module.Utils ) where import Control.Applicative ((<|>)) -import Foreign.Lua (FromLuaStack, Lua, NumResults) +import Foreign.Lua (FromLuaStack, Lua, LuaInteger, NumResults) import Text.Pandoc.Definition (Pandoc, Meta, Block, Inline) import Text.Pandoc.Lua.StackInstances () import Text.Pandoc.Lua.Util (addFunction) @@ -44,6 +44,7 @@ import qualified Text.Pandoc.Shared as Shared pushModule :: Lua NumResults pushModule = do Lua.newtable + addFunction "to_roman_numeral" toRomanNumeral addFunction "sha1" sha1 addFunction "stringify" stringify return 1 @@ -53,6 +54,9 @@ sha1 :: BSL.ByteString -> Lua String sha1 = return . SHA.showDigest . SHA.sha1 +-- | Convert pandoc structure to a string with formatting removed. +-- Footnotes are skipped (since we don't want their contents in link +-- labels). stringify :: AstElement -> Lua String stringify el = return $ case el of PandocElement pd -> Shared.stringify pd @@ -77,3 +81,7 @@ instance FromLuaStack AstElement where Right x -> return x Left _ -> Lua.throwLuaError "Expected an AST element, but could not parse value as such." + +-- | Convert a number < 4000 to uppercase roman numeral. +toRomanNumeral :: LuaInteger -> Lua String +toRomanNumeral = return . Shared.toRomanNumeral . fromIntegral |