From 2a67b7aea9e9d70e67c0def21da78abf4ec590a1 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 7 Jan 2020 10:11:46 -0800 Subject: [PATCH] Reveal.js writer: restore old behavior for 2D nesting. The fix to #6030 actually changed behavior, so that the 2D nesting occurred at slide level N-1 and N, instead of at the top-level section. This commit restores the 2.7.3 behavior. If there are more than 2 levels, the top level is horizontal and the rest are collapsed to vertical. Closes #6032. --- src/Text/Pandoc/Writers/HTML.hs | 28 +++++++++++++++++----------- test/command/6030.md | 20 +++++++++++++++++++- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 095d55c0e..b739e2b2d 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -80,6 +80,7 @@ data WriterState = WriterState , stEPUBVersion :: Maybe EPUBVersion -- ^ EPUB version if for epub , stSlideVariant :: HTMLSlideVariant , stSlideLevel :: Int -- ^ Slide level + , stInSection :: Bool -- ^ Content is in a section (revealjs) , stCodeBlockNum :: Int -- ^ Number of code block } @@ -90,6 +91,7 @@ defaultWriterState = WriterState {stNotes= [], stMath = False, stQuotes = False, stEPUBVersion = Nothing, stSlideVariant = NoSlides, stSlideLevel = 1, + stInSection = False, stCodeBlockNum = 0} -- Helpers to render HTML with the appropriate function. @@ -662,8 +664,6 @@ blockToHtml opts (Div (ident, "section":dclasses, dkvs) else case splitBy isPause xs of [] -> ([],[]) (z:zs) -> ([],z ++ concatMap inDiv zs) - titleContents <- blockListToHtml opts titleBlocks - innerContents <- blockListToHtml opts innerSecs let classes' = ordNub $ ["title-slide" | titleSlide] ++ ["slide" | slide] ++ ["section" | (slide || writerSectionDivs opts) && @@ -674,20 +674,26 @@ blockToHtml opts (Div (ident, "section":dclasses, dkvs) then H5.section else H.div let attr = (ident, classes', dkvs) + titleContents <- blockListToHtml opts titleBlocks + inSection <- gets stInSection + innerContents <- do + modify $ \st -> st{ stInSection = True } + res <- blockListToHtml opts innerSecs + modify $ \st -> st{ stInSection = inSection } + return res if titleSlide then do t <- addAttrs opts attr $ secttag $ nl opts <> header' <> nl opts <> titleContents <> nl opts + -- ensure 2D nesting for revealjs, but only for one level; + -- revealjs doesn't like more than one level of nesting return $ - -- ensure 2D nesting for revealjs, but only for one level; - -- revealjs doesn't like more than one level of nseting - (if slideVariant == RevealJsSlides && not (null innerSecs) && - level == slideLevel - 1 - then \z -> H5.section (nl opts <> z) - else id) $ t <> nl opts <> - if null innerSecs - then mempty - else innerContents <> nl opts + if slideVariant == RevealJsSlides && not inSection && + not (null innerSecs) + then H5.section (nl opts <> t <> nl opts <> innerContents) + else t <> nl opts <> if null innerSecs + then mempty + else innerContents <> nl opts else if writerSectionDivs opts || slide || (hident /= ident && not (T.null hident || T.null ident)) || (hclasses /= dclasses) || (hkvs /= dkvs) diff --git a/test/command/6030.md b/test/command/6030.md index 44a934a6a..e05bf6e7f 100644 --- a/test/command/6030.md +++ b/test/command/6030.md @@ -15,12 +15,20 @@ Three #### Four Four + +# New sec + +New sec + +## New sub + +New sub ^D +

One

One

-

Two

Two

@@ -32,6 +40,16 @@ Four

Four

+
+
+

New sec

+

New sec

+
+
+

New sub

+

New sub

+
+
``` ```