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.
This commit is contained in:
parent
f2f8ddabc8
commit
0b16b08543
1 changed files with 2 additions and 1 deletions
|
@ -117,6 +117,7 @@ import Text.Blaze (preEscapedText, Html)
|
||||||
#endif
|
#endif
|
||||||
import Data.ByteString.Lazy (ByteString, fromChunks)
|
import Data.ByteString.Lazy (ByteString, fromChunks)
|
||||||
import Text.Pandoc.Shared (readDataFileUTF8)
|
import Text.Pandoc.Shared (readDataFileUTF8)
|
||||||
|
import Data.Vector ((!?))
|
||||||
|
|
||||||
-- | Get default template for the specified writer.
|
-- | Get default template for the specified writer.
|
||||||
getDefaultTemplate :: (Maybe FilePath) -- ^ User data directory to search first
|
getDefaultTemplate :: (Maybe FilePath) -- ^ User data directory to search first
|
||||||
|
@ -185,7 +186,7 @@ var = Template . resolveVar
|
||||||
resolveVar :: Variable -> Value -> Text
|
resolveVar :: Variable -> Value -> Text
|
||||||
resolveVar var' val =
|
resolveVar var' val =
|
||||||
case multiLookup var' val of
|
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 (String t) -> T.stripEnd t
|
||||||
Just (Number n) -> T.pack $ show n
|
Just (Number n) -> T.pack $ show n
|
||||||
Just (Bool True) -> "true"
|
Just (Bool True) -> "true"
|
||||||
|
|
Loading…
Reference in a new issue