Lua: use more natural representation for Reference values
Omit `false` boolean values, push integers as numbers.
This commit is contained in:
parent
993222d2c9
commit
cd2bffee1e
3 changed files with 38 additions and 7 deletions
|
@ -55,14 +55,21 @@ pushName = pushAsTable
|
|||
, ("non-dropping-particle" , pushTextOrNil . nameNonDroppingParticle)
|
||||
, ("suffix" , pushTextOrNil . nameSuffix)
|
||||
, ("literal" , pushTextOrNil . nameLiteral)
|
||||
, ("comma-suffix" , pushBool . nameCommaSuffix)
|
||||
, ("static-ordering" , pushBool . nameStaticOrdering)
|
||||
, ("comma-suffix" , pushBoolOrNil . nameCommaSuffix)
|
||||
, ("static-ordering" , pushBoolOrNil . nameStaticOrdering)
|
||||
]
|
||||
where
|
||||
pushTextOrNil = \case
|
||||
Nothing -> pushnil
|
||||
Just xs -> pushText xs
|
||||
|
||||
-- | Pushes a boolean, but uses @nil@ instead of @false@; table fields
|
||||
-- are not set unless the value is true.
|
||||
pushBoolOrNil :: Pusher e Bool
|
||||
pushBoolOrNil = \case
|
||||
False -> pushnil
|
||||
True -> pushBool True
|
||||
|
||||
-- | Pushes a 'Variable' as string.
|
||||
pushVariable :: Pusher e Variable
|
||||
pushVariable = pushText . fromVariable
|
||||
|
@ -80,14 +87,13 @@ pushVal = \case
|
|||
pushDate :: LuaError e => Pusher e Date
|
||||
pushDate = pushAsTable
|
||||
[ ("date-parts", pushPandocList pushDateParts . dateParts)
|
||||
, ("circa", pushBool . dateCirca)
|
||||
, ("circa", pushBoolOrNil . dateCirca)
|
||||
, ("season", maybe pushnil pushIntegral . dateSeason)
|
||||
, ("literal", maybe pushnil pushText . dateLiteral)
|
||||
]
|
||||
where
|
||||
-- date parts are integers, but we push them as strings, as meta
|
||||
-- values can't handle integers yet.
|
||||
pushDateParts (DateParts dp) = pushPandocList (pushString . show) dp
|
||||
-- date parts are lists of Int values
|
||||
pushDateParts (DateParts dp) = pushPandocList pushIntegral dp
|
||||
|
||||
-- | Helper funtion to push an object as a table.
|
||||
pushAsTable :: LuaError e
|
||||
|
|
|
@ -29,7 +29,7 @@ tests =
|
|||
("lua" </> "module" </> "pandoc-path.lua")
|
||||
, testPandocLua "pandoc.types"
|
||||
("lua" </> "module" </> "pandoc-types.lua")
|
||||
, testPandocLua "pandoc.util"
|
||||
, testPandocLua "pandoc.utils"
|
||||
("lua" </> "module" </> "pandoc-utils.lua")
|
||||
]
|
||||
|
||||
|
|
|
@ -62,6 +62,31 @@ return {
|
|||
end),
|
||||
},
|
||||
|
||||
group 'references' {
|
||||
test('gets references from doc', function ()
|
||||
local ref = {
|
||||
['author'] = {
|
||||
{given = 'Max', family = 'Mustermann'}
|
||||
},
|
||||
['container-title'] = pandoc.Inlines('JOSS'),
|
||||
['id'] = 'test',
|
||||
['issued'] = {['date-parts'] = {{2021}}},
|
||||
['title'] = pandoc.Inlines{
|
||||
pandoc.Quoted('DoubleQuote', 'Interesting'),
|
||||
pandoc.Space(),
|
||||
'work'
|
||||
},
|
||||
['type'] = 'article-journal',
|
||||
}
|
||||
local nocite = pandoc.Cite(
|
||||
'@test',
|
||||
{pandoc.Citation('test', 'NormalCitation')}
|
||||
)
|
||||
local doc = pandoc.Pandoc({}, {nocite = nocite, references = {ref}})
|
||||
assert.are_same({ref}, pandoc.utils.references(doc))
|
||||
end)
|
||||
},
|
||||
|
||||
group 'sha1' {
|
||||
test('hashing', function ()
|
||||
local ref_hash = '0a0a9f2a6772942557ab5355d76af442f8f65e01'
|
||||
|
|
Loading…
Reference in a new issue