git.iko.soy/typeable/pandoc
on master help sign in
Adjusted formatting of LaTeX and ConTeXt footnotes:

- in ConTeXt, % is not needed at end of line before note, since space is gobbled. - beginning of footnote indented four spaces. - this required an additional parameter in wrappedTeX and wrapTeXIfNeeded, in Text.Pandoc.Shared. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1080 788f1e2b-df1e-0410-8736-df70ead52e1b

commit09b57fcf9ca4deab5fd7d8979863b36922edf6c3 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 17 Nov 2007, 18:42 (19 years ago) parent780b77c
5 files changed+40−30
src/Text/Pandoc/Shared.hs+19−9 src/Text/Pandoc/Writers/ConTeXt.hs+3−3 src/Text/Pandoc/Writers/LaTeX.hs+3−3 tests/writer.context+10−10 tests/writer.latex+5−5
src/Text/Pandoc/Shared.hs+19−9
@@ -227,8 +227,12 @@ isNote _ = False
227227
228228-- | Wrap inlines to line length, treating footnotes in a way that
229229-- makes sense in LaTeX and ConTeXt.
230−wrappedTeX :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
231−wrappedTeX listWriter sect = do
230+wrappedTeX :: Monad m
231+ => Bool -- | Include % on line before notes.
232+ -> ([Inline] -> m Doc) -- | Inline list writer.
233+ -> [Inline]
234+ -> m Doc
235+wrappedTeX includePercent listWriter sect = do
232236 let (firstpart, rest) = break isNote sect
233237 firstpartWrapped <- wrapped listWriter firstpart
234238 if null rest
@@ -236,17 +240,23 @@ wrappedTeX listWriter sect = do
236240 else do let (note:rest') = rest
237241 restWrapped <- if null rest'
238242 then return empty
239− else wrappedTeX listWriter rest'
243+ else wrappedTeX includePercent listWriter rest'
240244 noteText <- listWriter [note]
241− return $ firstpartWrapped <> PP.char '%' $$ noteText $$ restWrapped
245+ return $ firstpartWrapped <>
246+ (if includePercent then PP.char '%' else empty) $$
247+ noteText $$ restWrapped
242248
243249-- | Wrap inlines if the text wrap option is selected, specialized
244250-- for LaTeX and ConTeXt.
245−wrapTeXIfNeeded :: Monad m => WriterOptions -> ([Inline] -> m Doc) ->
246− [Inline] -> m Doc
247−wrapTeXIfNeeded opts = if writerWrapText opts
248− then wrappedTeX
249− else ($)
251+wrapTeXIfNeeded :: Monad m
252+ => WriterOptions
253+ -> Bool -- | Include % on line before notes.
254+ -> ([Inline] -> m Doc) -- | Inline list writer.
255+ -> [Inline]
256+ -> m Doc
257+wrapTeXIfNeeded opts includePercent = if writerWrapText opts
258+ then wrappedTeX includePercent
259+ else ($)
250260
251261--
252262-- Parsing
src/Text/Pandoc/Writers/ConTeXt.hs+3−3
@@ -116,9 +116,9 @@ blockToConTeXt :: WriterOptions
116116 -> State WriterState Doc
117117blockToConTeXt opts Null = return empty
118118blockToConTeXt opts (Plain lst) =
119− wrapTeXIfNeeded opts (inlineListToConTeXt opts) lst >>= return
119+ wrapTeXIfNeeded opts False (inlineListToConTeXt opts) lst >>= return
120120blockToConTeXt opts (Para lst) =
121− wrapTeXIfNeeded opts (inlineListToConTeXt opts) lst >>= return . (<> char '\n')
121+ wrapTeXIfNeeded opts False (inlineListToConTeXt opts) lst >>= return . (<> char '\n')
122122blockToConTeXt opts (BlockQuote lst) = do
123123 contents <- blockListToConTeXt opts lst
124124 return $ text "\\startblockquote\n" $$ contents $$ text "\\stopblockquote"
@@ -270,7 +270,7 @@ inlineToConTeXt opts (Image alternate (src, tit)) = do
270270 text tit <> text "}\n{\\externalfigure[" <> text src <> text "]}"
271271inlineToConTeXt opts (Note contents) = do
272272 contents' <- blockListToConTeXt opts contents
273− return $ text "\\footnote{" <>
273+ return $ text " \\footnote{" <>
274274 text (stripTrailingNewlines $ render contents') <>
275275 char '}'
276276
src/Text/Pandoc/Writers/LaTeX.hs+3−3
@@ -137,11 +137,11 @@ blockToLaTeX Null = return empty
137137blockToLaTeX (Plain lst) = do
138138 st <- get
139139 let opts = stOptions st
140− wrapTeXIfNeeded opts inlineListToLaTeX lst
140+ wrapTeXIfNeeded opts True inlineListToLaTeX lst
141141blockToLaTeX (Para lst) = do
142142 st <- get
143143 let opts = stOptions st
144− result <- wrapTeXIfNeeded opts inlineListToLaTeX lst
144+ result <- wrapTeXIfNeeded opts True inlineListToLaTeX lst
145145 return $ result <> char '\n'
146146blockToLaTeX (BlockQuote lst) = do
147147 contents <- blockListToLaTeX lst
@@ -314,5 +314,5 @@ inlineToLaTeX (Note contents) = do
314314 let rawnote = stripTrailingNewlines $ render contents'
315315 -- note: a \n before } is needed when note ends with a Verbatim environment
316316 let optNewline = "\\end{Verbatim}" `isSuffixOf` rawnote
317− return $ text "\\footnote{" <>
317+ return $ text " \\footnote{" <>
318318 text rawnote <> (if optNewline then char '\n' else empty) <> char '}'
tests/writer.context+10−10
@@ -821,11 +821,11 @@ Here is a movie
821821
822822\subject{Footnotes}
823823
824−Here is a footnote reference,%
825−\footnote{Here is the footnote. It can go anywhere after the footnote
824+Here is a footnote reference,
825+ \footnote{Here is the footnote. It can go anywhere after the footnote
826826reference. It need not be placed at the end of the document.}
827−and another.%
828−\footnote{Here's the long note. This one contains multiple blocks.
827+and another.
828+ \footnote{Here's the long note. This one contains multiple blocks.
829829
830830Subsequent blocks are indented to show that they belong to the
831831footnote (as with list items).
@@ -837,20 +837,20 @@ footnote (as with list items).
837837If you want, you can indent every line, but you can also be lazy
838838and just indent the first line of each block.}
839839This should {\em not} be a footnote reference, because it contains
840−a space.[\letterhat{}my note] Here is an inline note.%
841−\footnote{This is {\em easier} to type. Inline notes may contain
840+a space.[\letterhat{}my note] Here is an inline note.
841+ \footnote{This is {\em easier} to type. Inline notes may contain
842842\useurl[31][http://google.com][][links]\from[31] and \type{]}
843843verbatim characters, as well as [bracketed text].}
844844
845845\startblockquote
846−Notes can go in quotes.%
847−\footnote{In quote.}
846+Notes can go in quotes.
847+ \footnote{In quote.}
848848
849849\stopblockquote
850850\startitemize
851851\sym{1.}
852− And in list items.%
853− \footnote{In list.}
852+ And in list items.
853+ \footnote{In list.}
854854\stopitemize
855855This paragraph should not be part of the note, as it is not
856856indented.
tests/writer.latex+5−5
@@ -792,10 +792,10 @@ Here is a movie \includegraphics{movie.jpg} icon.
792792\section{Footnotes}
793793
794794Here is a footnote reference,%
795−\footnote{Here is the footnote. It can go anywhere after the footnote
795+ \footnote{Here is the footnote. It can go anywhere after the footnote
796796reference. It need not be placed at the end of the document.}
797797and another.%
798−\footnote{Here's the long note. This one contains multiple blocks.
798+ \footnote{Here's the long note. This one contains multiple blocks.
799799
800800Subsequent blocks are indented to show that they belong to the
801801footnote (as with list items).
@@ -807,19 +807,19 @@ If you want, you can indent every line, but you can also be lazy
807807and just indent the first line of each block.}
808808This should \emph{not} be a footnote reference, because it contains
809809a space.[\^{}my note] Here is an inline note.%
810−\footnote{This is \emph{easier} to type. Inline notes may contain
810+ \footnote{This is \emph{easier} to type. Inline notes may contain
811811\href{http://google.com}{links} and \verb!]! verbatim characters,
812812as well as [bracketed text].}
813813
814814\begin{quote}
815815Notes can go in quotes.%
816−\footnote{In quote.}
816+ \footnote{In quote.}
817817
818818\end{quote}
819819\begin{enumerate}[1.]
820820\item
821821 And in list items.%
822− \footnote{In list.}
822+ \footnote{In list.}
823823\end{enumerate}
824824This paragraph should not be part of the note, as it is not
825825indented.