Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML writer: unwrap incremental divs without other attributes #10330

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
```