aboutsummaryrefslogtreecommitdiff
path: root/pandoc-lua-engine/src
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2025-08-10 12:04:24 +0200
committerAlbert Krewinkel <[email protected]>2025-08-12 08:47:49 +0200
commit68d80cc9d914c23831aace776f0d5c981fd882e9 (patch)
treedd1d65de1e52397352799b7f8ed14befd4ea158e /pandoc-lua-engine/src
parent511ddc322339f40f30c173568da26c4296722cb5 (diff)
Lua: add functions `pandoc.text.superscript` and `subscript`.
The functions convert numbers and parentheses to superscript and subscript, respectively.
Diffstat (limited to 'pandoc-lua-engine/src')
-rw-r--r--pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Text.hs29
1 files changed, 29 insertions, 0 deletions
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Text.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Text.hs
index d83dd8014..8c43df526 100644
--- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Text.hs
+++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Text.hs
@@ -15,6 +15,7 @@ import Data.Version (makeVersion)
import HsLua
import Text.Pandoc.Error (PandocError)
import Text.Pandoc.Lua.PandocLua ()
+import Text.Pandoc.Writers.Shared (toSubscript, toSuperscript)
import qualified Data.Text as T
import qualified HsLua.Module.Text as TM
@@ -29,6 +30,8 @@ documentedModule = TM.documentedModule
, TM.lower `since` v[2,0,3]
, TM.reverse `since` v[2,0,3]
, TM.sub `since` v[2,0,3]
+ , subscript `since` v[3,8]
+ , superscript `since` v[3,8]
, TM.toencoding `since` v[3,0]
, TM.upper `since` v[2,0,3]
]
@@ -49,3 +52,29 @@ documentedModule = TM.documentedModule
}
where
v = makeVersion
+
+-- | Convert all chars in a string to Unicode subscript.
+subscript :: LuaError e => DocumentedFunction e
+subscript = defun "subscript"
+ ### pure . traverse toSubscript
+ <#> stringParam "input" "string to convert to subscript characters"
+ =#> functionResult (maybe pushnil pushString) "string|nil"
+ "Subscript version of the input, or `nil` if not all characters\
+ \ could be converted."
+ #? "Tries to convert the string into a Unicode subscript version of the\
+ \ string. Returns `nil` if not all characters of the input can be\
+ \ mapped to a subscript Unicode character.\
+ \ Supported characters include numbers, parentheses, and plus/minus."
+
+-- | Convert all chars in a string to Unicode superscript.
+superscript :: LuaError e => DocumentedFunction e
+superscript = defun "superscript"
+ ### pure . traverse toSuperscript
+ <#> stringParam "input" "string to convert to superscript characters"
+ =#> functionResult (maybe pushnil pushString) "string|nil"
+ "Superscript version of the input, or `nil` if not all characters\
+ \ could be converted."
+ #? "Tries to convert the string into a Unicode superscript version of the\
+ \ string. Returns `nil` if not all characters of the input can be\
+ \ mapped to a superscript Unicode character.\
+ \ Supported characters include numbers, parentheses, and plus/minus."