git.iko.soy/typeable/pandoc
on master help sign in
Beamer writer: support exampleblock and alertblock.

A block will be rendered as an exampleblock if the heading has class `example` and alertblock if it has class `alert`. Closes #7278.

commit76a4e7127be1116b67ae531f56aadb05963813b5 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 14 May 2021, 10:09 (5 years ago) parentb9b1ec5
3 files changed+51−4
MANUAL.txt+5−1 src/Text/Pandoc/Writers/LaTeX.hs+8−3 test/command/7278.md+38
MANUAL.txt+5−1
@@ -5666,7 +5666,11 @@ rules:
56665666 * A heading at the slide level always starts a new slide.
56675667
56685668 * Headings *below* the slide level in the hierarchy create
5669− headings *within* a slide.
5669+ headings *within* a slide. (In beamer, a "block" will be
5670+ created. If the heading has the class `example`, an
5671+ `exampleblock` environment will be used; if it has the class
5672+ `alert`, an `alertblock` will be used; otherwise a regular
5673+ `block` will be used.)
56705674
56715675 * Headings *above* the slide level in the hierarchy create
56725676 "title slides," which just contain the section title
src/Text/Pandoc/Writers/LaTeX.hs+8−3
@@ -290,7 +290,12 @@ blockToLaTeX :: PandocMonad m
290290 => Block -- ^ Block to convert
291291 -> LW m (Doc Text)
292292blockToLaTeX Null = return empty
293−blockToLaTeX (Div attr@(identifier,"block":_,_) (Header _ _ ils : bs)) = do
293+blockToLaTeX (Div attr@(identifier,"block":dclasses,_)
294+ (Header _ _ ils : bs)) = do
295+ let blockname
296+ | "example" `elem` dclasses = "exampleblock"
297+ | "alert" `elem` dclasses = "alertblock"
298+ | otherwise = "block"
294299 ref <- toLabel identifier
295300 let anchor = if T.null identifier
296301 then empty
@@ -298,8 +303,8 @@ blockToLaTeX (Div attr@(identifier,"block":_,_) (Header _ _ ils : bs)) = do
298303 braces (literal ref) <> braces empty
299304 title' <- inlineListToLaTeX ils
300305 contents <- blockListToLaTeX bs
301− wrapDiv attr $ ("\\begin{block}" <> braces title' <> anchor) $$
302− contents $$ "\\end{block}"
306+ wrapDiv attr $ ("\\begin" <> braces blockname <> braces title' <> anchor) $$
307+ contents $$ "\\end" <> braces blockname
303308blockToLaTeX (Div (identifier,"slide":dclasses,dkvs)
304309 (Header _ (_,hclasses,hkvs) ils : bs)) = do
305310 -- note: [fragile] is required or verbatim breaks
test/command/7278.mdnew file+38
@@ -0,0 +1,38 @@
1+```
2+% pandoc -t beamer
3+# Slide
4+
5+Some blocks:
6+
7+## example block title {.example}
8+
9+text in block
10+
11+## alert block title {.alert}
12+
13+text in block
14+
15+## block title
16+
17+text in block
18+^D
19+\begin{frame}{Slide}
20+\protect\hypertarget{slide}{}
21+Some blocks:
22+
23+\begin{exampleblock}{example block title}
24+\protect\hypertarget{example-block-title}{}
25+text in block
26+\end{exampleblock}
27+
28+\begin{alertblock}{alert block title}
29+\protect\hypertarget{alert-block-title}{}
30+text in block
31+\end{alertblock}
32+
33+\begin{block}{block title}
34+\protect\hypertarget{block-title}{}
35+text in block
36+\end{block}
37+\end{frame}
38+```