From bb76dec8435dc03db3662175e7c02dfc69771176 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 23 Oct 2024 16:13:13 +0200 Subject: [PATCH 1/5] Wrap in nonincremental div code annotation definition list to prevent incremental applying Only do it when `incremental: true` is set This leaves behind an empty
element in the output, which is not ideal. --- src/resources/filters/modules/constants.lua | 6 ++++++ src/resources/filters/quarto-pre/code-annotation.lua | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/resources/filters/modules/constants.lua b/src/resources/filters/modules/constants.lua index 82d034a20a..959ff34900 100644 --- a/src/resources/filters/modules/constants.lua +++ b/src/resources/filters/modules/constants.lua @@ -155,6 +155,9 @@ local kBackgroundColorWarning = "fcefdc" local kBackgroundColorTip = "ccf1e3" local kBackgroundColorCaution = "ffe5d0" +-- Pandoc classes for incremental flag +local kIncremental = "incremental" +local kNonIncremental = "nonincremental" return { kCitation = kCitation, @@ -245,4 +248,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 4cc3b0d279..cbf1405ee2 100644 --- a/src/resources/filters/quarto-pre/code-annotation.lua +++ b/src/resources/filters/quarto-pre/code-annotation.lua @@ -293,6 +293,8 @@ function code_annotations() -- an id counter to provide nice numeric ids to cell local idCounter = 1 + local isIncrementalDoc = PANDOC_WRITER_OPTIONS[constants.kIncremental] + -- walk the blocks and look for annotated code -- process the list top down so that we see the outer -- code divs first @@ -540,7 +542,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, isIncrementalDoc 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 +551,12 @@ function code_annotations() end flushPending() else - outputBlockClearPending(dl) + if isIncrementalDoc then + -- wrap in Non Incremental Div to prevent automatique + outputBlockClearPending(pandoc.Div({dl}, pandoc.Attr("", {constants.kNonIncremental}))) + else + outputBlockClearPending(dl) + end end else flushPending() From 820c9983da58e7a1ecdae0fd2b2fc05259a51b53 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 23 Oct 2024 16:18:59 +0200 Subject: [PATCH 2/5] Add a test for code annotation and incremental in revealjs --- tests/docs/smoke-all/2024/10/23/7142.qmd | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/docs/smoke-all/2024/10/23/7142.qmd diff --git a/tests/docs/smoke-all/2024/10/23/7142.qmd b/tests/docs/smoke-all/2024/10/23/7142.qmd new file mode 100644 index 0000000000..1bf6f82311 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/23/7142.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 From 105f09340609f2b71613a67e8b34c71256ca34c0 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 23 Oct 2024 16:44:39 +0200 Subject: [PATCH 3/5] split test files to cover all code-annotations --- .../docs/smoke-all/2024/10/23/7142/below.qmd | 32 +++++++++++++++++++ .../2024/10/23/{7142.qmd => 7142/hover.qmd} | 0 .../docs/smoke-all/2024/10/23/7142/select.qmd | 32 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 tests/docs/smoke-all/2024/10/23/7142/below.qmd rename tests/docs/smoke-all/2024/10/23/{7142.qmd => 7142/hover.qmd} (100%) create mode 100644 tests/docs/smoke-all/2024/10/23/7142/select.qmd 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 0000000000..bf44294994 --- /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: + - [] + - ['.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.qmd b/tests/docs/smoke-all/2024/10/23/7142/hover.qmd similarity index 100% rename from tests/docs/smoke-all/2024/10/23/7142.qmd rename to tests/docs/smoke-all/2024/10/23/7142/hover.qmd 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 0000000000..18cc0c68b4 --- /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 From e235cfb41ec07fc726981950415aaff125233333 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 23 Oct 2024 18:35:54 +0200 Subject: [PATCH 4/5] `code-annotation: below` should be an incremental list when `incremental: true` This is how it is working in Quarto 1.5 and previous --- src/resources/filters/modules/constants.lua | 4 ++++ .../filters/quarto-pre/code-annotation.lua | 14 ++++++++------ tests/docs/smoke-all/2024/10/23/7142/below.qmd | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/resources/filters/modules/constants.lua b/src/resources/filters/modules/constants.lua index 959ff34900..7153e48658 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" @@ -197,6 +199,8 @@ return { kDataCodeCellAnnotation = kDataCodeCellAnnotation, kDataCodeAnnonationClz = kDataCodeAnnonationClz, kCodeAnnotationStyleNone = kCodeAnnotationStyleNone, + kCodeAnnotationStyleHover = kCodeAnnotationStyleHover, + kCodeAnnotationStyleSelect = kCodeAnnotationStyleSelect, kCodeLine = kCodeLine, kCodeLines = kCodeLines, kCellAnnotationClass = kCellAnnotationClass, diff --git a/src/resources/filters/quarto-pre/code-annotation.lua b/src/resources/filters/quarto-pre/code-annotation.lua index cbf1405ee2..4fa26cf24a 100644 --- a/src/resources/filters/quarto-pre/code-annotation.lua +++ b/src/resources/filters/quarto-pre/code-annotation.lua @@ -293,7 +293,12 @@ function code_annotations() -- an id counter to provide nice numeric ids to cell local idCounter = 1 - local isIncrementalDoc = PANDOC_WRITER_OPTIONS[constants.kIncremental] + -- 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 @@ -302,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 @@ -542,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, isIncrementalDoc and constants.kNonIncremental or nil })) + 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) @@ -551,7 +553,7 @@ function code_annotations() end flushPending() else - if isIncrementalDoc then + if requireNonIncremental then -- wrap in Non Incremental Div to prevent automatique outputBlockClearPending(pandoc.Div({dl}, pandoc.Attr("", {constants.kNonIncremental}))) else diff --git a/tests/docs/smoke-all/2024/10/23/7142/below.qmd b/tests/docs/smoke-all/2024/10/23/7142/below.qmd index bf44294994..2b4a6f33c2 100644 --- a/tests/docs/smoke-all/2024/10/23/7142/below.qmd +++ b/tests/docs/smoke-all/2024/10/23/7142/below.qmd @@ -8,8 +8,8 @@ _quarto: tests: revealjs: ensureHtmlElements: + - ['dt.fragment', 'dd.fragment'] - [] - - ['.fragment'] ensureFileRegexMatches: - [] - [] From abcf1893bce3aac6d26f30b78396338e4933f307 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 24 Oct 2024 10:14:04 +0200 Subject: [PATCH 5/5] Add to changelog [skip ci] --- news/changelog-1.6.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index bf90919d29..cbd6364915 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