git.iko.soy/typeable/pandoc
on master help sign in
Use template variables for include-before/after.

* These options now imply -s; previously they worked also in fragment mode. * Users can now adjust position of include-before and include-after text in the templates. * Default position of include-before moved back (as it originally was) before table of contents. * Resolves Issue #217. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1883 788f1e2b-df1e-0410-8736-df70ead52e1b

commit3b9be92492cca7573f9ce79dff099b4d2fa3c56c authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 13 Mar 2010, 04:11 (17 years ago) parenta35af5d
26 files changed+113−69
README+8−2 man/man1/pandoc.1.md+8 src/Text/Pandoc/Writers/ConTeXt.hs+1−7 src/Text/Pandoc/Writers/Docbook.hs+1−6 src/Text/Pandoc/Writers/HTML.hs+1−3 src/Text/Pandoc/Writers/LaTeX.hs+1−7 src/Text/Pandoc/Writers/Man.hs+1−5 src/Text/Pandoc/Writers/Markdown.hs+1−7 src/Text/Pandoc/Writers/MediaWiki.hs+1−3 src/Text/Pandoc/Writers/OpenDocument.hs+1−6 src/Text/Pandoc/Writers/RST.hs+1−6 src/Text/Pandoc/Writers/RTF.hs+1−3 src/Text/Pandoc/Writers/Texinfo.hs+1−7 src/pandoc.hs+8−6 templates/context.template+6 templates/docbook.template+6 templates/html.template+6 templates/latex.template+8 templates/man.template+6 templates/markdown.template+8 templates/mediawiki.template+8 templates/opendocument.template+6 templates/rst.template+8 templates/rtf.template+6 templates/texinfo.template+8 tests/s5.inserts.html+2−1
README+8−2
@@ -276,14 +276,14 @@ For further documentation, see the `pandoc(1)` man page.
276276 `\begin{document}` command in LaTeX). This can be used to include
277277 navigation bars or banners in HTML documents. This option can be
278278 used repeatedly to include multiple files. They will be included in
279− the order specified.
279+ the order specified. Implies `--standalone`.
280280
281281`-A` or `--include-after-body` *filename*
282282: includes the contents of *filename* (verbatim) at the end of
283283 the document body (before the `</body>` tag in HTML, or the
284284 `\end{document}` command in LaTeX). This option can be be used
285285 repeatedly to include multiple files. They will be included in the
286− order specified.
286+ order specified. Implies `--standalone`.
287287
288288`--reference-odt` *filename*
289289: uses the specified file as a style reference in producing an ODT.
@@ -475,6 +475,12 @@ depending on the output format, but include:
475475 values)
476476`toc`
477477: non-null value if `--toc/--table-of-contents` was specified
478+`include-before`
479+: contents specified by `-B/--include-before-body` (may have
480+ multiple values)
481+`include-after`
482+: contents specified by `-A/--include-after-body` (may have
483+ multiple values)
478484`body`
479485: body of document
480486`title`
man/man1/pandoc.1.md+8
@@ -195,9 +195,11 @@ should pipe input and output through `iconv`:
195195
196196-B *FILE*, \--include-before-body=*FILE*
197197: Include contents of *FILE* at the beginning of the document body.
198+ Implies `-s`.
198199
199200-A *FILE*, \--include-after-body=*FILE*
200201: Include contents of *FILE* at the end of the document body.
202+ Implies `-s`.
201203
202204-C *FILE*, \--custom-header=*FILE*
203205: Use contents of *FILE* as the document header. *Note: This option is
@@ -295,6 +297,12 @@ depending on the output format, but include:
295297 values)
296298`toc`
297299: non-null value if `--toc/--table-of-contents` was specified
300+`include-before`
301+: contents specified by `-B/--include-before-body` (may have
302+ multiple values)
303+`include-after`
304+: contents specified by `-A/--include-after-body` (may have
305+ multiple values)
298306`body`
299307: body of document
300308`title`
src/Text/Pandoc/Writers/ConTeXt.hs+1−7
@@ -64,13 +64,7 @@ pandocToConTeXt options (Pandoc (Meta title authors date) blocks) = do
6464 then return ""
6565 else liftM render $ inlineListToConTeXt date
6666 body <- blockListToConTeXt blocks
67− let before = if null (writerIncludeBefore options)
68− then empty
69− else text $ writerIncludeBefore options
70− let after = if null (writerIncludeAfter options)
71− then empty
72− else text $ writerIncludeAfter options
73− let main = render $ before $$ body $$ after
67+ let main = render body
7468 let context = writerVariables options ++
7569 [ ("toc", if writerTableOfContents options then "yes" else "")
7670 , ("body", main)
src/Text/Pandoc/Writers/Docbook.hs+1−6
@@ -65,12 +65,7 @@ writeDocbook opts (Pandoc (Meta tit auths dat) blocks) =
6565 authors = map (authorToDocbook opts) auths
6666 date = inlinesToDocbook opts dat
6767 elements = hierarchicalize blocks
68− before = writerIncludeBefore opts
69− after = writerIncludeAfter opts
70− main = render $
71− (if null before then empty else text before) $$
72− vcat (map (elementToDocbook opts) elements) $$
73− (if null after then empty else text after)
68+ main = render $ vcat (map (elementToDocbook opts) elements)
7469 context = writerVariables opts ++
7570 [ ("body", main)
7671 , ("title", render title)
src/Text/Pandoc/Writers/HTML.hs+1−3
@@ -105,9 +105,7 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
105105 blocks' <- liftM toHtmlFromList $ mapM (elementToHtml opts) sects
106106 st <- get
107107 let notes = reverse (stNotes st)
108− let before = primHtml $ writerIncludeBefore opts
109− let after = primHtml $ writerIncludeAfter opts
110− let thebody = before +++ blocks' +++ footnoteSection notes +++ after
108+ let thebody = blocks' +++ footnoteSection notes
111109 let math = if stMath st
112110 then case writerHTMLMathMethod opts of
113111 LaTeXMathML (Just url) ->
src/Text/Pandoc/Writers/LaTeX.hs+1−7
@@ -74,13 +74,7 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
7474 authorsText <- mapM (liftM render . inlineListToLaTeX) authors
7575 dateText <- liftM render $ inlineListToLaTeX date
7676 body <- blockListToLaTeX blocks
77− let before = if null (writerIncludeBefore options)
78− then empty
79− else text $ writerIncludeBefore options
80− let after = if null (writerIncludeAfter options)
81− then empty
82− else text $ writerIncludeAfter options
83− let main = render $ before $$ body $$ after
77+ let main = render body
8478 st <- get
8579 let context = writerVariables options ++
8680 [ ("toc", if writerTableOfContents options then "yes" else "")
src/Text/Pandoc/Writers/Man.hs+1−5
@@ -48,10 +48,6 @@ writeMan opts document = evalState (pandocToMan opts document) (WriterState [] F
4848-- | Return groff man representation of document.
4949pandocToMan :: WriterOptions -> Pandoc -> State WriterState String
5050pandocToMan opts (Pandoc (Meta title authors date) blocks) = do
51− let before = writerIncludeBefore opts
52− let after = writerIncludeAfter opts
53− let before' = if null before then empty else text before
54− let after' = if null after then empty else text after
5551 titleText <- inlineListToMan opts title
5652 authors' <- mapM (inlineListToMan opts) authors
5753 date' <- inlineListToMan opts date
@@ -66,7 +62,7 @@ pandocToMan opts (Pandoc (Meta title authors date) blocks) = do
6662 body <- blockListToMan opts blocks
6763 notes <- liftM stNotes get
6864 notes' <- notesToMan opts (reverse notes)
69− let main = render $ before' $$ body $$ notes' $$ after'
65+ let main = render $ body $$ notes'
7066 hasTables <- liftM stHasTables get
7167 let context = writerVariables opts ++
7268 [ ("body", main)
src/Text/Pandoc/Writers/Markdown.hs+1−7
@@ -60,17 +60,11 @@ pandocToMarkdown opts (Pandoc (Meta title authors date) 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
6963 (notes, _) <- get
7064 notes' <- notesToMarkdown opts (reverse notes)
7165 (_, refs) <- get -- note that the notes may contain refs
7266 refs' <- keyTableToMarkdown opts (reverse refs)
73− let main = render $ before $+$ body $+$ text "" $+$ notes' $+$ text "" $+$ refs' $+$ after
67+ let main = render $ body $+$ text "" $+$ notes' $+$ text "" $+$ refs'
7468 let context = writerVariables opts ++
7569 [ ("toc", render toc)
7670 , ("body", main)
src/Text/Pandoc/Writers/MediaWiki.hs+1−3
@@ -53,14 +53,12 @@ writeMediaWiki opts document =
5353-- | Return MediaWiki representation of document.
5454pandocToMediaWiki :: WriterOptions -> Pandoc -> State WriterState String
5555pandocToMediaWiki opts (Pandoc _ blocks) = do
56− let before = writerIncludeBefore opts
57− let after = writerIncludeAfter opts
5856 body <- blockListToMediaWiki opts blocks
5957 notesExist <- get >>= return . stNotes
6058 let notes = if notesExist
6159 then "\n<references />"
6260 else ""
63− let main = before ++ body ++ after ++ notes
61+ let main = body ++ notes
6462 let context = writerVariables opts ++
6563 [ ("body", main) ] ++
6664 [ ("toc", "yes") | writerTableOfContents opts ]
src/Text/Pandoc/Writers/OpenDocument.hs+1−6
@@ -166,12 +166,7 @@ writeOpenDocument opts (Pandoc (Meta title authors date) blocks) =
166166 date'' <- inlinesToOpenDocument opts date
167167 doc'' <- blocksToOpenDocument opts blocks
168168 return (doc'', title'', authors'', date'')
169− before = writerIncludeBefore opts
170− after = writerIncludeAfter opts
171− body = (if null before then empty else text before) $$
172− doc $$
173− (if null after then empty else text after)
174− body' = render body
169+ body' = render doc
175170 styles = stTableStyles s ++ stParaStyles s ++ stTextStyles s
176171 listStyle (n,l) = inTags True "text:list-style"
177172 [("style:name", "L" ++ show n)] (vcat l)
src/Text/Pandoc/Writers/RST.hs+1−6
@@ -59,10 +59,6 @@ writeRST opts document =
5959pandocToRST :: Pandoc -> State WriterState String
6060pandocToRST (Pandoc (Meta tit auth dat) blocks) = do
6161 opts <- liftM stOptions get
62− let before = writerIncludeBefore opts
63− after = writerIncludeAfter opts
64− before' = if null before then empty else text before
65− after' = if null after then empty else text after
6662 title <- titleToRST tit
6763 authors <- mapM inlineListToRST auth
6864 date <- inlineListToRST dat
@@ -72,8 +68,7 @@ pandocToRST (Pandoc (Meta tit auth dat) blocks) = do
7268 refs <- liftM (reverse . stLinks) get >>= keyTableToRST
7369 pics <- liftM (reverse . stImages) get >>= pictTableToRST
7470 hasMath <- liftM stHasMath get
75− let main = render $ before' $+$ body $+$ notes $+$
76− text "" $+$ refs $+$ pics $+$ after'
71+ let main = render $ body $+$ notes $+$ text "" $+$ refs $+$ pics
7772 let context = writerVariables opts ++
7873 [ ("body", main)
7974 , ("title", render title)
src/Text/Pandoc/Writers/RTF.hs+1−3
@@ -42,9 +42,7 @@ writeRTF options (Pandoc (Meta title authors date) blocks) =
4242 authorstext = map inlineListToRTF authors
4343 datetext = inlineListToRTF date
4444 spacer = not $ all null $ titletext : datetext : authorstext
45− body = writerIncludeBefore options ++
46− concatMap (blockToRTF 0 AlignDefault) blocks ++
47− writerIncludeAfter options
45+ body = concatMap (blockToRTF 0 AlignDefault) blocks
4846 context = writerVariables options ++
4947 [ ("body", body)
5048 , ("title", titletext)
src/Text/Pandoc/Writers/Texinfo.hs+1−7
@@ -69,13 +69,7 @@ pandocToTexinfo options (Pandoc (Meta title authors date) blocks) = do
6969 let titlePage = not $ all null $ title : date : authors
7070 main <- blockListToTexinfo blocks
7171 st <- get
72− let before = if null (writerIncludeBefore options)
73− then empty
74− else text (writerIncludeBefore options)
75− let after = if null (writerIncludeAfter options)
76− then empty
77− else text (writerIncludeAfter options)
78− let body = render $ before $$ main $$ after
72+ let body = render main
7973 let context = writerVariables options ++
8074 [ ("body", body)
8175 , ("title", render titleText)
src/pandoc.hs+8−6
@@ -399,9 +399,10 @@ options =
399399 (ReqArg
400400 (\arg opt -> do
401401 text <- readFile arg
402− let oldBefore = optBefore opt
403− -- add new text to end, so it is included in proper order
404− return opt { optBefore = oldBefore ++ [text] })
402+ -- add new ones to end, so they're included in order specified
403+ let newvars = optVariables opt ++ [("include-before",text)]
404+ return opt { optVariables = newvars,
405+ optStandalone = True })
405406 "FILENAME")
406407 "" -- "File to include before document body"
407408
@@ -409,9 +410,10 @@ options =
409410 (ReqArg
410411 (\arg opt -> do
411412 text <- readFile arg
412− let oldAfter = optAfter opt
413− -- add new text to end, so it is included in proper order
414− return opt { optAfter = oldAfter ++ [text]})
413+ -- add new ones to end, so they're included in order specified
414+ let newvars = optVariables opt ++ [("include-after",text)]
415+ return opt { optVariables = newvars,
416+ optStandalone = True })
415417 "FILENAME")
416418 "" -- "File to include after document body"
417419
templates/context.template+6
@@ -73,10 +73,16 @@ $endif$
7373 \blank[3*medium]
7474\stopalignment
7575$endif$
76+$for(include-before)$
77+$include-before$
78+$endfor$
7679$if(toc)$
7780\placecontent
7881$endif$
7982
8083$body$
8184
85+$for(include-after)$
86+$include-after$
87+$endfor$
8288\stoptext
templates/docbook.template+6
@@ -17,6 +17,12 @@ $if(date)$
1717 <date>$date$</date>
1818$endif$
1919 </articleinfo>
20+$for(include-before)$
21+$include-before$
22+$endfor$
2023$body$
24+$for(include-after)$
25+$include-after$
26+$endfor$
2127</article>
2228
templates/html.template+6
@@ -44,9 +44,15 @@ $endif$
4444$if(title)$
4545<h1 class="title">$title$</h1>
4646$endif$
47+$for(include-before)$
48+$include-before$
49+$endfor$
4750$if(toc)$
4851$toc$
4952$endif$
5053$body$
54+$for(include-after)$
55+$include-after$
56+$endfor$
5157</body>
5258</html>
templates/latex.template+8
@@ -80,10 +80,18 @@ $if(title)$
8080\maketitle
8181$endif$
8282
83+$for(include-before)$
84+$include-before$
85+
86+$endfor$
8387$if(toc)$
8488\tableofcontents
8589
8690$endif$
8791$body$
92+$for(include-after)$
93+
94+$include-after$
95+$endfor$
8896
8997\end{document}
templates/man.template+6
@@ -5,7 +5,13 @@ $endif$
55$for(header-includes)$
66$header-includes$
77$endfor$
8+$for(include-before)$
9+$include-before$
10+$endfor$
811$body$
12+$for(include-after)$
13+$include-after$
14+$endfor$
915$if(author)$
1016.SH AUTHORS
1117$for(author)$$author$$sep$; $endfor$.
templates/markdown.template+8
@@ -7,9 +7,17 @@ $endif$
77$for(header-includes)$
88$header-includes$
99
10+$endfor$
11+$for(include-before)$
12+$include-before$
13+
1014$endfor$
1115$if(toc)$
1216$toc$
1317
1418$endif$
1519$body$
20+$for(include-after)$
21+
22+$include-after$
23+$endfor$
templates/mediawiki.template+8
@@ -1,8 +1,16 @@
11$if(legacy-header)$
22$legacy-header$
33$endif$
4+$for(include-before)$
5+$include-before$
6+
7+$endfor$
48$if(toc)$
59__TOC__
610
711$endif$
812$body$
13+$for(include-after)$
14+
15+$include-after$
16+$endfor$
templates/opendocument.template+6
@@ -15,7 +15,13 @@ $endfor$
1515$if(date)$
1616<text:p text:style-name="Date">$date$</text:p>
1717$endif$
18+$for(include-before)$
19+$include-before$
20+$endfor$
1821$body$
22+$for(include-after)$
23+$include-after$
24+$endfor$
1925</office:text>
2026</office:body>
2127</office:document-content>
templates/rst.template+8
@@ -20,6 +20,10 @@ $if(math)$
2020 :format: html latex
2121
2222$endif$
23+$for(include-before)$
24+$include-before$
25+
26+$endfor$
2327$if(toc)$
2428.. contents::
2529
@@ -29,3 +33,7 @@ $header-includes$
2933
3034$endfor$
3135$body$
36+$for(include-after)$
37+
38+$include-after$
39+$endfor$
templates/rtf.template+6
@@ -21,5 +21,11 @@ $endif$
2121$if(spacer)$
2222{\pard \ql \f0 \sa180 \li0 \fi0 \par}
2323$endif$
24+$for(include-before)$
25+$include-before$
26+$endfor$
2427$body$
28+$for(include-after)$
29+$include-after$
30+$endfor$
2531}
templates/texinfo.template+8
@@ -51,10 +51,18 @@ $endif$
5151@end titlepage
5252
5353$endif$
54+$for(include-before)$
55+$include-before$
56+
57+$endfor$
5458$if(toc)$
5559@contents
5660
5761$endif$
5862$body$
63+$for(include-after)$
64+
65+$include-after$
66+$endfor$
5967
6068@bye
tests/s5.inserts.html+2−1
@@ -57,7 +57,8 @@ STUFF INSERTED
5757 ></li
5858 ></ul
5959 ></div
60−>STUFF INSERTED
60+>
61+STUFF INSERTED
6162</body>
6263</html>
6364