diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index bf90919d293..cbd63649155 100644 --- a/news/changelog-1.6.md +++ b/news/changelog-1.6.md @@ -50,6 +50,7 @@ All changes included in 1.6: - ([#10887](https://github.com/quarto-dev/quarto-cli/issues/10887)): Updating default Mathjax used from 2.7.0 to 2.7.9. - ([#9999](https://github.com/quarto-dev/quarto-cli/issues/9999)): Fix spacing problems of different size elements in columns. - ([#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. `## `. +- ([#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`. ## `typst` Format diff --git a/src/resources/filters/modules/constants.lua b/src/resources/filters/modules/constants.lua index 82d034a20af..7153e486581 100644 --- a/src/resources/filters/modules/constants.lua +++ b/src/resources/filters/modules/constants.lua @@ -39,6 +39,8 @@ local kDataCodeCellLines = 'data-code-lines' local kDataCodeCellAnnotation = 'data-code-annotation' local kDataCodeAnnonationClz = 'code-annotation-code' local kCodeAnnotationStyleNone = "none" +local kCodeAnnotationStyleHover = "hover" +local kCodeAnnotationStyleSelect = "select" local kCodeLine = "code-line" local kCodeLines = "code-lines" local kCellAnnotationClass = "cell-annotation" @@ -155,6 +157,9 @@ local kBackgroundColorWarning = "fcefdc" local kBackgroundColorTip = "ccf1e3" local kBackgroundColorCaution = "ffe5d0" +-- Pandoc classes for incremental flag +local kIncremental = "incremental" +local kNonIncremental = "nonincremental" return { kCitation = kCitation, @@ -194,6 +199,8 @@ return { kDataCodeCellAnnotation = kDataCodeCellAnnotation, kDataCodeAnnonationClz = kDataCodeAnnonationClz, kCodeAnnotationStyleNone = kCodeAnnotationStyleNone, + kCodeAnnotationStyleHover = kCodeAnnotationStyleHover, + kCodeAnnotationStyleSelect = kCodeAnnotationStyleSelect, kCodeLine = kCodeLine, kCodeLines = kCodeLines, kCellAnnotationClass = kCellAnnotationClass, @@ -245,4 +252,7 @@ return { kBackgroundColorWarning = kBackgroundColorWarning, kBackgroundColorTip = kBackgroundColorTip, kBackgroundColorCaution = kBackgroundColorCaution, + + kIncremental = kIncremental, + kNonIncremental = kNonIncremental } diff --git a/src/resources/filters/quarto-pre/code-annotation.lua b/src/resources/filters/quarto-pre/code-annotation.lua index 4cc3b0d2798..4fa26cf24a6 100644 --- a/src/resources/filters/quarto-pre/code-annotation.lua +++ b/src/resources/filters/quarto-pre/code-annotation.lua @@ -293,6 +293,13 @@ function code_annotations() -- an id counter to provide nice numeric ids to cell local idCounter = 1 + -- the user request code annotations value + local codeAnnotations = param(constants.kCodeAnnotationsParam) + + local requireNonIncremental = PANDOC_WRITER_OPTIONS[constants.kIncremental] and ( + codeAnnotations == constants.kCodeAnnotationStyleSelect or codeAnnotations == constants.kCodeAnnotationStyleHover + ) + -- walk the blocks and look for annotated code -- process the list top down so that we see the outer -- code divs first @@ -300,9 +307,6 @@ function code_annotations() traverse = 'topdown', Blocks = function(blocks) - -- the user request code annotations value - local codeAnnotations = param(constants.kCodeAnnotationsParam) - -- if code annotations is false, then shut it down if codeAnnotations ~= false then @@ -540,7 +544,7 @@ function code_annotations() if codeAnnotations ~= constants.kCodeAnnotationStyleNone then if pendingCodeCell ~= nil then -- wrap the definition list in a cell - local dlDiv = pandoc.Div({dl}, pandoc.Attr("", {constants.kCellAnnotationClass})) + local dlDiv = pandoc.Div({dl}, pandoc.Attr("", {constants.kCellAnnotationClass, requireNonIncremental and constants.kNonIncremental or nil })) if is_custom_node(pendingCodeCell) then local custom = _quarto.ast.resolve_custom_data(pendingCodeCell) or pandoc.Div({}) -- won't happen but the Lua analyzer doesn't know it custom.content:insert(2, dlDiv) @@ -549,7 +553,12 @@ function code_annotations() end flushPending() else - outputBlockClearPending(dl) + if requireNonIncremental then + -- wrap in Non Incremental Div to prevent automatique + outputBlockClearPending(pandoc.Div({dl}, pandoc.Attr("", {constants.kNonIncremental}))) + else + outputBlockClearPending(dl) + end end else flushPending() diff --git a/tests/docs/smoke-all/2024/10/23/7142/below.qmd b/tests/docs/smoke-all/2024/10/23/7142/below.qmd new file mode 100644 index 00000000000..2b4a6f33c25 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/23/7142/below.qmd @@ -0,0 +1,32 @@ +--- +title: Code annotaton and incremental +format: + revealjs: + incremental: true + code-annotations: below +_quarto: + tests: + revealjs: + ensureHtmlElements: + - ['dt.fragment', 'dd.fragment'] + - [] + ensureFileRegexMatches: + - [] + - [] +--- + +## First slide + +## Slides with annotations + +``` python +1 + 1 # <1> +x = 2 # <2> +x + 3 # <3> +``` + +1. Note 1 +2. Note 2 +3. Note 3 + +## Last slide \ No newline at end of file diff --git a/tests/docs/smoke-all/2024/10/23/7142/hover.qmd b/tests/docs/smoke-all/2024/10/23/7142/hover.qmd new file mode 100644 index 00000000000..1bf6f82311e --- /dev/null +++ b/tests/docs/smoke-all/2024/10/23/7142/hover.qmd @@ -0,0 +1,32 @@ +--- +title: Code annotaton and incremental +format: + revealjs: + incremental: true + code-annotations: hover +_quarto: + tests: + revealjs: + ensureHtmlElements: + - [] + - ['.fragment'] + ensureFileRegexMatches: + - [] + - [] +--- + +## First slide + +## Slides with annotations + +``` python +1 + 1 # <1> +x = 2 # <2> +x + 3 # <3> +``` + +1. Note 1 +2. Note 2 +3. Note 3 + +## Last slide \ No newline at end of file diff --git a/tests/docs/smoke-all/2024/10/23/7142/select.qmd b/tests/docs/smoke-all/2024/10/23/7142/select.qmd new file mode 100644 index 00000000000..18cc0c68b4d --- /dev/null +++ b/tests/docs/smoke-all/2024/10/23/7142/select.qmd @@ -0,0 +1,32 @@ +--- +title: Code annotaton and incremental +format: + revealjs: + incremental: true + code-annotations: select +_quarto: + tests: + revealjs: + ensureHtmlElements: + - [] + - ['.fragment'] + ensureFileRegexMatches: + - [] + - [] +--- + +## First slide + +## Slides with annotations + +``` python +1 + 1 # <1> +x = 2 # <2> +x + 3 # <3> +``` + +1. Note 1 +2. Note 2 +3. Note 3 + +## Last slide \ No newline at end of file