git.iko.soy/typeable/pandoc
on master help sign in
Fix regression in beamer slide structure with certain slide levels.

Closes #6030.

commit66bca029c75e5d29ce10d929f621a82d521bc37c authorJohn MacFarlane <jgm@berkeley.edu> dateSun 5 Jan 2020, 11:10 (7 years ago) parent0dff9b3
2 files changed+60−8
src/Text/Pandoc/Writers/LaTeX.hs+17−8 test/command/6030.md+43
src/Text/Pandoc/Writers/LaTeX.hs+17−8
@@ -53,7 +53,7 @@ data WriterState =
5353 , stInQuote :: Bool -- true if in a blockquote
5454 , stExternalNotes :: Bool -- true if in context where
5555 -- we need to store footnotes
56− , stInMinipage :: Bool -- true if in minipage
56+ , stInMinipage :: Bool -- true if in minipage
5757 , stInHeading :: Bool -- true if in a section heading
5858 , stInItem :: Bool -- true if in \item[..]
5959 , stNotes :: [Doc Text] -- notes in a minipage
@@ -455,11 +455,21 @@ toSlides bs = do
455455
456456-- this creates section slides and marks slides with class "slide","block"
457457elementToBeamer :: PandocMonad m => Int -> Block -> LW m Block
458−elementToBeamer slideLevel d@(Div (ident,dclasses,dkvs)
459− xs@(Header lvl _ _ : _))
460− | lvl > slideLevel = return $ Div (ident,"block":dclasses,dkvs) xs
461− | lvl < slideLevel = return d
462− | otherwise = return $ Div (ident,"slide":dclasses,dkvs) xs
458+elementToBeamer slideLevel (Div (ident,"section":dclasses,dkvs)
459+ xs@(h@(Header lvl _ _) : ys))
460+ | lvl > slideLevel
461+ = return $ Div (ident,"block":dclasses,dkvs) xs
462+ | lvl < slideLevel
463+ = do let isDiv (Div{}) = True
464+ isDiv _ = False
465+ let (titleBs, slideBs) = break isDiv ys
466+ return $
467+ if null titleBs
468+ then Div (ident,dclasses,dkvs) xs
469+ else Div (ident,dclasses,dkvs)
470+ (h : Div ("","slide":dclasses,dkvs) (h:titleBs) : slideBs)
471+ | otherwise
472+ = return $ Div (ident,"slide":dclasses,dkvs) xs
463473elementToBeamer _ x = return x
464474
465475isListBlock :: Block -> Bool
@@ -516,8 +526,7 @@ blockToLaTeX (Div (identifier,"slide":dclasses,dkvs)
516526 braces (literal ref) <> braces empty
517527 contents <- blockListToLaTeX bs >>= wrapDiv (identifier,classes,kvs)
518528 return $ ("\\begin{frame}" <> options <> slideTitle <> slideAnchor) $$
519− contents $$
520− "\\end{frame}"
529+ contents $$ "\\end{frame}"
521530blockToLaTeX (Div (identifier@(T.uncons -> Just (_,_)),dclasses,dkvs)
522531 (Header lvl ("",hclasses,hkvs) ils : bs)) =
523532 -- move identifier from div to header
test/command/6030.md+43
@@ -33,3 +33,46 @@ Four
3333</section>
3434</section>
3535```
36+
37+```
38+% pandoc -t beamer --slide-level=3
39+# One
40+
41+One
42+
43+## Two
44+
45+Two
46+
47+### Three
48+
49+Three
50+
51+#### Four
52+
53+Four
54+^D
55+\hypertarget{one}{%
56+\section{One}\label{one}}
57+
58+\begin{frame}{One}
59+One
60+\end{frame}
61+
62+\hypertarget{two}{%
63+\subsection{Two}\label{two}}
64+
65+\begin{frame}{Two}
66+Two
67+\end{frame}
68+
69+\begin{frame}{Three}
70+\protect\hypertarget{three}{}
71+Three
72+
73+\begin{block}{Four}
74+\protect\hypertarget{four}{}
75+Four
76+\end{block}
77+\end{frame}
78+```