summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:16:08 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:16:08 +0000
commitf4e738a6a9c21507ca6cad16125bdd96afeaf473 (patch)
treec0e97841d32680d4417b0bf44762824fc57b1855 /src/Text/Pandoc
parentdd210437f6abab19512c387ac73af1e3e44aa5ae (diff)
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/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Templates.hs22
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