-
Notifications
You must be signed in to change notification settings - Fork 450
fix(html): make code-tools toggle work when code-copy is enabled #14707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cderv
merged 2 commits into
quarto-dev:main
from
mcanouil:fix/13583-code-tools-code-copy
Jul 21, 2026
+106
−5
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| title: Code tools toggle with code-copy | ||
| format: html | ||
| code-fold: true | ||
| code-tools: true | ||
| code-copy: true | ||
| keep-hidden: true | ||
| --- | ||
|
|
||
| Regression test for #13583: with `code-copy` enabled (the default), each code | ||
| block is wrapped in `div.code-copy-outer-scaffold`. The "Show All Code" / | ||
| "Hide All Code" items in the `code-tools` menu must still open/close every | ||
| folded `<details>` and reveal/hide the `echo: false` cell's source. | ||
|
|
||
| ```{ojs} | ||
| x = 5 | ||
| ``` | ||
|
|
||
| ```{ojs} | ||
| //| echo: false | ||
| y = 10 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- | ||
| format: html | ||
| engine: jupyter | ||
| code-fold: true | ||
| code-tools: true | ||
| code-copy: true | ||
| keep-hidden: true | ||
| _quarto: | ||
| tests: | ||
| html: | ||
| ensureHtmlElements: | ||
| - - "details.code-fold" # folded cell survives the code-copy scaffold | ||
| - "div.code-copy-outer-scaffold > div.sourceCode" | ||
| - "div.sourceCode.cell-code.hidden" # echo: false cell | ||
| - [] | ||
| --- | ||
|
|
||
| With `code-copy` enabled (the default), each code block is wrapped in a | ||
| `div.code-copy-outer-scaffold`, which broke the "Show All Code" / "Hide All | ||
| Code" `code-tools` selectors that assumed `.sourceCode` was a direct child of | ||
| `<details>` or `.cell` (issue #13583). This document checks the post-fix DOM: | ||
| the folded cell keeps its `details.code-fold`, the scaffold wraps the | ||
| `div.sourceCode`, and the `echo: false` cell (kept via `keep-hidden: true`) | ||
| still carries `div.sourceCode.cell-code.hidden`. | ||
|
|
||
| ```{python} | ||
| print("visible, folded code") | ||
| ``` | ||
|
|
||
| ```{python} | ||
| #| echo: false | ||
| print("hidden code") | ||
| ``` |
45 changes: 45 additions & 0 deletions
45
tests/integration/playwright/tests/html-code-tools-toggle.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { expect, test } from "@playwright/test"; | ||
| import { getUrl } from "../src/utils"; | ||
|
|
||
| // Regression test for #13583. With code-copy enabled (the default), each code | ||
| // block is wrapped in div.code-copy-outer-scaffold, which used to break the | ||
| // direct-child selectors the code-tools "Show All Code" / "Hide All Code" | ||
| // handler relied on. The toggle must still open/close every folded <details> | ||
| // and swap the hidden<->unhidden class on the echo:false cell's source. | ||
| test("code-tools Show/Hide All Code toggles folded and hidden code with code-copy", async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto(getUrl("html/code-tools-toggle.html"), { | ||
| waitUntil: "load", | ||
| }); | ||
|
|
||
| const details = page.locator(".cell details.code-fold"); | ||
| const hiddenCode = page.locator("div.sourceCode.cell-code.hidden"); | ||
| const unhiddenCode = page.locator("div.sourceCode.cell-code.unhidden"); | ||
|
|
||
| // Baseline: two folded cells, both collapsed; the echo:false cell's source | ||
| // is emitted hidden (keep-hidden). | ||
| await expect(details).toHaveCount(2); | ||
| await expect(details.nth(0)).toHaveJSProperty("open", false); | ||
| await expect(details.nth(1)).toHaveJSProperty("open", false); | ||
| await expect(hiddenCode).toHaveCount(1); | ||
| await expect(unhiddenCode).toHaveCount(0); | ||
|
|
||
| // Show All Code: every <details> opens, the hidden source becomes unhidden. | ||
| await page.locator("#quarto-code-tools-menu").click(); | ||
| await page.locator("#quarto-show-all-code").click(); | ||
|
|
||
| await expect(details.nth(0)).toHaveJSProperty("open", true); | ||
| await expect(details.nth(1)).toHaveJSProperty("open", true); | ||
| await expect(hiddenCode).toHaveCount(0); | ||
| await expect(unhiddenCode).toHaveCount(1); | ||
|
|
||
| // Hide All Code: every <details> closes, the source goes back to hidden. | ||
| await page.locator("#quarto-code-tools-menu").click(); | ||
| await page.locator("#quarto-hide-all-code").click(); | ||
|
|
||
| await expect(details.nth(0)).toHaveJSProperty("open", false); | ||
| await expect(details.nth(1)).toHaveJSProperty("open", false); | ||
| await expect(hiddenCode).toHaveCount(1); | ||
| await expect(unhiddenCode).toHaveCount(0); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.