Skip to content

Commit 7039273

Browse files
authored
feat: add code-line-fragment-indices for Reveal.js line highlights (#15293)
Stepped line highlights in Reveal.js take the next free fragment index, so a highlight cannot sit between other fragments such as notes on the slide. The new code-line-fragment-indices attribute and cell option set the index of each highlight step after the first. The first step is the code block itself and still shows when the slide opens. - Accept a comma-separated string, a single number, or a YAML list. - Require non-negative integers in strictly increasing order. Otherwise warn at render time and keep the default order. - Keep the attribute only for Reveal.js with stepped code-line-numbers, and pass it through knitr, Jupyter and OJS cells. Fixes #7378 Fixes #11585
1 parent d5e0617 commit 7039273

23 files changed

Lines changed: 805 additions & 12 deletions

‎news/changelog-1.12.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ All changes included in 1.12:
2222

2323
- ([#15251](https://github.com/quarto-dev/quarto-cli/pull/15251)): Fix algorithm blocks (`#alg-`) being set in italics. Their body is now upright, like definitions, examples and exercises. (author: @mcanouil)
2424

25+
### `revealjs`
26+
27+
- ([#7378](https://github.com/quarto-dev/quarto-cli/issues/7378)): Add `code-line-fragment-indices` to set the fragment index of each step of stepped `code-line-numbers` highlighting. (author: @mcanouil)
28+
2529
### `typst`
2630

2731
- ([#15168](https://github.com/quarto-dev/quarto-cli/issues/15168)): Fix definitions, examples and exercises being set in italics in Typst output with the default `theorem-appearance: simple`. Their body is now upright, as in LaTeX output, while theorems, lemmas, corollaries, propositions and conjectures keep an italic body. (author: @mcanouil)

‎src/config/constants.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export const kFigEnv = "fig-env";
108108
export const kFigPos = "fig-pos";
109109
export const kCodeFold = "code-fold";
110110
export const kCodeLineNumbers = "code-line-numbers";
111+
export const kCodeLineFragmentIndices = "code-line-fragment-indices";
111112
export const kCodeOverflow = "code-overflow";
112113
export const kCodeLink = "code-link";
113114
export const kCodeTools = "code-tools";

‎src/core/handlers/base.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
kCellPanel,
5555
kCellTblColumn,
5656
kCodeFold,
57+
kCodeLineFragmentIndices,
5758
kCodeLineNumbers,
5859
kCodeOverflow,
5960
kCodeSummary,
@@ -807,6 +808,7 @@ export function getDivAttributes(
807808
kCellLstLabel,
808809
kCodeFold,
809810
kCodeLineNumbers,
811+
kCodeLineFragmentIndices,
810812
kCodeSummary,
811813
kCodeOverflow,
812814
kCellClasses,

‎src/core/jupyter/jupyter.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ import {
106106
kCellTblColumn,
107107
kCellWidth,
108108
kCodeFold,
109+
kCodeLineFragmentIndices,
109110
kCodeLineNumbers,
110111
kCodeOverflow,
111112
kCodeSummary,
@@ -228,6 +229,7 @@ export const kJupyterCellInternalOptionKeys = [
228229
kCellMdIndent,
229230
kCodeFold,
230231
kCodeLineNumbers,
232+
kCodeLineFragmentIndices,
231233
kCodeSummary,
232234
kCodeOverflow,
233235
kHtmlTableProcessing,
@@ -1508,6 +1510,13 @@ async function mdFromCodeCell(
15081510
if (typeof cell.options[kCodeLineNumbers] !== "undefined") {
15091511
md.push(` code-line-numbers=\"${cell.options[kCodeLineNumbers]}\"`);
15101512
}
1513+
if (typeof cell.options[kCodeLineFragmentIndices] !== "undefined") {
1514+
md.push(
1515+
` code-line-fragment-indices=\"${
1516+
[cell.options[kCodeLineFragmentIndices]].flat().join(",")
1517+
}\"`,
1518+
);
1519+
}
15111520
}
15121521
md.push("}\n");
15131522
let source = typeof cell.source === "string"

‎src/core/jupyter/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
kCellTblColumn,
3737
kCellUserExpressions,
3838
kCodeFold,
39+
kCodeLineFragmentIndices,
3940
kCodeLineNumbers,
4041
kCodeOverflow,
4142
kCodeSummary,
@@ -216,6 +217,7 @@ export interface JupyterCellOptions extends JupyterOutputFigureOptions {
216217
[kCellColumn]?: string;
217218
[kCodeFold]?: string;
218219
[kCodeLineNumbers]?: boolean | string;
220+
[kCodeLineFragmentIndices]?: string | number | number[];
219221
[kCodeSummary]?: string;
220222
[kCodeOverflow]?: string;
221223
[kCellMdIndent]?: string;

‎src/execute/ojs/compile.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
kCellLstCap,
4646
kCellLstLabel,
4747
kCodeFold,
48+
kCodeLineFragmentIndices,
4849
kCodeLineNumbers,
4950
kCodeOverflow,
5051
kEcho,
@@ -517,6 +518,14 @@ export async function ojsCompile(
517518
);
518519
}
519520

521+
if (typeof cell.options?.[kCodeLineFragmentIndices] !== "undefined") {
522+
srcAttrs.push(
523+
`${kCodeLineFragmentIndices}="${
524+
[cell.options?.[kCodeLineFragmentIndices]].flat().join(",")
525+
}"`,
526+
);
527+
}
528+
520529
const srcConfig = {
521530
classes: srcClasses.slice(),
522531
attrs: srcAttrs.slice(),

‎src/resources/editor/tools/attrs.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@
315315
doc: Show line numbers for code block
316316
- value: 'code-line-numbers="false"'
317317
doc: Do not show line numbers for code block
318+
- value: 'code-line-fragment-indices="$0"'
319+
doc: Fragment index of each code line highlight step (Reveal.js only)
318320
- value: 'shortcodes="false"'
319321
doc: Do not process shortcodes in this code block
320322

‎src/resources/editor/tools/vs-code.mjs‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7459,6 +7459,31 @@ var init_yaml_intelligence_resources = __esm({
74597459
long: "Include line numbers in code block output (`true` or `false`).\n\nFor revealjs output only, you can also specify a string to highlight\nspecific lines (and/or animate between sets of highlighted lines).\n\n* Sets of lines are denoted with commas:\n * `3,4,5`\n * `1,10,12`\n* Ranges can be denoted with dashes and combined with commas:\n * `1-3,5` \n * `5-10,12,14`\n* Finally, animation steps are separated by `|`:\n * `1-3|1-3,5` first shows `1-3`, then `1-3,5`\n * `|5|5-10,12` first shows no numbering, then 5, then lines 5-10\n and 12\n"
74607460
}
74617461
},
7462+
{
7463+
name: "code-line-fragment-indices",
7464+
tags: {
7465+
formats: [
7466+
"revealjs"
7467+
]
7468+
},
7469+
schema: {
7470+
anyOf: [
7471+
{
7472+
string: {
7473+
pattern: "^\\s*\\d+\\s*(,\\s*\\d+\\s*)*$"
7474+
}
7475+
},
7476+
{
7477+
maybeArrayOf: "number"
7478+
}
7479+
],
7480+
errorDescription: "be a non-negative integer, a list of them, or a comma-separated string of them, such as `1,2`"
7481+
},
7482+
description: {
7483+
short: "Fragment index of each step of stepped code-line-numbers highlighting (Reveal.js only).",
7484+
long: 'Fragment index of each step of stepped `code-line-numbers` highlighting\n(Reveal.js only).\n\nGive one index for each step after the first, as a comma-separated list\nof non-negative integers, a YAML list, or a single number.\nThe indices must be strictly increasing.\nEach value places its highlight step among the other fragments of the\nslide, in the same way as `fragment-index` on any other fragment.\nA lower value shows earlier.\nFor example, `code-line-numbers: "|1|2"` with\n`code-line-fragment-indices: "1,2"` shows line 1 at fragment index 1 and\nline 2 at fragment index 2.\n\nThe first step is the code block itself and is not a fragment.\nStart `code-line-numbers` with `|` to give the first highlight its own\nindex.\n\nThe number of indices must equal the number of steps minus one.\nIf it does not, or if the indices are not strictly increasing,\nthe list is ignored, a warning is printed, and the steps use\nthe default order.\n'
7485+
}
7486+
},
74627487
{
74637488
name: "lst-label",
74647489
schema: "string",
@@ -23555,6 +23580,10 @@ var init_yaml_intelligence_resources = __esm({
2355523580
short: "Include line numbers in code block output (<code>true</code> or\n<code>false</code>)",
2355623581
long: "Include line numbers in code block output (<code>true</code> or\n<code>false</code>).\nFor revealjs output only, you can also specify a string to highlight\nspecific lines (and/or animate between sets of highlighted lines)."
2355723582
},
23583+
{
23584+
short: "Fragment index of each step of stepped code-line-numbers highlighting\n(Reveal.js only).",
23585+
long: 'Fragment index of each step of stepped <code>code-line-numbers</code>\nhighlighting (Reveal.js only).\nGive one index for each step after the first, as a comma-separated\nlist of non-negative integers, a YAML list, or a single number. The\nindices must be strictly increasing. Each value places its highlight\nstep among the other fragments of the slide, in the same way as\n<code>fragment-index</code> on any other fragment. A lower value shows\nearlier. For example, <code>code-line-numbers: "|1|2"</code> with\n<code>code-line-fragment-indices: "1,2"</code> shows line 1 at fragment\nindex 1 and line 2 at fragment index 2.\nThe first step is the code block itself and is not a fragment. Start\n<code>code-line-numbers</code> with <code>|</code> to give the first\nhighlight its own index.\nThe number of indices must equal the number of steps minus one. If it\ndoes not, or if the indices are not strictly increasing, the list is\nignored, a warning is printed, and the steps use the default order.'
23586+
},
2355823587
"Unique label for code listing (used in cross references)",
2355923588
"Caption for code listing",
2356023589
"Whether to reformat R code.",
@@ -25848,12 +25877,12 @@ var init_yaml_intelligence_resources = __esm({
2584825877
mermaid: "%%"
2584925878
},
2585025879
"handlers/mermaid/schema.yml": {
25851-
_internalId: 221307,
25880+
_internalId: 222271,
2585225881
type: "object",
2585325882
description: "be an object",
2585425883
properties: {
2585525884
"mermaid-format": {
25856-
_internalId: 221299,
25885+
_internalId: 222263,
2585725886
type: "enum",
2585825887
enum: [
2585925888
"png",
@@ -25869,7 +25898,7 @@ var init_yaml_intelligence_resources = __esm({
2586925898
exhaustiveCompletions: true
2587025899
},
2587125900
theme: {
25872-
_internalId: 221306,
25901+
_internalId: 222270,
2587325902
type: "anyOf",
2587425903
anyOf: [
2587525904
{

‎src/resources/editor/tools/yaml/all-schema-definitions.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎src/resources/editor/tools/yaml/web-worker.js‎

Lines changed: 32 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)