From f4e738a6a9c21507ca6cad16125bdd96afeaf473 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Thu, 31 Dec 2009 01:16:08 +0000 Subject: 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 --- src/Text/Pandoc/Templates.hs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/Text/Pandoc') 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 -- cgit v1.2.3