Restored writerIncludeBefore, writerIncludeAfter.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1700 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
fiddlosopher 2009-12-31 01:12:59 +00:00
parent 3ec8772daf
commit 1f580fb701
16 changed files with 50 additions and 61 deletions

View file

@ -984,6 +984,8 @@ data WriterOptions = WriterOptions
{ writerStandalone :: Bool -- ^ Include header and footer { writerStandalone :: Bool -- ^ Include header and footer
, writerTemplate :: String -- ^ Template to use in standalone mode , writerTemplate :: String -- ^ Template to use in standalone mode
, writerVariables :: [(String, String)] -- ^ Variables to set in template , 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 , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
, writerTableOfContents :: Bool -- ^ Include table of contents , writerTableOfContents :: Bool -- ^ Include table of contents
, writerS5 :: Bool -- ^ We're writing S5 , writerS5 :: Bool -- ^ We're writing S5
@ -1005,6 +1007,8 @@ defaultWriterOptions =
WriterOptions { writerStandalone = False WriterOptions { writerStandalone = False
, writerTemplate = "" , writerTemplate = ""
, writerVariables = [] , writerVariables = []
, writerIncludeBefore = ""
, writerIncludeAfter = ""
, writerTabStop = 4 , writerTabStop = 4
, writerTableOfContents = False , writerTableOfContents = False
, writerS5 = False , writerS5 = False

View file

@ -52,7 +52,14 @@ writeLaTeX options document =
pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do 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 titletext <- liftM render $ inlineListToLaTeX title
authorsText <- mapM (liftM render . inlineListToLaTeX) authors authorsText <- mapM (liftM render . inlineListToLaTeX) authors
dateText <- liftM render $ inlineListToLaTeX date dateText <- liftM render $ inlineListToLaTeX date
@ -62,7 +69,9 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
, ("title", titletext) , ("title", titletext)
, ("authors", intercalate "\\\\" authorsText) , ("authors", intercalate "\\\\" authorsText)
, ("date", dateText) ] , ("date", dateText) ]
return $ renderTemplate context $ writerTemplate options return $ if writerStandalone options
then renderTemplate context $ writerTemplate options
else main
-- escape things as needed for LaTeX -- escape things as needed for LaTeX

View file

@ -60,17 +60,25 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
then tableOfContents opts headerBlocks then tableOfContents opts headerBlocks
else empty else empty
body <- blockListToMarkdown opts blocks 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, _) <- get
notes' <- notesToMarkdown opts (reverse notes) notes' <- notesToMarkdown opts (reverse notes)
(_, refs) <- get -- note that the notes may contain refs (_, refs) <- get -- note that the notes may contain refs
refs' <- keyTableToMarkdown opts (reverse refs) refs' <- keyTableToMarkdown opts (reverse refs)
let main = render $ before $+$ body $+$ text "" $+$ notes' $+$ text "" $+$ refs' $+$ after
let context = writerVariables opts ++ let context = writerVariables opts ++
[ ("toc", render toc) [ ("toc", render toc)
, ("body", render $ body $+$ text "" $+$ notes' $+$ , ("body", main)
text "" $+$ refs')
, ("titleblock", render head') , ("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. -- | Return markdown representation of reference key table.
keyTableToMarkdown :: WriterOptions -> KeyTable -> State WriterState Doc keyTableToMarkdown :: WriterOptions -> KeyTable -> State WriterState Doc

View file

@ -138,6 +138,8 @@ data Opt = Opt
, optTableOfContents :: Bool -- ^ Include table of contents , optTableOfContents :: Bool -- ^ Include table of contents
, optTemplate :: String -- ^ Custom template , optTemplate :: String -- ^ Custom template
, optVariables :: [(String,String)] -- ^ Template variables to set , 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 , optOutputFile :: String -- ^ Name of output file
, optNumberSections :: Bool -- ^ Number sections in LaTeX , optNumberSections :: Bool -- ^ Number sections in LaTeX
, optIncremental :: Bool -- ^ Use incremental lists in S5 , optIncremental :: Bool -- ^ Use incremental lists in S5
@ -172,6 +174,8 @@ defaultOpts = Opt
, optTableOfContents = False , optTableOfContents = False
, optTemplate = "" , optTemplate = ""
, optVariables = [] , optVariables = []
, optBefore = []
, optAfter = []
, optOutputFile = "-" -- "-" means stdout , optOutputFile = "-" -- "-" means stdout
, optNumberSections = False , optNumberSections = False
, optIncremental = False , optIncremental = False
@ -383,13 +387,8 @@ options =
(ReqArg (ReqArg
(\arg opt -> do (\arg opt -> do
text <- readFile arg text <- readFile arg
let oldvars = optVariables opt let oldBefore = optBefore opt
let newvars = case lookup "before" oldvars of return opt { optBefore = text : oldBefore })
Nothing -> ("before", text) : oldvars
Just b -> ("before", b ++ text) :
filter ((/= "before") . fst)
oldvars
return opt { optVariables = newvars })
"FILENAME") "FILENAME")
"" -- "File to include before document body" "" -- "File to include before document body"
@ -397,13 +396,8 @@ options =
(ReqArg (ReqArg
(\arg opt -> do (\arg opt -> do
text <- readFile arg text <- readFile arg
let oldvars = optVariables opt let oldAfter = optAfter opt
let newvars = case lookup "after" oldvars of return opt { optAfter = text : oldAfter })
Nothing -> ("after", text) : oldvars
Just a -> ("after", a ++ text) :
filter ((/= "after") . fst)
oldvars
return opt { optVariables = newvars })
"FILENAME") "FILENAME")
"" -- "File to include after document body" "" -- "File to include after document body"
@ -572,6 +566,8 @@ main = do
, optWriter = writerName , optWriter = writerName
, optParseRaw = parseRaw , optParseRaw = parseRaw
, optVariables = variables , optVariables = variables
, optBefore = befores
, optAfter = afters
, optTableOfContents = toc , optTableOfContents = toc
, optTemplate = template , optTemplate = template
, optOutputFile = outputFile , optOutputFile = outputFile
@ -665,6 +661,8 @@ main = do
then defaultTemplate then defaultTemplate
else template, else template,
writerVariables = variables', writerVariables = variables',
writerIncludeBefore = concat befores,
writerIncludeAfter = concat afters,
writerTabStop = tabStop, writerTabStop = tabStop,
writerTableOfContents = toc && writerTableOfContents = toc &&
writerName' /= "s5", writerName' /= "s5",

View file

@ -78,8 +78,6 @@ $header-includes$
\placecontent \placecontent
$before$
\subject{section oen} \subject{section oen}
\startitemize[n][stopper=.] \startitemize[n][stopper=.]
@ -106,7 +104,6 @@ footnote
code code
\stoptyping \stoptyping
} }
$after$
\stoptext \stoptext

View file

@ -10,7 +10,7 @@
/>$header-includes$ />$header-includes$
</head </head
><body ><body
>$before$ >
<h1 class="title" <h1 class="title"
><span class="math" ><span class="math"
><em ><em
@ -68,7 +68,7 @@
> <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
></ol ></ol
></div ></div
>$after$ >
</body </body
></html ></html
> >

View file

@ -10,7 +10,7 @@
/>$header-includes$ />$header-includes$
</head </head
><body ><body
>$before$ >
<h1 class="title" <h1 class="title"
><span class="math" ><span class="math"
><em ><em
@ -68,7 +68,7 @@
> <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
></ol ></ol
></div ></div
>$after$ >
</body </body
></html ></html
> >

View file

@ -1,4 +1,3 @@
$if(standalone)$
$if(legacy-header)$ $if(legacy-header)$
$legacy-header$ $legacy-header$
$else$ $else$
@ -49,17 +48,8 @@ $endif$
\begin{document} \begin{document}
\maketitle \maketitle
$endif$
$if(toc)$ $if(toc)$
\tableofcontents \tableofcontents
$endif$ $endif$
$if(before)$
$before$
$endif$
$body$ $body$
$if(after)$
$after$
$endif$
$if(standalone)$
\end{document} \end{document}
$endif$

View file

@ -10,7 +10,7 @@
/>$header-includes$ />$header-includes$
</head </head
><body ><body
>$before$ >
<h1 class="title" <h1 class="title"
><span class="math" ><span class="math"
><em ><em
@ -68,7 +68,7 @@
> <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
></ol ></ol
></div ></div
>$after$ >
</body </body
></html ></html
> >

View file

@ -1,18 +1,10 @@
$if(standalone)$
$if(titleblock)$ $if(titleblock)$
$titleblock$ $titleblock$
$endif$ $endif$
$if(header-includes)$ $if(header-includes)$
$header-includes$ $header-includes$
$endif$ $endif$
$endif$
$if(before)$
$before$
$endif$
$if(toc)$ $if(toc)$
$toc$ $toc$
$endif$ $endif$
$body$ $body$
$if(after)$
$after$
$endif$

View file

@ -10,7 +10,7 @@
/>$header-includes$ />$header-includes$
</head </head
><body ><body
>$before$ >
<h1 class="title" <h1 class="title"
><span class="math" ><span class="math"
><em ><em
@ -68,7 +68,7 @@
> <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
></ol ></ol
></div ></div
>$after$ >
</body </body
></html ></html
> >

View file

@ -10,7 +10,7 @@
/>$header-includes$ />$header-includes$
</head </head
><body ><body
>$before$ >
<h1 class="title" <h1 class="title"
><span class="math" ><span class="math"
><em ><em
@ -68,7 +68,7 @@
> <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
></ol ></ol
></div ></div
>$after$ >
</body </body
></html ></html
> >

View file

@ -9,8 +9,6 @@
$header-includes$ $header-includes$
$before$
.. role:: math(raw) .. role:: math(raw)
:format: html latex :format: html latex
@ -39,6 +37,3 @@ footnote [1]_
code code
$after$

View file

@ -9,7 +9,6 @@ $header-includes$
{\pard \ql \f0 \sa180 \li0 \fi0 \par} {\pard \ql \f0 \sa180 \li0 \fi0 \par}
{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 Contents\par} {\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 Contents\par}
{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab section oen\sa180\par} {\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab section oen\sa180\par}
$before$
{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 section oen\par} {\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 section oen\par}
{\pard \ql \f0 \sa0 \li360 \fi-360 1.\tx360\tab one\par} {\pard \ql \f0 \sa0 \li360 \fi-360 1.\tx360\tab one\par}
{\pard \ql \f0 \sa0 \li720 \fi-360 a.\tx360\tab two\par} {\pard \ql \f0 \sa0 \li720 \fi-360 a.\tx360\tab two\par}
@ -18,7 +17,6 @@ $before$
{\pard \ql \f0 \sa180 \li0 \fi0 footnote{\super\chftn}{\*\footnote\chftn\~\plain\pard {\pard \ql \f0 \sa180 \li0 \fi0 with code\par} {\pard \ql \f0 \sa180 \li0 \fi0 footnote{\super\chftn}{\*\footnote\chftn\~\plain\pard {\pard \ql \f0 \sa180 \li0 \fi0 with code\par}
{\pard \ql \f0 \sa180 \li0 \fi0 \f1 code\par} {\pard \ql \f0 \sa180 \li0 \fi0 \f1 code\par}
}\par} }\par}
$after$
} }

View file

@ -271,7 +271,7 @@ window.onload=startup;window.onresize=function(){setTimeout('fontScale()',50);}
$header-includes$ $header-includes$
</head </head
><body ><body
>$before$ >
<div class="layout"> <div class="layout">
<div id="controls"></div> <div id="controls"></div>
<div id="currentSlide"></div> <div id="currentSlide"></div>
@ -343,7 +343,7 @@ $header-includes$
> <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
></ol ></ol
></div ></div
>$after$ >
</body </body
></html ></html
> >

View file

@ -12,7 +12,6 @@ $header-includes$
$date$ $date$
@end titlepage @end titlepage
@contents @contents
$before$
@node Top @node Top
@top @math{title} @top @math{title}
@ -48,6 +47,5 @@ code
@end verbatim @end verbatim
} }
$after$
@bye @bye