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.
This commit is contained in:
John MacFarlane 2021-05-14 10:09:02 -07:00
parent b9b1ec586a
commit 76a4e7127b
3 changed files with 51 additions and 4 deletions

View file

@ -5666,7 +5666,11 @@ rules:
* A heading at the slide level always starts a new slide.
* Headings *below* the slide level in the hierarchy create
headings *within* a slide.
headings *within* a slide. (In beamer, a "block" will be
created. If the heading has the class `example`, an
`exampleblock` environment will be used; if it has the class
`alert`, an `alertblock` will be used; otherwise a regular
`block` will be used.)
* Headings *above* the slide level in the hierarchy create
"title slides," which just contain the section title

View file

@ -290,7 +290,12 @@ blockToLaTeX :: PandocMonad m
=> Block -- ^ Block to convert
-> LW m (Doc Text)
blockToLaTeX Null = return empty
blockToLaTeX (Div attr@(identifier,"block":_,_) (Header _ _ ils : bs)) = do
blockToLaTeX (Div attr@(identifier,"block":dclasses,_)
(Header _ _ ils : bs)) = do
let blockname
| "example" `elem` dclasses = "exampleblock"
| "alert" `elem` dclasses = "alertblock"
| otherwise = "block"
ref <- toLabel identifier
let anchor = if T.null identifier
then empty
@ -298,8 +303,8 @@ blockToLaTeX (Div attr@(identifier,"block":_,_) (Header _ _ ils : bs)) = do
braces (literal ref) <> braces empty
title' <- inlineListToLaTeX ils
contents <- blockListToLaTeX bs
wrapDiv attr $ ("\\begin{block}" <> braces title' <> anchor) $$
contents $$ "\\end{block}"
wrapDiv attr $ ("\\begin" <> braces blockname <> braces title' <> anchor) $$
contents $$ "\\end" <> braces blockname
blockToLaTeX (Div (identifier,"slide":dclasses,dkvs)
(Header _ (_,hclasses,hkvs) ils : bs)) = do
-- note: [fragile] is required or verbatim breaks

38
test/command/7278.md Normal file
View file

@ -0,0 +1,38 @@
```
% pandoc -t beamer
# Slide
Some blocks:
## example block title {.example}
text in block
## alert block title {.alert}
text in block
## block title
text in block
^D
\begin{frame}{Slide}
\protect\hypertarget{slide}{}
Some blocks:
\begin{exampleblock}{example block title}
\protect\hypertarget{example-block-title}{}
text in block
\end{exampleblock}
\begin{alertblock}{alert block title}
\protect\hypertarget{alert-block-title}{}
text in block
\end{alertblock}
\begin{block}{block title}
\protect\hypertarget{block-title}{}
text in block
\end{block}
\end{frame}
```