git.iko.soy/typeable/pandoc
on master help sign in
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

commitf4e738a6a9c21507ca6cad16125bdd96afeaf473 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 31 Dec 2009, 01:16 (17 years ago) parentdd21043
1 file changed+11−11
src/Text/Pandoc/Templates.hs+11−11
src/Text/Pandoc/Templates.hs+11−11
@@ -149,21 +149,21 @@ conditional = try $ do
149149 string ")$"
150150 -- if newline after the "if", then a newline after "endif" will be swallowed
151151 multiline <- option False $ try $ skipEndline >> return True
152+ ifContents <- liftM concat parseTemplate
153+ -- reset state for else block
154+ setState $ TemplateState pos vars
155+ elseContents <- option "" $ do try (string "$else$")
156+ when multiline $ optional skipEndline
157+ liftM concat parseTemplate
158+ string "$endif$"
159+ when multiline $ optional skipEndline
152160 let conditionSatisfied = case lookup id' vars of
153161 Nothing -> False
154162 Just "" -> False
155163 Just _ -> True
156− contents <- if conditionSatisfied
157− then liftM concat parseTemplate
158− else do
159− parseTemplate -- skip if part, then reset position
160− setState $ TemplateState pos vars
161− option "" $ do try (string "$else$")
162− when multiline $ optional skipEndline
163− liftM concat parseTemplate
164− string "$endif$"
165− when multiline $ optional skipEndline
166− return contents
164+ return $ if conditionSatisfied
165+ then ifContents
166+ else elseContents
167167
168168for :: GenParser Char TemplateState String
169169for = try $ do