git.iko.soy/typeable/pandoc
on master help sign in
Templates: Changed how array variables are resolved.

Previously if `foo` is an array (which might be because multiple values were set on the command line), `$foo$` would resolve to the concatenation of the elements of foo. This is rarely useful behavior. It has been changed so that the first value is rendered. Of course, you can still iterate over the values using `$for(foo)$`. This has the result that you can override earlier settings using -V by putting new values later on the command line. That's useful for many purposes.

commit0b16b08543e87503968649e63154a629005a406f authorJohn MacFarlane <jgm@berkeley.edu> dateMon 21 Oct 2013, 12:31 (13 years ago) parentf2f8dda
1 file changed+2−1
src/Text/Pandoc/Templates.hs+2−1
src/Text/Pandoc/Templates.hs+2−1
@@ -117,6 +117,7 @@ import Text.Blaze (preEscapedText, Html)
117117#endif
118118import Data.ByteString.Lazy (ByteString, fromChunks)
119119import Text.Pandoc.Shared (readDataFileUTF8)
120+import Data.Vector ((!?))
120121
121122-- | Get default template for the specified writer.
122123getDefaultTemplate :: (Maybe FilePath) -- ^ User data directory to search first
@@ -185,7 +186,7 @@ var = Template . resolveVar
185186resolveVar :: Variable -> Value -> Text
186187resolveVar var' val =
187188 case multiLookup var' val of
188− Just (Array vec) -> mconcat $ map (resolveVar []) $ toList vec
189+ Just (Array vec) -> maybe mempty (resolveVar []) $ vec !? 0
189190 Just (String t) -> T.stripEnd t
190191 Just (Number n) -> T.pack $ show n
191192 Just (Bool True) -> "true"