diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2021-10-24 22:49:34 +0200 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2021-10-25 09:08:58 +0200 |
commit | 230b133db53e8ef2677fe13304e1e03276ca6448 (patch) | |
tree | bada7875937f7d4f7d2c98d6ea4c0d169dc37dcd /src/Text/Pandoc/Lua/Marshaling | |
parent | 113a66bd08fa4921157d95873c18c46431e565f9 (diff) | |
download | pandoc-230b133db53e8ef2677fe13304e1e03276ca6448.tar.gz |
Lua: marshal Citation values as userdata objects
Diffstat (limited to 'src/Text/Pandoc/Lua/Marshaling')
-rw-r--r-- | src/Text/Pandoc/Lua/Marshaling/AST.hs | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/src/Text/Pandoc/Lua/Marshaling/AST.hs b/src/Text/Pandoc/Lua/Marshaling/AST.hs index 5791b39c1..e436ffffc 100644 --- a/src/Text/Pandoc/Lua/Marshaling/AST.hs +++ b/src/Text/Pandoc/Lua/Marshaling/AST.hs @@ -37,6 +37,7 @@ module Text.Pandoc.Lua.Marshaling.AST , pushAttr , pushBlock + , pushCitation , pushInline , pushListAttributes , pushMetaValue @@ -109,24 +110,35 @@ instance Pushable Inline where instance Pushable Citation where push = pushCitation -pushCitation :: LuaError e => Pusher e Citation -pushCitation (Citation cid prefix suffix mode noteNum hash) = - pushViaConstr' "Citation" - [ push cid, push mode, push prefix, push suffix, push noteNum, push hash +typeCitation :: LuaError e => DocumentedType e Citation +typeCitation = deftype "Citation" [] + [ property "id" "citation ID / key" + (pushText, citationId) + (peekText, \citation cid -> citation{ citationId = cid }) + , property "mode" "citation mode" + (pushString . show, citationMode) + (peekRead, \citation mode -> citation{ citationMode = mode }) + , property "prefix" "citation prefix" + (pushInlines, citationPrefix) + (peekInlines, \citation prefix -> citation{ citationPrefix = prefix }) + , property "suffix" "citation suffix" + (pushInlines, citationSuffix) + (peekInlines, \citation suffix -> citation{ citationPrefix = suffix }) + , property "note_num" "note number" + (pushIntegral, citationNoteNum) + (peekIntegral, \citation noteNum -> citation{ citationNoteNum = noteNum }) + , property "hash" "hash number" + (pushIntegral, citationHash) + (peekIntegral, \citation hash -> citation{ citationHash = hash }) + , method $ defun "clone" ### return <#> udparam typeCitation "obj" "" + =#> functionResult pushCitation "Citation" "copy of obj" ] -peekCitation :: LuaError e => Peeker e Citation -peekCitation = fmap (retrieving "Citation") - . typeChecked "table" Lua.istable $ \idx -> do - idx' <- liftLua $ absindex idx - Citation - <$!> peekFieldRaw peekText "id" idx' - <*> peekFieldRaw (peekList peekInline) "prefix" idx' - <*> peekFieldRaw (peekList peekInline) "suffix" idx' - <*> peekFieldRaw peekRead "mode" idx' - <*> peekFieldRaw peekIntegral "note_num" idx' - <*> peekFieldRaw peekIntegral "hash" idx' +pushCitation :: LuaError e => Pusher e Citation +pushCitation = pushUD typeCitation +peekCitation :: LuaError e => Peeker e Citation +peekCitation = peekUD typeCitation instance Pushable Alignment where push = Lua.pushString . show @@ -289,6 +301,9 @@ peekBlocks = peekList peekBlock peekInlines :: LuaError e => Peeker e [Inline] peekInlines = peekList peekInline +pushInlines :: LuaError e => Pusher e [Inline] +pushInlines = pushPandocList pushInline + -- | Push Caption element pushCaption :: LuaError e => Caption -> LuaE e () pushCaption (Caption shortCaption longCaption) = do |