git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1594 from jkr/itemFix

Item fix

commit3533218d6d7e15384262bf478d5ebf5e191f96ff authorJohn MacFarlane <jgm@berkeley.edu> dateSun 31 Aug 2014, 19:31 (12 years ago) parent01b7957dfc8ab5
2 files changed+19−2
src/Text/Pandoc/Writers/LaTeX.hs+12−2 tests/Tests/Writers/LaTeX.hs+7
src/Text/Pandoc/Writers/LaTeX.hs+12−2
@@ -572,7 +572,13 @@ tableCellToLaTeX header (width, align, blocks) = do
572572 $ reverse ns)
573573
574574listItemToLaTeX :: [Block] -> State WriterState Doc
575−listItemToLaTeX lst = blockListToLaTeX lst >>= return . (text "\\item" $$) .
575+listItemToLaTeX lst
576+ -- we need to put some text before a header if it's the first
577+ -- element in an item. This will look ugly in LaTeX regardless, but
578+ -- this will keep the typesetter from throwing an error.
579+ | ((Header _ _ _) :_) <- lst =
580+ blockListToLaTeX lst >>= return . (text "\\item ~" $$) . (nest 2)
581+ | otherwise = blockListToLaTeX lst >>= return . (text "\\item" $$) .
576582 (nest 2)
577583
578584defListItemToLaTeX :: ([Inline], [[Block]]) -> State WriterState Doc
@@ -586,7 +592,11 @@ defListItemToLaTeX (term, defs) = do
586592 then braces term'
587593 else term'
588594 def' <- liftM vsep $ mapM blockListToLaTeX defs
589− return $ "\\item" <> brackets term'' $$ def'
595+ return $ case defs of
596+ (((Header _ _ _) : _) : _) ->
597+ "\\item" <> brackets term'' <> " ~ " $$ def'
598+ _ ->
599+ "\\item" <> brackets term'' $$ def'
590600
591601-- | Craft the section header, inserting the secton reference, if supplied.
592602sectionHeader :: Bool -- True for unnumbered
tests/Tests/Writers/LaTeX.hs+7
@@ -53,6 +53,13 @@ tests = [ testGroup "code blocks"
5353 headerWith ("foo",["unnumbered"],[]) 1
5454 (text "Header 1" <> note (plain $ text "note")) =?>
5555 "\\section*{Header 1\\footnote{note}}\\label{foo}\n\\addcontentsline{toc}{section}{Header 1}\n"
56+ , "in list item" =:
57+ bulletList [header 2 (text "foo")] =?>
58+ "\\begin{itemize}\n\\item ~\n \\subsection{foo}\n\\end{itemize}"
59+ , "in definition list item" =:
60+ definitionList [(text "foo", [header 2 (text "bar"),
61+ para $ text "baz"])] =?>
62+ "\\begin{description}\n\\item[foo] ~ \n\\subsection{bar}\n\nbaz\n\\end{description}"
5663 ]
5764 , testGroup "inline code"
5865 [ "struck out and highlighted" =: