Repository navigation
feat: add code-line-fragment-indices for Reveal.js line highlights - #15293
Conversation
…keep it out of serialised options
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
cderv
left a comment
There was a problem hiding this comment.
Thanks for this, the approach looks good to me. I have two questions before going further.
Indices out of order
Upstream reveal.js only has a start index for the steps (data-fragment-index on <code>, then +1 for each step, see hakimel/reveal.js#3055), so this goes further and we need to decide how an arbitrary list behaves.
The list is accepted in any order, but the clones are stacked in the order of code-line-numbers, and a later clone covers the earlier ones once visible. With this
```{.r code-line-numbers="|1|2" code-line-fragment-indices="4,2"}
x <- 1
y <- 2
```line 2 is highlighted first, then at index 4 the line 1 clone becomes visible but stays under the line 2 one, so the line 1 highlight never shows. With "2,2" both clones show at the same time and only line 2 is seen. The render gives no warning in both cases.
Should we warn and fall back like for a wrong count, when the indices are not strictly increasing ? Or do you want to support any order by appending the clones sorted by index (the hidden handler scrolls to previousSibling, so it would need the same order) ?
Number and list values in cell options
For a cell with a single step, the natural way to write it is
#| code-line-numbers: "|1"
#| code-line-fragment-indices: 2but YAML gives a number, and the schema only accepts a string, so the render fails with Field "code-line-fragment-indices" has value 2, which must instead be a comma-separated list of non-negative integers. Same for [2, 4]. It is a hard error for knitr and Jupyter cells, not the warning and fallback the PR description mentions (that one applies to the code block attribute).
Did you consider accepting a number, and maybe a list of numbers, like code-line-numbers accepts a boolean or a string ? knitr and Jupyter would then need to turn it into the comma-separated string for the attribute.
One smaller thing, the OJS path has no fixture. I checked by hand that an {ojs} cell does get data-code-line-fragment-indices on the source block, so adding it to the smoke-all tests would keep it covered.
|
Thanks. For the order, I'll require strictly increasing indices. You're right about cell options too. I'll add tests for |
…s and lists Indices that are not strictly increasing hid a highlight step, so they now trigger the warning and fall back to the default order. Cell options accept a number or a list of numbers as well as a string, and knitr, Jupyter and OJS turn them into the comma-separated attribute. Tests cover decreasing and equal indices, number and list values, and an OJS cell.
cderv
left a comment
There was a problem hiding this comment.
Thanks, the strict ordering check and the number and list forms look good to me. Ready to merge.
Description
Stepped line highlighting in Reveal.js gives each highlight step the next free fragment index.
So a highlight can't sit between other fragments on the slide, such as a note on each line.
This adds a
code-line-fragment-indicesattribute and cell option that sets the index of each step after the first.The first step is the code block itself, so it still shows when the slide opens.
::: {.fragment fragment-index=1} First note. ::: ```{.python code-line-numbers="|1|2" code-line-fragment-indices="2,4"} x = [1, 2, 3] print(x) ``` ::: {.fragment fragment-index=3} Second note. :::The video steps the same slide through four clicks, without the attribute on the left and with
"2,4"on the right.On the left, both notes appear before any line is highlighted.
On the right, note 1, line 1, note 2 and line 2 appear in turn.
code-line-fragment-indices.mp4
The list must hold one non-negative integer for each step after the first, in strictly increasing order.
If it doesn't, the render prints a warning and the slide keeps the current order.
In a cell, the option can be a comma-separated string, a single number or a YAML list.
The Lua filter keeps the attribute only for Reveal.js with stepped
code-line-numbers, and knitr, Jupyter and OJS cells pass the option through.Without the attribute, decks behave as before.
Highlighted lines meet the 4.5:1 contrast ratio.
Dimmed lines are at 2.26:1, from the existing 0.4 opacity, which this doesn't change.
Closes #7378.
Closes #11585.
Docs: quarto-dev/quarto-web#2340.
Checklist
I have (if applicable):
AI-assisted PR
Note: autonomous AI agents submitting PRs without human oversight are not permitted — see the Code of Conduct.