Skip to content

Commit e928dd8

Browse files
authored
Merge pull request #11170 from quarto-dev/revealjs/code-annotation-incremental
2 parents b1e5d9c + abcf189 commit e928dd8

File tree

6 files changed

+121
-5
lines changed

6 files changed

+121
-5
lines changed

news/changelog-1.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ All changes included in 1.6:
5050
- ([#10887](https://github.com/quarto-dev/quarto-cli/issues/10887)): Updating default Mathjax used from 2.7.0 to 2.7.9.
5151
- ([#9999](https://github.com/quarto-dev/quarto-cli/issues/9999)): Fix spacing problems of different size elements in columns.
5252
- ([#11146](https://github.com/quarto-dev/quarto-cli/issues/11146)): Fix issue with slide created with `---` and having no title showing up in TOC. Now they don't show up as slide created with empty header e.g. `## `.
53+
- ([#7142](https://github.com/quarto-dev/quarto-cli/issues/7142)): Fix issue in slides with `incremental: true` not working as expected when `code-annotation: hover` or `code-annotation: select`.
5354

5455
## `typst` Format
5556

src/resources/filters/modules/constants.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ local kDataCodeCellLines = 'data-code-lines'
3939
local kDataCodeCellAnnotation = 'data-code-annotation'
4040
local kDataCodeAnnonationClz = 'code-annotation-code'
4141
local kCodeAnnotationStyleNone = "none"
42+
local kCodeAnnotationStyleHover = "hover"
43+
local kCodeAnnotationStyleSelect = "select"
4244
local kCodeLine = "code-line"
4345
local kCodeLines = "code-lines"
4446
local kCellAnnotationClass = "cell-annotation"
@@ -155,6 +157,9 @@ local kBackgroundColorWarning = "fcefdc"
155157
local kBackgroundColorTip = "ccf1e3"
156158
local kBackgroundColorCaution = "ffe5d0"
157159

160+
-- Pandoc classes for incremental flag
161+
local kIncremental = "incremental"
162+
local kNonIncremental = "nonincremental"
158163

159164
return {
160165
kCitation = kCitation,
@@ -194,6 +199,8 @@ return {
194199
kDataCodeCellAnnotation = kDataCodeCellAnnotation,
195200
kDataCodeAnnonationClz = kDataCodeAnnonationClz,
196201
kCodeAnnotationStyleNone = kCodeAnnotationStyleNone,
202+
kCodeAnnotationStyleHover = kCodeAnnotationStyleHover,
203+
kCodeAnnotationStyleSelect = kCodeAnnotationStyleSelect,
197204
kCodeLine = kCodeLine,
198205
kCodeLines = kCodeLines,
199206
kCellAnnotationClass = kCellAnnotationClass,
@@ -245,4 +252,7 @@ return {
245252
kBackgroundColorWarning = kBackgroundColorWarning,
246253
kBackgroundColorTip = kBackgroundColorTip,
247254
kBackgroundColorCaution = kBackgroundColorCaution,
255+
256+
kIncremental = kIncremental,
257+
kNonIncremental = kNonIncremental
248258
}

src/resources/filters/quarto-pre/code-annotation.lua

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,20 @@ function code_annotations()
293293
-- an id counter to provide nice numeric ids to cell
294294
local idCounter = 1
295295

296+
-- the user request code annotations value
297+
local codeAnnotations = param(constants.kCodeAnnotationsParam)
298+
299+
local requireNonIncremental = PANDOC_WRITER_OPTIONS[constants.kIncremental] and (
300+
codeAnnotations == constants.kCodeAnnotationStyleSelect or codeAnnotations == constants.kCodeAnnotationStyleHover
301+
)
302+
296303
-- walk the blocks and look for annotated code
297304
-- process the list top down so that we see the outer
298305
-- code divs first
299306
local code_filter = {
300307
traverse = 'topdown',
301308
Blocks = function(blocks)
302309

303-
-- the user request code annotations value
304-
local codeAnnotations = param(constants.kCodeAnnotationsParam)
305-
306310
-- if code annotations is false, then shut it down
307311
if codeAnnotations ~= false then
308312

@@ -540,7 +544,7 @@ function code_annotations()
540544
if codeAnnotations ~= constants.kCodeAnnotationStyleNone then
541545
if pendingCodeCell ~= nil then
542546
-- wrap the definition list in a cell
543-
local dlDiv = pandoc.Div({dl}, pandoc.Attr("", {constants.kCellAnnotationClass}))
547+
local dlDiv = pandoc.Div({dl}, pandoc.Attr("", {constants.kCellAnnotationClass, requireNonIncremental and constants.kNonIncremental or nil }))
544548
if is_custom_node(pendingCodeCell) then
545549
local custom = _quarto.ast.resolve_custom_data(pendingCodeCell) or pandoc.Div({}) -- won't happen but the Lua analyzer doesn't know it
546550
custom.content:insert(2, dlDiv)
@@ -549,7 +553,12 @@ function code_annotations()
549553
end
550554
flushPending()
551555
else
552-
outputBlockClearPending(dl)
556+
if requireNonIncremental then
557+
-- wrap in Non Incremental Div to prevent automatique
558+
outputBlockClearPending(pandoc.Div({dl}, pandoc.Attr("", {constants.kNonIncremental})))
559+
else
560+
outputBlockClearPending(dl)
561+
end
553562
end
554563
else
555564
flushPending()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Code annotaton and incremental
3+
format:
4+
revealjs:
5+
incremental: true
6+
code-annotations: below
7+
_quarto:
8+
tests:
9+
revealjs:
10+
ensureHtmlElements:
11+
- ['dt.fragment', 'dd.fragment']
12+
- []
13+
ensureFileRegexMatches:
14+
- []
15+
- []
16+
---
17+
18+
## First slide
19+
20+
## Slides with annotations
21+
22+
``` python
23+
1 + 1 # <1>
24+
x = 2 # <2>
25+
x + 3 # <3>
26+
```
27+
28+
1. Note 1
29+
2. Note 2
30+
3. Note 3
31+
32+
## Last slide
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Code annotaton and incremental
3+
format:
4+
revealjs:
5+
incremental: true
6+
code-annotations: hover
7+
_quarto:
8+
tests:
9+
revealjs:
10+
ensureHtmlElements:
11+
- []
12+
- ['.fragment']
13+
ensureFileRegexMatches:
14+
- []
15+
- []
16+
---
17+
18+
## First slide
19+
20+
## Slides with annotations
21+
22+
``` python
23+
1 + 1 # <1>
24+
x = 2 # <2>
25+
x + 3 # <3>
26+
```
27+
28+
1. Note 1
29+
2. Note 2
30+
3. Note 3
31+
32+
## Last slide
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Code annotaton and incremental
3+
format:
4+
revealjs:
5+
incremental: true
6+
code-annotations: select
7+
_quarto:
8+
tests:
9+
revealjs:
10+
ensureHtmlElements:
11+
- []
12+
- ['.fragment']
13+
ensureFileRegexMatches:
14+
- []
15+
- []
16+
---
17+
18+
## First slide
19+
20+
## Slides with annotations
21+
22+
``` python
23+
1 + 1 # <1>
24+
x = 2 # <2>
25+
x + 3 # <3>
26+
```
27+
28+
1. Note 1
29+
2. Note 2
30+
3. Note 3
31+
32+
## Last slide

0 commit comments

Comments
 (0)