aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Shared.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 31730a9e7..d6663f193 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -65,6 +65,7 @@ module Text.Pandoc.Shared (
makeMeta,
metaToJSON,
setField,
+ defField,
-- * TagSoup HTML handling
renderTags',
-- * File handling
@@ -562,6 +563,19 @@ setField field val (Object hashmap) =
_ -> toJSON [oldval, newval]
setField _ _ x = x
+defField :: ToJSON a
+ => String
+ -> a
+ -> Value
+ -> Value
+-- | Set a field of a JSON object if it currently has no value.
+-- If it has a value, do nothing.
+-- This is a utility function to be used in preparing template contexts.
+defField field val (Object hashmap) =
+ Object $ H.insertWith f (T.pack field) (toJSON val) hashmap
+ where f _newval oldval = oldval
+defField _ _ x = x
+
--
-- TagSoup HTML handling
--