aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2017-12-23 11:53:26 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2017-12-23 13:42:35 +0100
commit35f0567a8fe840ca65f8474d0293942c76a1220f (patch)
tree7664aec1683cdec1fbf7696e449a8512978fd21a /src/Text/Pandoc
parentef4351c4d2dee9b392c80e439a3c0f0d60594a33 (diff)
downloadpandoc-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/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Lua/Module/Utils.hs10
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