diff options
author | John MacFarlane <jgm@berkeley.edu> | 2013-10-21 12:31:07 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2013-10-21 12:33:20 -0700 |
commit | 0b16b08543e87503968649e63154a629005a406f (patch) | |
tree | 0c067738452d82e16c6640d48862450818fd0e37 /src/Text/Pandoc | |
parent | f2f8ddabc876c2c4a3838448f918f9cb1cc0c1b9 (diff) | |
download | pandoc-0b16b08543e87503968649e63154a629005a406f.tar.gz |
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.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Templates.hs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Templates.hs b/src/Text/Pandoc/Templates.hs index 7f744c7e1..ad8838f72 100644 --- a/src/Text/Pandoc/Templates.hs +++ b/src/Text/Pandoc/Templates.hs @@ -117,6 +117,7 @@ import Text.Blaze (preEscapedText, Html) #endif import Data.ByteString.Lazy (ByteString, fromChunks) import Text.Pandoc.Shared (readDataFileUTF8) +import Data.Vector ((!?)) -- | Get default template for the specified writer. getDefaultTemplate :: (Maybe FilePath) -- ^ User data directory to search first @@ -185,7 +186,7 @@ var = Template . resolveVar resolveVar :: Variable -> Value -> Text resolveVar var' val = case multiLookup var' val of - Just (Array vec) -> mconcat $ map (resolveVar []) $ toList vec + Just (Array vec) -> maybe mempty (resolveVar []) $ vec !? 0 Just (String t) -> T.stripEnd t Just (Number n) -> T.pack $ show n Just (Bool True) -> "true" |