diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-12-31 01:16:08 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-12-31 01:16:08 +0000 |
commit | f4e738a6a9c21507ca6cad16125bdd96afeaf473 (patch) | |
tree | c0e97841d32680d4417b0bf44762824fc57b1855 /src | |
parent | dd210437f6abab19512c387ac73af1e3e44aa5ae (diff) | |
download | pandoc-f4e738a6a9c21507ca6cad16125bdd96afeaf473.tar.gz |
Fixed bug with $else$ in templates module.
We need to be sure we parse the else block even if the
if condition is satisfied.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1724 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Templates.hs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Templates.hs b/src/Text/Pandoc/Templates.hs index 548bf7db5..03055735a 100644 --- a/src/Text/Pandoc/Templates.hs +++ b/src/Text/Pandoc/Templates.hs @@ -149,21 +149,21 @@ conditional = try $ do string ")$" -- if newline after the "if", then a newline after "endif" will be swallowed multiline <- option False $ try $ skipEndline >> return True + ifContents <- liftM concat parseTemplate + -- reset state for else block + setState $ TemplateState pos vars + elseContents <- option "" $ do try (string "$else$") + when multiline $ optional skipEndline + liftM concat parseTemplate + string "$endif$" + when multiline $ optional skipEndline let conditionSatisfied = case lookup id' vars of Nothing -> False Just "" -> False Just _ -> True - contents <- if conditionSatisfied - then liftM concat parseTemplate - else do - parseTemplate -- skip if part, then reset position - setState $ TemplateState pos vars - option "" $ do try (string "$else$") - when multiline $ optional skipEndline - liftM concat parseTemplate - string "$endif$" - when multiline $ optional skipEndline - return contents + return $ if conditionSatisfied + then ifContents + else elseContents for :: GenParser Char TemplateState String for = try $ do |