@@ -45,6 +45,8 @@ module Text.Pandoc.Shared (
45 toRomanNumeral,
45 toRomanNumeral,
47 wrapIfNeeded,
47 wrapIfNeeded,
48 -- * Parsing
50 -- * Parsing
@@ -96,7 +98,8 @@ module Text.Pandoc.Shared (
97import Text.Pandoc.Definition
99import Text.Pandoc.Definition
98import Text.ParserCombinators.Parsec
100import Text.ParserCombinators.Parsec
99−import Text.PrettyPrint.HughesPJ ( Doc, fsep )
101+import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty )
102+import qualified Text.PrettyPrint.HughesPJ as PP
100import Text.Pandoc.CharacterReferences ( characterReference )
103import Text.Pandoc.CharacterReferences ( characterReference )
101import Data.Char ( toLower, toUpper, ord, isLower, isUpper )
104import Data.Char ( toLower, toUpper, ord, isLower, isUpper )
102import Data.List ( find, isPrefixOf )
105import Data.List ( find, isPrefixOf )
@@ -211,12 +214,40 @@ wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
211wrapped listWriter sect = (mapM listWriter $ splitBy Space sect) >>=
214wrapped listWriter sect = (mapM listWriter $ splitBy Space sect) >>=
212 return . fsep
215 return . fsep
217+-- | Wrap inlines if the text wrap option is selected.
214wrapIfNeeded :: Monad m => WriterOptions -> ([Inline] -> m Doc) ->
218wrapIfNeeded :: Monad m => WriterOptions -> ([Inline] -> m Doc) ->
215 [Inline] -> m Doc
219 [Inline] -> m Doc
216wrapIfNeeded opts = if writerWrapText opts
220wrapIfNeeded opts = if writerWrapText opts
217 then wrapped
221 then wrapped
224+-- auxiliary function for wrappedTeX
225+isNote (Note _) = True
228+-- | Wrap inlines to line length, treating footnotes in a way that
229+-- makes sense in LaTeX and ConTeXt.
230+wrappedTeX :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
231+wrappedTeX listWriter sect = do
232+ let (firstpart, rest) = break isNote sect
233+ firstpartWrapped <- wrapped listWriter firstpart
235+ then return firstpartWrapped
236+ else do let (note:rest') = rest
237+ restWrapped <- if null rest'
239+ else wrappedTeX listWriter rest'
240+ noteText <- listWriter [note]
241+ return $ firstpartWrapped <> PP.char '%' $$ noteText $$ restWrapped
243+-- | Wrap inlines if the text wrap option is selected, specialized
244+-- for LaTeX and ConTeXt.
245+wrapTeXIfNeeded :: Monad m => WriterOptions -> ([Inline] -> m Doc) ->
247+wrapTeXIfNeeded opts = if writerWrapText opts
221-- Parsing
252-- Parsing