summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:14:11 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:14:11 +0000
commitc70f585e563872001a9205208f9c1aca7933d587 (patch)
tree218b4a110280726998a7c42b800d813ff31d1191 /src/Text/Pandoc
parent213895f033e60707123b42f8a780f1a3a9ef6196 (diff)
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
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Templates.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Templates.hs b/src/Text/Pandoc/Templates.hs
index 69cd5c554..b40cf7fdb 100644
--- a/src/Text/Pandoc/Templates.hs
+++ b/src/Text/Pandoc/Templates.hs
@@ -37,10 +37,16 @@ by dollar signs. To include a literal @$@ in your template, use
@$$@. Variable names must begin with a letter and can contain letters,
numbers, @_@, and @-@.
+The value of a variable will be indented to the same level as the
+variable.
+
A conditional begins with @$if(variable_name)$@ and ends with @$endif$@.
It may optionally contain an @$else$@ section. The if section is
used if @variable_name@ has a non-null value, otherwise the else section
is used.
+
+Conditional keywords should not be indented, or unexpected spacing
+problems may occur.
-}
module Text.Pandoc.Templates (renderTemplate, getDefaultTemplate) where
@@ -98,13 +104,13 @@ escapedDollar = try $ string "$$" >> return "$"
conditional :: GenParser Char TemplateState String
conditional = try $ do
+ let skipEndline = try $ skipMany (oneOf " \t") >> newline
TemplateState pos vars <- getState
string "$if("
id' <- ident
string ")$"
-- if newline after the "if", then a newline after "endif" will be swallowed
- multiline <- option False $ try $
- newline >> count pos (char ' ') >> return True
+ multiline <- option False $ try $ skipEndline >> return True
let conditionSatisfied = case lookup id' vars of
Nothing -> False
Just "" -> False
@@ -115,10 +121,10 @@ conditional = try $ do
parseTemplate -- skip if part, then reset position
setState $ TemplateState pos vars
option "" $ do try (string "$else$")
- optional newline
+ when multiline $ optional skipEndline
liftM concat parseTemplate
string "$endif$"
- when multiline $ optional $ newline
+ when multiline $ optional skipEndline
return contents
ident :: GenParser Char TemplateState String