git.iko.soy/typeable/pandoc
on master help sign in
Presentations: Use divs to set incremental/non-incremental

Currently, html and beamer presentations use a list-inside-blockquote convention for setting incremental and all-at-once presentation of lists (or reversing the command-line default). This allows the user to set this on a per-case basis with divs, named `incremental` and `nonincremental` respectively, as in: ::: incremental - snap - crackle - pop ::: Note that the former list-inside-blockquote convention still works so as not to break any existing presentations. Closes: #4381

commit69a72099305ff4efe10f8bc5dbab103f1302b2ad authorJesse Rosenthal <jrosenthal@jhu.edu> dateTue 20 Feb 2018, 16:22 (9 years ago) parent8b7df2d
2 files changed+83−53
src/Text/Pandoc/Writers/HTML.hs+16−7 src/Text/Pandoc/Writers/LaTeX.hs+67−46
src/Text/Pandoc/Writers/HTML.hs+16−7
@@ -2,6 +2,7 @@
22{-# LANGUAGE OverloadedStrings #-}
33{-# LANGUAGE ScopedTypeVariables #-}
44{-# LANGUAGE ViewPatterns #-}
5+{-# LANGUAGE MultiWayIf #-}
56{-
67Copyright (C) 2006-2018 John MacFarlane <jgm@berkeley.edu>
78
@@ -678,23 +679,31 @@ blockToHtml opts (LineBlock lns) =
678679 return $ H.div ! A.class_ "line-block" $ htmlLines
679680blockToHtml opts (Div attr@(ident, classes, kvs') bs) = do
680681 html5 <- gets stHtml5
682+ slideVariant <- gets stSlideVariant
681683 let kvs = [(k,v) | (k,v) <- kvs', k /= "width"] ++
682684 [("style", "width:" ++ w ++ ";")
683685 | ("width",w) <- kvs', "column" `elem` classes]
684686 let speakerNotes = "notes" `elem` classes
685687 -- we don't want incremental output inside speaker notes, see #1394
686− let opts' = if speakerNotes then opts{ writerIncremental = False } else opts
687− contents <- if "columns" `elem` classes
688+ let opts' = if | speakerNotes -> opts{ writerIncremental = False }
689+ | "incremental" `elem` classes -> opts{ writerIncremental = True }
690+ | "nonincremental" `elem` classes -> opts{ writerIncremental = False }
691+ | otherwise -> opts
692+ -- we remove "incremental" and "nonincremental" if we're in a
693+ -- slide presentaiton format.
694+ classes' = case slideVariant of
695+ NoSlides -> classes
696+ _ -> filter (\k -> k /= "incremental" && k /= "nonincremental") classes
697+ contents <- if "columns" `elem` classes'
688698 then -- we don't use blockListToHtml because it inserts
689699 -- a newline between the column divs, which throws
690700 -- off widths! see #4028
691701 mconcat <$> mapM (blockToHtml opts) bs
692702 else blockListToHtml opts' bs
693703 let contents' = nl opts >> contents >> nl opts
694− let (divtag, classes') = if html5 && "section" `elem` classes
695− then (H5.section, filter (/= "section") classes)
696− else (H.div, classes)
697− slideVariant <- gets stSlideVariant
704+ let (divtag, classes'') = if html5 && "section" `elem` classes'
705+ then (H5.section, filter (/= "section") classes')
706+ else (H.div, classes')
698707 if speakerNotes
699708 then case slideVariant of
700709 RevealJsSlides -> addAttrs opts' attr $
@@ -706,7 +715,7 @@ blockToHtml opts (Div attr@(ident, classes, kvs') bs) = do
706715 NoSlides -> addAttrs opts' attr $
707716 H.div contents'
708717 _ -> return mempty
709− else addAttrs opts (ident, classes', kvs) $
718+ else addAttrs opts (ident, classes'', kvs) $
710719 divtag contents'
711720blockToHtml opts (RawBlock f str) = do
712721 ishtml <- isRawHtml f
src/Text/Pandoc/Writers/LaTeX.hs+67−46
@@ -442,54 +442,75 @@ blockToLaTeX :: PandocMonad m
442442 => Block -- ^ Block to convert
443443 -> LW m Doc
444444blockToLaTeX Null = return empty
445−blockToLaTeX (Div (identifier,classes,kvs) bs) = do
446− beamer <- gets stBeamer
447− linkAnchor' <- hypertarget True identifier empty
448− -- see #2704 for the motivation for adding \leavevmode:
449− let linkAnchor =
450− case bs of
451− Para _ : _
452− | not (isEmpty linkAnchor')
453− -> "\\leavevmode" <> linkAnchor' <> "%"
454− _ -> linkAnchor'
455− let align dir txt = inCmd "begin" dir $$ txt $$ inCmd "end" dir
456− lang <- toLang $ lookup "lang" kvs
457− let wrapColumns = if "columns" `elem` classes
458− then \contents ->
459− inCmd "begin" "columns" <> brackets "T"
460− $$ contents
461− $$ inCmd "end" "columns"
462− else id
463− wrapColumn = if "column" `elem` classes
464− then \contents ->
465− let fromPct xs =
466− case reverse xs of
467− '%':ds -> '0':'.': reverse ds
468− _ -> xs
469− w = maybe "0.48" fromPct (lookup "width" kvs)
470− in inCmd "begin" "column" <>
471− braces (text w <> "\\textwidth")
472− $$ contents
473− $$ inCmd "end" "column"
474− else id
475− wrapDir = case lookup "dir" kvs of
476− Just "rtl" -> align "RTL"
477− Just "ltr" -> align "LTR"
478− _ -> id
479− wrapLang txt = case lang of
480− Just lng -> let (l, o) = toPolyglossiaEnv lng
481− ops = if null o
482− then ""
483− else brackets $ text o
484− in inCmd "begin" (text l) <> ops
485− $$ blankline <> txt <> blankline
486− $$ inCmd "end" (text l)
487− Nothing -> txt
488− wrapNotes txt = if beamer && "notes" `elem` classes
445+blockToLaTeX (Div (identifier,classes,kvs) bs)
446+ | "incremental" `elem` classes = do
447+ let classes' = filter ("incremental"/=) classes
448+ beamer <- gets stBeamer
449+ if beamer
450+ then do oldIncremental <- gets stIncremental
451+ modify $ \s -> s{ stIncremental = True }
452+ result <- blockToLaTeX $ Div (identifier,classes',kvs) bs
453+ modify $ \s -> s{ stIncremental = oldIncremental }
454+ return result
455+ else blockToLaTeX $ Div (identifier,classes',kvs) bs
456+ | "nonincremental" `elem` classes = do
457+ let classes' = filter ("nonincremental"/=) classes
458+ beamer <- gets stBeamer
459+ if beamer
460+ then do oldIncremental <- gets stIncremental
461+ modify $ \s -> s{ stIncremental = False }
462+ result <- blockToLaTeX $ Div (identifier,classes',kvs) bs
463+ modify $ \s -> s{ stIncremental = oldIncremental }
464+ return result
465+ else blockToLaTeX $ Div (identifier,classes',kvs) bs
466+ | otherwise = do
467+ beamer <- gets stBeamer
468+ linkAnchor' <- hypertarget True identifier empty
469+ -- see #2704 for the motivation for adding \leavevmode:
470+ let linkAnchor =
471+ case bs of
472+ Para _ : _
473+ | not (isEmpty linkAnchor')
474+ -> "\\leavevmode" <> linkAnchor' <> "%"
475+ _ -> linkAnchor'
476+ let align dir txt = inCmd "begin" dir $$ txt $$ inCmd "end" dir
477+ lang <- toLang $ lookup "lang" kvs
478+ let wrapColumns = if "columns" `elem` classes
479+ then \contents ->
480+ inCmd "begin" "columns" <> brackets "T"
481+ $$ contents
482+ $$ inCmd "end" "columns"
483+ else id
484+ wrapColumn = if "column" `elem` classes
485+ then \contents ->
486+ let fromPct xs =
487+ case reverse xs of
488+ '%':ds -> '0':'.': reverse ds
489+ _ -> xs
490+ w = maybe "0.48" fromPct (lookup "width" kvs)
491+ in inCmd "begin" "column" <>
492+ braces (text w <> "\\textwidth")
493+ $$ contents
494+ $$ inCmd "end" "column"
495+ else id
496+ wrapDir = case lookup "dir" kvs of
497+ Just "rtl" -> align "RTL"
498+ Just "ltr" -> align "LTR"
499+ _ -> id
500+ wrapLang txt = case lang of
501+ Just lng -> let (l, o) = toPolyglossiaEnv lng
502+ ops = if null o
503+ then ""
504+ else brackets $ text o
505+ in inCmd "begin" (text l) <> ops
506+ $$ blankline <> txt <> blankline
507+ $$ inCmd "end" (text l)
508+ Nothing -> txt
509+ wrapNotes txt = if beamer && "notes" `elem` classes
489510 then "\\note" <> braces txt -- speaker notes
490511 else linkAnchor $$ txt
491− (wrapColumns . wrapColumn . wrapDir . wrapLang . wrapNotes)
492− <$> blockListToLaTeX bs
512+ (wrapColumns . wrapColumn . wrapDir . wrapLang . wrapNotes)
513+ <$> blockListToLaTeX bs
493514blockToLaTeX (Plain lst) =
494515 inlineListToLaTeX $ dropWhile isLineBreakOrSpace lst
495516-- title beginning with fig: indicates that the image is a figure