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/Module | |
parent | 113a66bd08fa4921157d95873c18c46431e565f9 (diff) | |
download | pandoc-230b133db53e8ef2677fe13304e1e03276ca6448.tar.gz |
Lua: marshal Citation values as userdata objects
Diffstat (limited to 'src/Text/Pandoc/Lua/Module')
-rw-r--r-- | src/Text/Pandoc/Lua/Module/Pandoc.hs | 23 | ||||
-rw-r--r-- | src/Text/Pandoc/Lua/Module/Types.hs | 1 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Lua/Module/Pandoc.hs b/src/Text/Pandoc/Lua/Module/Pandoc.hs index eeadfa340..bc9ddc5e5 100644 --- a/src/Text/Pandoc/Lua/Module/Pandoc.hs +++ b/src/Text/Pandoc/Lua/Module/Pandoc.hs @@ -64,6 +64,7 @@ pushModule = do pushName (functionName fn) pushDocumentedFunction fn rawset (nth 3) + forM_ otherConstructors addConstr forM_ inlineConstructors addConstr -- add constructors to Inlines.constructor newtable -- constructor @@ -165,6 +166,28 @@ mkInlinesConstr name constr = defun name <#> parameter peekFuzzyInlines "content" "Inlines" "" =#> functionResult pushInline "Inline" "new object" +otherConstructors :: LuaError e => [DocumentedFunction e] +otherConstructors = + [ defun "Citation" + ### (\cid mode mprefix msuffix mnote_num mhash -> + cid `seq` mode `seq` mprefix `seq` msuffix `seq` + mnote_num `seq` mhash `seq` return $! Citation + { citationId = cid + , citationMode = mode + , citationPrefix = fromMaybe mempty mprefix + , citationSuffix = fromMaybe mempty msuffix + , citationNoteNum = fromMaybe 0 mnote_num + , citationHash = fromMaybe 0 mhash + }) + <#> parameter peekText "string" "cid" "citation ID (e.g. bibtex key)" + <#> parameter peekRead "citation mode" "mode" "citation rendering mode" + <#> optionalParameter peekFuzzyInlines "prefix" "Inlines" "" + <#> optionalParameter peekFuzzyInlines "suffix" "Inlines" "" + <#> optionalParameter peekIntegral "note_num" "integer" "note number" + <#> optionalParameter peekIntegral "hash" "integer" "hash number" + =#> functionResult pushCitation "Citation" "new citation object" + #? "Creates a single citation." + ] walkElement :: (Walkable (SingletonsList Inline) a, Walkable (SingletonsList Block) a, diff --git a/src/Text/Pandoc/Lua/Module/Types.hs b/src/Text/Pandoc/Lua/Module/Types.hs index 7307c6e88..4a7d14d2f 100644 --- a/src/Text/Pandoc/Lua/Module/Types.hs +++ b/src/Text/Pandoc/Lua/Module/Types.hs @@ -37,7 +37,6 @@ pushCloneTable = do Lua.newtable addFunction "Attr" $ cloneWith peekAttr pushAttr addFunction "Block" $ cloneWith peekBlock pushBlock - addFunction "Citation" $ cloneWith peekCitation Lua.push addFunction "Inline" $ cloneWith peekInline pushInline addFunction "Meta" $ cloneWith peekMeta Lua.push addFunction "MetaValue" $ cloneWith peekMetaValue pushMetaValue |