aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:12:59 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-31 01:12:59 +0000
commit1f580fb70189f91894ec757dd00cd4286d0da8a6 (patch)
tree04f6a64233bca673b1e749599e14ad4ab9a60acf /src
parent3ec8772daff7d76097d7435c4e8da1df5ee4cc6a (diff)
downloadpandoc-1f580fb70189f91894ec757dd00cd4286d0da8a6.tar.gz
Restored writerIncludeBefore, writerIncludeAfter.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1700 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Shared.hs4
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs13
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs14
-rw-r--r--src/pandoc.hs26
4 files changed, 38 insertions, 19 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index ae14937d5..dbb5d94a4 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -984,6 +984,8 @@ data WriterOptions = WriterOptions
{ writerStandalone :: Bool -- ^ Include header and footer
, writerTemplate :: String -- ^ Template to use in standalone mode
, writerVariables :: [(String, String)] -- ^ Variables to set in template
+ , writerIncludeBefore :: String -- ^ Text to include before the body
+ , writerIncludeAfter :: String -- ^ Text to include after the body
, writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
, writerTableOfContents :: Bool -- ^ Include table of contents
, writerS5 :: Bool -- ^ We're writing S5
@@ -1005,6 +1007,8 @@ defaultWriterOptions =
WriterOptions { writerStandalone = False
, writerTemplate = ""
, writerVariables = []
+ , writerIncludeBefore = ""
+ , writerIncludeAfter = ""
, writerTabStop = 4
, writerTableOfContents = False
, writerS5 = False
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index f119598a6..6782cc14e 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -52,7 +52,14 @@ writeLaTeX options document =
pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
- main <- liftM render $ blockListToLaTeX blocks
+ body <- blockListToLaTeX blocks
+ let before = if null (writerIncludeBefore options)
+ then empty
+ else text $ writerIncludeBefore options
+ let after = if null (writerIncludeAfter options)
+ then empty
+ else text $ writerIncludeAfter options
+ let main = render $ before $$ body $$ after
titletext <- liftM render $ inlineListToLaTeX title
authorsText <- mapM (liftM render . inlineListToLaTeX) authors
dateText <- liftM render $ inlineListToLaTeX date
@@ -62,7 +69,9 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
, ("title", titletext)
, ("authors", intercalate "\\\\" authorsText)
, ("date", dateText) ]
- return $ renderTemplate context $ writerTemplate options
+ return $ if writerStandalone options
+ then renderTemplate context $ writerTemplate options
+ else main
-- escape things as needed for LaTeX
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 266336968..25fe561da 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -60,17 +60,25 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
then tableOfContents opts headerBlocks
else empty
body <- blockListToMarkdown opts blocks
+ let before = if null (writerIncludeBefore opts)
+ then empty
+ else text $ writerIncludeBefore opts
+ let after = if null (writerIncludeAfter opts)
+ then empty
+ else text $ writerIncludeAfter opts
(notes, _) <- get
notes' <- notesToMarkdown opts (reverse notes)
(_, refs) <- get -- note that the notes may contain refs
refs' <- keyTableToMarkdown opts (reverse refs)
+ let main = render $ before $+$ body $+$ text "" $+$ notes' $+$ text "" $+$ refs' $+$ after
let context = writerVariables opts ++
[ ("toc", render toc)
- , ("body", render $ body $+$ text "" $+$ notes' $+$
- text "" $+$ refs')
+ , ("body", main)
, ("titleblock", render head')
]
- return $ renderTemplate context $ writerTemplate opts
+ if writerStandalone opts
+ then return $ renderTemplate context $ writerTemplate opts
+ else return main
-- | Return markdown representation of reference key table.
keyTableToMarkdown :: WriterOptions -> KeyTable -> State WriterState Doc
diff --git a/src/pandoc.hs b/src/pandoc.hs
index a18e069cc..431a41836 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -138,6 +138,8 @@ data Opt = Opt
, optTableOfContents :: Bool -- ^ Include table of contents
, optTemplate :: String -- ^ Custom template
, optVariables :: [(String,String)] -- ^ Template variables to set
+ , optBefore :: [String] -- ^ Texts to include before body
+ , optAfter :: [String] -- ^ Texts to include after body
, optOutputFile :: String -- ^ Name of output file
, optNumberSections :: Bool -- ^ Number sections in LaTeX
, optIncremental :: Bool -- ^ Use incremental lists in S5
@@ -172,6 +174,8 @@ defaultOpts = Opt
, optTableOfContents = False
, optTemplate = ""
, optVariables = []
+ , optBefore = []
+ , optAfter = []
, optOutputFile = "-" -- "-" means stdout
, optNumberSections = False
, optIncremental = False
@@ -383,13 +387,8 @@ options =
(ReqArg
(\arg opt -> do
text <- readFile arg
- let oldvars = optVariables opt
- let newvars = case lookup "before" oldvars of
- Nothing -> ("before", text) : oldvars
- Just b -> ("before", b ++ text) :
- filter ((/= "before") . fst)
- oldvars
- return opt { optVariables = newvars })
+ let oldBefore = optBefore opt
+ return opt { optBefore = text : oldBefore })
"FILENAME")
"" -- "File to include before document body"
@@ -397,13 +396,8 @@ options =
(ReqArg
(\arg opt -> do
text <- readFile arg
- let oldvars = optVariables opt
- let newvars = case lookup "after" oldvars of
- Nothing -> ("after", text) : oldvars
- Just a -> ("after", a ++ text) :
- filter ((/= "after") . fst)
- oldvars
- return opt { optVariables = newvars })
+ let oldAfter = optAfter opt
+ return opt { optAfter = text : oldAfter })
"FILENAME")
"" -- "File to include after document body"
@@ -572,6 +566,8 @@ main = do
, optWriter = writerName
, optParseRaw = parseRaw
, optVariables = variables
+ , optBefore = befores
+ , optAfter = afters
, optTableOfContents = toc
, optTemplate = template
, optOutputFile = outputFile
@@ -665,6 +661,8 @@ main = do
then defaultTemplate
else template,
writerVariables = variables',
+ writerIncludeBefore = concat befores,
+ writerIncludeAfter = concat afters,
writerTabStop = tabStop,
writerTableOfContents = toc &&
writerName' /= "s5",