Skip to content

Commit

Permalink
HTML writer: unwrap empty incremental divs
Browse files Browse the repository at this point in the history
Divs are unwrapped if the only purpose of the div seems to be to control
whether lists are presented incrementally on slides.

Closes: #10328
  • Loading branch information
tarleb authored and jgm committed Oct 23, 2024
1 parent daef2fd commit 4c66bf2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/Text/Pandoc/Writers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,15 @@ blockToHtmlInner opts (Div attr@(ident, classes, kvs') bs) = do
[("role", "listitem") | isCslBibEntry && html5]
let speakerNotes = "notes" `elem` classes
-- we don't want incremental output inside speaker notes, see #1394
let opts' = if | speakerNotes -> opts{ writerIncremental = False }
| "incremental" `elem` classes -> opts{ writerIncremental = True }
| "nonincremental" `elem` classes -> opts{ writerIncremental = False }
| otherwise -> opts
let (opts', isIncrDiv) =
if | speakerNotes ->
(opts{ writerIncremental = False }, False)
| "incremental" `elem` classes ->
(opts{ writerIncremental = True }, True)
| "nonincremental" `elem` classes ->
(opts{ writerIncremental = False }, True)
| otherwise ->
(opts, False)
-- we remove "incremental" and "nonincremental" if we're in a
-- slide presentation format.
classes' = case slideVariant of
Expand All @@ -886,18 +891,22 @@ blockToHtmlInner opts (Div attr@(ident, classes, kvs') bs) = do
let (divtag, classes'') = if html5 && "section" `elem` classes'
then (H5.section, filter (/= "section") classes')
else (H.div, classes')
if speakerNotes
then case slideVariant of
RevealJsSlides -> addAttrs opts' attr $
H5.aside contents'
DZSlides -> do
t <- addAttrs opts' attr $
H5.div contents'
return $ t ! A5.role "note"
NoSlides -> addAttrs opts' attr $
H.div contents'
_ -> return mempty
else addAttrs opts (ident, classes'', kvs) $
if | isIncrDiv && (ident, classes'', kvs) == nullAttr ->
-- Unwrap divs that only have (non)increment information
pure contents
| speakerNotes ->
case slideVariant of
RevealJsSlides -> addAttrs opts' attr $
H5.aside contents'
DZSlides -> do
t <- addAttrs opts' attr $
H5.div contents'
return $ t ! A5.role "note"
NoSlides -> addAttrs opts' attr $
H.div contents'
_ -> return mempty
| otherwise ->
addAttrs opts (ident, classes'', kvs) $
divtag contents'
blockToHtmlInner opts (RawBlock f str) = do
ishtml <- isRawHtml f
Expand Down
37 changes: 37 additions & 0 deletions test/command/10328.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Unwrap divs if they only have the `nonincremental` or `incremental` classes.

```
% pandoc --incremental --from=markdown --to=revealjs
## First slide
::: nonincremental
1. Note 1
2. Note 2
3. Note 3
:::
## Second Slide
1. Note 1
2. Note 2
3. Note 3
^D
<section id="first-slide" class="slide level2">
<h2>First slide</h2>
<ol type="1">
<li>Note 1</li>
<li>Note 2</li>
<li>Note 3</li>
</ol>
</section>
<section id="second-slide" class="slide level2">
<h2>Second Slide</h2>
<ol type="1">
<li class="fragment">Note 1</li>
<li class="fragment">Note 2</li>
<li class="fragment">Note 3</li>
</ol>
</section>
```

0 comments on commit 4c66bf2

Please sign in to comment.