diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2021-12-20 09:28:38 +0100 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2021-12-20 09:41:03 +0100 |
commit | cd2bffee1e4c0ca9c999bd37f81732664f9f107a (patch) | |
tree | 88822fe1d8ac78a476a8025cf5562ac24ae74c8d /src/Text/Pandoc/Lua | |
parent | 993222d2c9c94cbf51f06528b79ffddd56b9da46 (diff) | |
download | pandoc-cd2bffee1e4c0ca9c999bd37f81732664f9f107a.tar.gz |
Lua: use more natural representation for Reference values
Omit `false` boolean values, push integers as numbers.
Diffstat (limited to 'src/Text/Pandoc/Lua')
-rw-r--r-- | src/Text/Pandoc/Lua/Marshal/Reference.hs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Lua/Marshal/Reference.hs b/src/Text/Pandoc/Lua/Marshal/Reference.hs index 51501836f..ee297484e 100644 --- a/src/Text/Pandoc/Lua/Marshal/Reference.hs +++ b/src/Text/Pandoc/Lua/Marshal/Reference.hs @@ -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 |