git.iko.soy/typeable/pandoc
on master help sign in
Restored writerIncludeBefore, writerIncludeAfter.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1700 788f1e2b-df1e-0410-8736-df70ead52e1b

commit1f580fb70189f91894ec757dd00cd4286d0da8a6 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 31 Dec 2009, 01:12 (17 years ago) parent3ec8772
16 files changed+50−61
src/Text/Pandoc/Shared.hs+4 src/Text/Pandoc/Writers/LaTeX.hs+11−2 src/Text/Pandoc/Writers/Markdown.hs+11−3 src/pandoc.hs+12−14 templates/context.template−3 templates/docbook.template+2−2 templates/html.template+2−2 templates/latex.template−10 templates/man.template+2−2 templates/markdown.template−8 templates/mediawiki.template+2−2 templates/opendocument.template+2−2 templates/rst.template−5 templates/rtf.template−2 templates/s5.template+2−2 templates/texinfo.template−2
src/Text/Pandoc/Shared.hs+4
@@ -984,6 +984,8 @@ data WriterOptions = WriterOptions
984984 { writerStandalone :: Bool -- ^ Include header and footer
985985 , writerTemplate :: String -- ^ Template to use in standalone mode
986986 , writerVariables :: [(String, String)] -- ^ Variables to set in template
987+ , writerIncludeBefore :: String -- ^ Text to include before the body
988+ , writerIncludeAfter :: String -- ^ Text to include after the body
987989 , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
988990 , writerTableOfContents :: Bool -- ^ Include table of contents
989991 , writerS5 :: Bool -- ^ We're writing S5
@@ -1005,6 +1007,8 @@ defaultWriterOptions =
10051007 WriterOptions { writerStandalone = False
10061008 , writerTemplate = ""
10071009 , writerVariables = []
1010+ , writerIncludeBefore = ""
1011+ , writerIncludeAfter = ""
10081012 , writerTabStop = 4
10091013 , writerTableOfContents = False
10101014 , writerS5 = False
src/Text/Pandoc/Writers/LaTeX.hs+11−2
@@ -52,7 +52,14 @@ writeLaTeX options document =
5252
5353pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
5454pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
55− main <- liftM render $ blockListToLaTeX blocks
55+ body <- blockListToLaTeX blocks
56+ let before = if null (writerIncludeBefore options)
57+ then empty
58+ else text $ writerIncludeBefore options
59+ let after = if null (writerIncludeAfter options)
60+ then empty
61+ else text $ writerIncludeAfter options
62+ let main = render $ before $$ body $$ after
5663 titletext <- liftM render $ inlineListToLaTeX title
5764 authorsText <- mapM (liftM render . inlineListToLaTeX) authors
5865 dateText <- liftM render $ inlineListToLaTeX date
@@ -62,7 +69,9 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
6269 , ("title", titletext)
6370 , ("authors", intercalate "\\\\" authorsText)
6471 , ("date", dateText) ]
65− return $ renderTemplate context $ writerTemplate options
72+ return $ if writerStandalone options
73+ then renderTemplate context $ writerTemplate options
74+ else main
6675
6776-- escape things as needed for LaTeX
6877
src/Text/Pandoc/Writers/Markdown.hs+11−3
@@ -60,17 +60,25 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
6060 then tableOfContents opts headerBlocks
6161 else empty
6262 body <- blockListToMarkdown opts blocks
63+ let before = if null (writerIncludeBefore opts)
64+ then empty
65+ else text $ writerIncludeBefore opts
66+ let after = if null (writerIncludeAfter opts)
67+ then empty
68+ else text $ writerIncludeAfter opts
6369 (notes, _) <- get
6470 notes' <- notesToMarkdown opts (reverse notes)
6571 (_, refs) <- get -- note that the notes may contain refs
6672 refs' <- keyTableToMarkdown opts (reverse refs)
73+ let main = render $ before $+$ body $+$ text "" $+$ notes' $+$ text "" $+$ refs' $+$ after
6774 let context = writerVariables opts ++
6875 [ ("toc", render toc)
69− , ("body", render $ body $+$ text "" $+$ notes' $+$
70− text "" $+$ refs')
76+ , ("body", main)
7177 , ("titleblock", render head')
7278 ]
73− return $ renderTemplate context $ writerTemplate opts
79+ if writerStandalone opts
80+ then return $ renderTemplate context $ writerTemplate opts
81+ else return main
7482
7583-- | Return markdown representation of reference key table.
7684keyTableToMarkdown :: WriterOptions -> KeyTable -> State WriterState Doc
src/pandoc.hs+12−14
@@ -138,6 +138,8 @@ data Opt = Opt
138138 , optTableOfContents :: Bool -- ^ Include table of contents
139139 , optTemplate :: String -- ^ Custom template
140140 , optVariables :: [(String,String)] -- ^ Template variables to set
141+ , optBefore :: [String] -- ^ Texts to include before body
142+ , optAfter :: [String] -- ^ Texts to include after body
141143 , optOutputFile :: String -- ^ Name of output file
142144 , optNumberSections :: Bool -- ^ Number sections in LaTeX
143145 , optIncremental :: Bool -- ^ Use incremental lists in S5
@@ -172,6 +174,8 @@ defaultOpts = Opt
172174 , optTableOfContents = False
173175 , optTemplate = ""
174176 , optVariables = []
177+ , optBefore = []
178+ , optAfter = []
175179 , optOutputFile = "-" -- "-" means stdout
176180 , optNumberSections = False
177181 , optIncremental = False
@@ -383,13 +387,8 @@ options =
383387 (ReqArg
384388 (\arg opt -> do
385389 text <- readFile arg
386− let oldvars = optVariables opt
387− let newvars = case lookup "before" oldvars of
388− Nothing -> ("before", text) : oldvars
389− Just b -> ("before", b ++ text) :
390− filter ((/= "before") . fst)
391− oldvars
392− return opt { optVariables = newvars })
390+ let oldBefore = optBefore opt
391+ return opt { optBefore = text : oldBefore })
393392 "FILENAME")
394393 "" -- "File to include before document body"
395394
@@ -397,13 +396,8 @@ options =
397396 (ReqArg
398397 (\arg opt -> do
399398 text <- readFile arg
400− let oldvars = optVariables opt
401− let newvars = case lookup "after" oldvars of
402− Nothing -> ("after", text) : oldvars
403− Just a -> ("after", a ++ text) :
404− filter ((/= "after") . fst)
405− oldvars
406− return opt { optVariables = newvars })
399+ let oldAfter = optAfter opt
400+ return opt { optAfter = text : oldAfter })
407401 "FILENAME")
408402 "" -- "File to include after document body"
409403
@@ -572,6 +566,8 @@ main = do
572566 , optWriter = writerName
573567 , optParseRaw = parseRaw
574568 , optVariables = variables
569+ , optBefore = befores
570+ , optAfter = afters
575571 , optTableOfContents = toc
576572 , optTemplate = template
577573 , optOutputFile = outputFile
@@ -665,6 +661,8 @@ main = do
665661 then defaultTemplate
666662 else template,
667663 writerVariables = variables',
664+ writerIncludeBefore = concat befores,
665+ writerIncludeAfter = concat afters,
668666 writerTabStop = tabStop,
669667 writerTableOfContents = toc &&
670668 writerName' /= "s5",
templates/context.template−3
@@ -78,8 +78,6 @@ $header-includes$
7878
7979\placecontent
8080
81−$before$
82−
8381\subject{section oen}
8482
8583\startitemize[n][stopper=.]
@@ -106,7 +104,6 @@ footnote
106104code
107105\stoptyping
108106}
109−$after$
110107
111108\stoptext
112109
templates/docbook.template+2−2
@@ -10,7 +10,7 @@
1010 />$header-includes$
1111</head
1212 ><body
13− >$before$
13+ >
1414<h1 class="title"
1515 ><span class="math"
1616 ><em
@@ -68,7 +68,7 @@
6868 > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
6969 ></ol
7070 ></div
71− >$after$
71+ >
7272</body
7373 ></html
7474>
templates/html.template+2−2
@@ -10,7 +10,7 @@
1010 />$header-includes$
1111</head
1212 ><body
13− >$before$
13+ >
1414<h1 class="title"
1515 ><span class="math"
1616 ><em
@@ -68,7 +68,7 @@
6868 > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
6969 ></ol
7070 ></div
71− >$after$
71+ >
7272</body
7373 ></html
7474>
templates/latex.template−10
@@ -1,4 +1,3 @@
1−$if(standalone)$
21$if(legacy-header)$
32$legacy-header$
43$else$
@@ -49,17 +48,8 @@ $endif$
4948\begin{document}
5049\maketitle
5150
52−$endif$
5351$if(toc)$
5452\tableofcontents
5553$endif$
56−$if(before)$
57−$before$
58−$endif$
5954$body$
60−$if(after)$
61−$after$
62−$endif$
63−$if(standalone)$
6455\end{document}
65−$endif$
templates/man.template+2−2
@@ -10,7 +10,7 @@
1010 />$header-includes$
1111</head
1212 ><body
13− >$before$
13+ >
1414<h1 class="title"
1515 ><span class="math"
1616 ><em
@@ -68,7 +68,7 @@
6868 > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
6969 ></ol
7070 ></div
71− >$after$
71+ >
7272</body
7373 ></html
7474>
templates/markdown.template−8
@@ -1,18 +1,10 @@
1−$if(standalone)$
21$if(titleblock)$
32$titleblock$
43$endif$
54$if(header-includes)$
65$header-includes$
76$endif$
8−$endif$
9−$if(before)$
10−$before$
11−$endif$
127$if(toc)$
138$toc$
149$endif$
1510$body$
16−$if(after)$
17−$after$
18−$endif$
templates/mediawiki.template+2−2
@@ -10,7 +10,7 @@
1010 />$header-includes$
1111</head
1212 ><body
13− >$before$
13+ >
1414<h1 class="title"
1515 ><span class="math"
1616 ><em
@@ -68,7 +68,7 @@
6868 > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
6969 ></ol
7070 ></div
71− >$after$
71+ >
7272</body
7373 ></html
7474>
templates/opendocument.template+2−2
@@ -10,7 +10,7 @@
1010 />$header-includes$
1111</head
1212 ><body
13− >$before$
13+ >
1414<h1 class="title"
1515 ><span class="math"
1616 ><em
@@ -68,7 +68,7 @@
6868 > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
6969 ></ol
7070 ></div
71− >$after$
71+ >
7272</body
7373 ></html
7474>
templates/rst.template−5
@@ -9,8 +9,6 @@
99
1010$header-includes$
1111
12−$before$
13−
1412.. role:: math(raw)
1513 :format: html latex
1614
@@ -39,6 +37,3 @@ footnote [1]_
3937
4038 code
4139
42−
43−$after$
44−
templates/rtf.template−2
@@ -9,7 +9,6 @@ $header-includes$
99{\pard \ql \f0 \sa180 \li0 \fi0 \par}
1010{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 Contents\par}
1111{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab section oen\sa180\par}
12−$before$
1312{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 section oen\par}
1413{\pard \ql \f0 \sa0 \li360 \fi-360 1.\tx360\tab one\par}
1514{\pard \ql \f0 \sa0 \li720 \fi-360 a.\tx360\tab two\par}
@@ -18,7 +17,6 @@ $before$
1817{\pard \ql \f0 \sa180 \li0 \fi0 footnote{\super\chftn}{\*\footnote\chftn\~\plain\pard {\pard \ql \f0 \sa180 \li0 \fi0 with code\par}
1918{\pard \ql \f0 \sa180 \li0 \fi0 \f1 code\par}
2019}\par}
21−$after$
2220
2321}
2422
templates/s5.template+2−2
@@ -271,7 +271,7 @@ window.onload=startup;window.onresize=function(){setTimeout('fontScale()',50);}
271271$header-includes$
272272</head
273273 ><body
274− >$before$
274+ >
275275<div class="layout">
276276<div id="controls"></div>
277277<div id="currentSlide"></div>
@@ -343,7 +343,7 @@ $header-includes$
343343 > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
344344 ></ol
345345 ></div
346− >$after$
346+ >
347347</body
348348 ></html
349349>
templates/texinfo.template−2
@@ -12,7 +12,6 @@ $header-includes$
1212$date$
1313@end titlepage
1414@contents
15−$before$
1615
1716@node Top
1817@top @math{title}
@@ -48,6 +47,5 @@ code
4847@end verbatim
4948}
5049
51−$after$
5250
5351@bye