git.iko.soy/typeable/pandoc
on master help sign in
data/pandoc.lua: fix attribute names of Citation

The fields were named like the Haskell fields, not like the documented, shorter version. The names are changed to match the documentation and Citations are given a shared metatable to enable simple extensibility. Fixes: #4222

commit4f564b92030168a5416f8ca07530d189f3a6f277 authorAlbert Krewinkel <albert@zeitkraut.de> dateFri 5 Jan 2018, 08:15 (9 years ago) parent856bc54
2 files changed+21−19
data/pandoc.lua+15−13 src/Text/Pandoc/Lua/StackInstances.hs+6−6
data/pandoc.lua+15−13
@@ -764,6 +764,8 @@ M.Attr.__newindex = function(t, k, v)
764764end
765765setmetatable(M.Attr, M.Attr)
766766
767+-- Citation
768+M.Citation = {}
767769
768770--- Creates a single citation.
769771-- @function Citation
@@ -773,20 +775,20 @@ setmetatable(M.Attr, M.Attr)
773775-- @tparam[opt] {Inline,...} suffix citation suffix
774776-- @tparam[opt] int note_num note number
775777-- @tparam[opt] int hash hash number
776−M.Citation = function(id, mode, prefix, suffix, note_num, hash)
777− prefix = prefix or {}
778− suffix = suffix or {}
779− note_num = note_num or 0
780− hash = hash or 0
781− return {
782− citationId = id,
783− citationPrefix = prefix,
784− citationSuffix = suffix,
785− citationMode = mode,
786− citationNoteNum = note_num,
787− citationHash = hash,
788− }
778+M.Citation.__call = function(t, id, mode, prefix, suffix, note_num, hash)
779+ return setmetatable(
780+ {
781+ id = id,
782+ mode = mode,
783+ prefix = prefix or {},
784+ suffix = suffix or {},
785+ note_num = note_num or 0,
786+ hash = hash or 0,
787+ },
788+ t
789+ )
789790end
791+setmetatable(M.Citation, M.Citation)
790792
791793
792794------------------------------------------------------------------------
src/Text/Pandoc/Lua/StackInstances.hs+6−6
@@ -84,12 +84,12 @@ instance ToLuaStack Citation where
8484
8585instance FromLuaStack Citation where
8686 peek idx = do
87− id' <- getTable idx "citationId"
88− prefix <- getTable idx "citationPrefix"
89− suffix <- getTable idx "citationSuffix"
90− mode <- getTable idx "citationMode"
91− num <- getTable idx "citationNoteNum"
92− hash <- getTable idx "citationHash"
87+ id' <- getTable idx "id"
88+ prefix <- getTable idx "prefix"
89+ suffix <- getTable idx "suffix"
90+ mode <- getTable idx "mode"
91+ num <- getTable idx "note_num"
92+ hash <- getTable idx "hash"
9393 return $ Citation id' prefix suffix mode num hash
9494
9595instance ToLuaStack Alignment where