git.iko.soy/typeable/pandoc
on master help sign in
Templates: don't try to handle indented $if$, $else$, $endif$.

Instead, require that these be flush left in multiline conditionals. Also, swallow empty space after keywords in multiline conditionals. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1709 788f1e2b-df1e-0410-8736-df70ead52e1b

commitc70f585e563872001a9205208f9c1aca7933d587 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 31 Dec 2009, 01:14 (17 years ago) parent213895f
1 file changed+10−4
src/Text/Pandoc/Templates.hs+10−4
src/Text/Pandoc/Templates.hs+10−4
@@ -37,10 +37,16 @@ by dollar signs. To include a literal @$@ in your template, use
3737@$$@. Variable names must begin with a letter and can contain letters,
3838numbers, @_@, and @-@.
3939
40+The value of a variable will be indented to the same level as the
41+variable.
42+
4043A conditional begins with @$if(variable_name)$@ and ends with @$endif$@.
4144It may optionally contain an @$else$@ section. The if section is
4245used if @variable_name@ has a non-null value, otherwise the else section
4346is used.
47+
48+Conditional keywords should not be indented, or unexpected spacing
49+problems may occur.
4450-}
4551
4652module Text.Pandoc.Templates (renderTemplate, getDefaultTemplate) where
@@ -98,13 +104,13 @@ escapedDollar = try $ string "$$" >> return "$"
98104
99105conditional :: GenParser Char TemplateState String
100106conditional = try $ do
107+ let skipEndline = try $ skipMany (oneOf " \t") >> newline
101108 TemplateState pos vars <- getState
102109 string "$if("
103110 id' <- ident
104111 string ")$"
105112 -- if newline after the "if", then a newline after "endif" will be swallowed
106− multiline <- option False $ try $
107− newline >> count pos (char ' ') >> return True
113+ multiline <- option False $ try $ skipEndline >> return True
108114 let conditionSatisfied = case lookup id' vars of
109115 Nothing -> False
110116 Just "" -> False
@@ -115,10 +121,10 @@ conditional = try $ do
115121 parseTemplate -- skip if part, then reset position
116122 setState $ TemplateState pos vars
117123 option "" $ do try (string "$else$")
118− optional newline
124+ when multiline $ optional skipEndline
119125 liftM concat parseTemplate
120126 string "$endif$"
121− when multiline $ optional $ newline
127+ when multiline $ optional skipEndline
122128 return contents
123129
124130ident :: GenParser Char TemplateState String