git.iko.soy/typeable/pandoc
on master help sign in
[Tex] Remove invalid inlines in sections (#3218)

Latex doesn't like when hypertargets or images are put in the options list of the section. They are not lost since they were actually duplicated and present also in the second argument list. Note on the implementation: I had to inline the definiton of 'foldMap' since it is not implemented in every version of Haskell that Pandoc supports.

commit5219599a775b5765d39ddceae4d57223c8eacc41 authorhubertp-lshift <hubertp@lshift.de> dateSat 26 Nov 2016, 21:47 (10 years ago) parent015dead
1 file changed+6−4
src/Text/Pandoc/Writers/LaTeX.hs+6−4
src/Text/Pandoc/Writers/LaTeX.hs+6−4
@@ -743,14 +743,16 @@ sectionHeader :: Bool -- True for unnumbered
743743sectionHeader unnumbered ident level lst = do
744744 txt <- inlineListToLaTeX lst
745745 plain <- stringToLaTeX TextString $ concatMap stringify lst
746− let noNote (Note _) = Str ""
747− noNote x = x
748− let lstNoNotes = walk noNote lst
746+ let removeInvalidInline (Note _) = []
747+ removeInvalidInline (Span (id', _, _) _) | not (null id') = []
748+ removeInvalidInline (Image _ _ _) = []
749+ removeInvalidInline x = [x]
750+ let lstNoNotes = foldr (mappend . (\x -> walkM removeInvalidInline x)) mempty lst
749751 txtNoNotes <- inlineListToLaTeX lstNoNotes
750752 -- footnotes in sections don't work (except for starred variants)
751753 -- unless you specify an optional argument:
752754 -- \section[mysec]{mysec\footnote{blah}}
753− optional <- if unnumbered || lstNoNotes == lst
755+ optional <- if unnumbered || lstNoNotes == lst || lstNoNotes == []
754756 then return empty
755757 else do
756758 return $ brackets txtNoNotes