aboutsummaryrefslogtreecommitdiff
path: root/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2026-01-08 17:29:39 +0100
committerAlbert Krewinkel <[email protected]>2026-01-08 17:55:04 +0100
commitcb8739f5b079ad5d73be6601eb7dd62c61c533a1 (patch)
tree27b6c4ffba933c8f83ebd97cbde712276e3f020c /pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs
parent8123be654d6ece208df32afc26b4fe1629e78ffd (diff)
Lua: switch to HsLua 2.5
Diffstat (limited to 'pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs')
-rw-r--r--pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs69
1 files changed, 27 insertions, 42 deletions
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs
index 9e6d033d4..cf4325b17 100644
--- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs
+++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Pandoc.hs
@@ -63,17 +63,15 @@ import qualified Data.Text as T
import qualified Text.Pandoc.UTF8 as UTF8
documentedModule :: Module PandocError
-documentedModule = Module
- { moduleName = "pandoc"
- , moduleDescription = T.unlines
+documentedModule = defmodule "pandoc"
+ `withDescription` T.unlines
[ "Fields and functions for pandoc scripts; includes constructors for"
, "document tree elements, functions to parse text in a given"
, "format, and functions to filter and modify a subtree."
]
- , moduleFields = readersField : writersField :
+ `withFields` readersField : writersField :
stringConstants ++ [inlineField, blockField]
- , moduleOperations = []
- , moduleFunctions = mconcat
+ `withFunctions` mconcat
[ [mkPandoc, mkMeta]
, metaValueConstructors
, blockConstructors
@@ -83,25 +81,20 @@ documentedModule = Module
, otherConstructors
, functions
]
- , moduleTypeInitializers =
- [ initType typePandoc
- , initType typeBlock
- , initType typeInline
- ]
- }
+ `associateType` typePandoc
+ `associateType` typeBlock
+ `associateType` typeInline
-- | Set of input formats accepted by @read@.
readersField :: Field PandocError
-readersField = Field
- { fieldName = "readers"
- , fieldType = "table"
- , fieldDescription = T.unlines
+readersField = deffield "readers"
+ `withType` "table"
+ `withDescription` T.unlines
[ "Set of formats that pandoc can parse. All keys in this table can"
, "be used as the `format` value in `pandoc.read`."
]
- , fieldPushValue = pushKeyValuePairs pushText (pushText . readerType)
+ `withValue` pushKeyValuePairs pushText (pushText . readerType)
(readers @PandocLua)
- }
where
readerType = \case
TextReader {} -> "text"
@@ -109,16 +102,14 @@ readersField = Field
-- | Set of input formats accepted by @write@.
writersField :: Field PandocError
-writersField = Field
- { fieldName = "writers"
- , fieldType = "table"
- , fieldDescription = T.unlines
+writersField = deffield "writers"
+ `withType` "table"
+ `withDescription` T.unlines
[ "Set of formats that pandoc can generate. All keys in this table"
, "can be used as the `format` value in `pandoc.write`."
]
- , fieldPushValue = pushKeyValuePairs pushText (pushText . writerType)
+ `withValue` pushKeyValuePairs pushText (pushText . writerType)
(writers @PandocLua)
- }
where
writerType = \case
TextWriter {} -> "text"
@@ -126,25 +117,21 @@ writersField = Field
-- | Inline table field
inlineField :: Field PandocError
-inlineField = Field
- { fieldName = "Inline"
- , fieldType = "table"
- , fieldDescription = "Inline constructors, nested under 'constructors'."
+inlineField = deffield "Inline"
+ `withType` "table"
+ `withDescription` "Inline constructors, nested under 'constructors'."
-- the nesting happens for historical reasons and should probably be
-- changed.
- , fieldPushValue = pushWithConstructorsSubtable inlineConstructors
- }
+ `withValue` pushWithConstructorsSubtable inlineConstructors
-- | @Block@ module field
blockField :: Field PandocError
-blockField = Field
- { fieldName = "Block"
- , fieldType = "table"
- , fieldDescription = "Inline constructors, nested under 'constructors'."
+blockField = deffield "Block"
+ `withType` "table"
+ `withDescription` "Inline constructors, nested under 'constructors'."
-- the nesting happens for historical reasons and should probably be
-- changed.
- , fieldPushValue = pushWithConstructorsSubtable blockConstructors
- }
+ `withValue` pushWithConstructorsSubtable blockConstructors
pushWithConstructorsSubtable :: [DocumentedFunction PandocError]
-> LuaE PandocError ()
@@ -222,12 +209,10 @@ stringConstants =
, constrs (Proxy @Alignment)
, constrs (Proxy @CitationMode)
]
- toField s = Field
- { fieldName = T.pack s
- , fieldType = "string"
- , fieldDescription = T.pack s
- , fieldPushValue = pushString s
- }
+ toField s = deffield (Name $ UTF8.fromString s)
+ `withType` "string"
+ `withDescription` T.pack s
+ `withValue` pushString s
in map toField nullaryConstructors
functions :: [DocumentedFunction PandocError]