fix(markup): wrap indented code blocks for the code-copy button#37748
Conversation
Indented (4-space) code blocks were emitted by goldmark's default renderer as plain `<pre><code>` without the `code-block-container` wrapper that the JS `initMarkupCodeCopy` keys on. As a result, only fenced code blocks received the copy button. Register `ast.KindCodeBlock` with a renderer that produces the same wrapper as the highlighting renderer so both syntaxes get the button. Adds a temporary e2e test verifying the copy button on both block types. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Modern Firefox no longer needs `firefoxUserPrefs` for clipboard read, so
the conditional skip is unnecessary. Switch the copy button locator to
`getByRole('button')` and rename the loop variable.
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Moved to its own PR (go-gitea#37748) since it's an independent bug fix. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Ensures the “copy” button appears for both fenced and indented Markdown code blocks by making Goldmark render indented code blocks with the same wrapper used by the JS code-copy initializer, and adds an e2e test to validate the behavior.
Changes:
- Register a renderer for
ast.KindCodeBlockto wrap indented code blocks withcode-block-container. - Implement
renderCodeBlockto emit the wrapper +<pre><code>for indented blocks. - Add a Playwright e2e test asserting copy buttons work for both fenced and indented code blocks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/e2e/code-copy.test.ts | Adds e2e coverage ensuring copy button exists/works for both fenced and indented code blocks. |
| modules/markup/markdown/goldmark.go | Adds a Goldmark node renderer for indented code blocks that emits the wrapper required by the code-copy JS. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I couldn't reproduce goldmark will emit the Indented (4-space) code blocks. Could you have an example at gitea.com ? |
https://gitea.com/silverwind/symlink-test/src/branch/master/README.md#code-blocks
|
|
I think it needs a backend unit test, but not the e2e test See TestMarkdownFencedCodeBlock Or keeping the e2e test is fine, but backend unittest is still better to clarify the output |
|
unit test can be added additionally, but e2e test is still good because it also verifies the frontend parts. |
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
unit test added, e2e test removed |
…lock Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
* origin/main: (104 commits) fix(deps): update module github.com/go-git/go-git/v5 to v5.19.1 [security] (go-gitea#37786) fix(pull): handle empty pull request files view to allow reviews (go-gitea#37783) fix(markup): make RenderString never fail (go-gitea#37779) fix(markup): wrap indented code blocks for the code-copy button (go-gitea#37748) fix(permissions): Fix reading permission (go-gitea#37769) fix: add natural sort to sortTreeViewNodes (go-gitea#37772) fix: package creation unique conflict (go-gitea#37774) fix(deps): update npm dependencies (go-gitea#37768) fix(deps): update module gitlab.com/gitlab-org/api/client-go/v2 to v2.26.0 (go-gitea#37771) ci: split giteabot workflow (go-gitea#37770) [skip ci] Updated translations via Crowdin fix: Unify public-only token filtering in API queries and repo access checks (go-gitea#37118) fix(deps): update module google.golang.org/grpc to v1.81.1 (go-gitea#37762) chore: make DefaultTitleSource default to auto to match GitHub (go-gitea#37767) ci: fix cache-related issues (go-gitea#37761) chore: fix tests (go-gitea#37760) refactor(waitgroup): replace Add/Done goroutines with WaitGroup.Go (go-gitea#37764) fix(deps): update go dependencies (go-gitea#37752) chore(deps): update action dependencies (go-gitea#37751) fix(deps): update module github.com/google/go-github/v85 to v86 (go-gitea#37754) ... # Conflicts: # .github/workflows/pull-db-tests.yml # modules/storage/s3_test.go
…ns (#37744) - Adds a copy button to each action step header that copies the step's rendered log output to clipboard. - Extract a shared `copyToClipboard(target, content)` helper in `clipboard.ts` that adds SVG success/failure feedback. - `is-loading` height for the new helper is sourced from `--loading-size`. - Change actions log timestamp format to include seconds. The indented-markdown code-block fix has moved to #37748. <img width="244" height="165" alt="copystep" src="https://github.com/user-attachments/assets/ce286b51-f77b-4d82-b161-ca0aa7ec4fdc" /> <img width="187" height="150" alt="copybt" src="https://github.com/user-attachments/assets/5366b290-b776-496d-8dd4-58d5fa60be92" /> Fixes: #26116 --- This PR was written with the help of Claude Opus 4.7 --------- Signed-off-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Nicolas <bircni@icloud.com>

Indented (4-space) code blocks were emitted by goldmark's default renderer as plain
<pre><code>without thecode-block-containerwrapper that the JSinitMarkupCodeCopykeys on. As a result, only fenced code blocks received the copy button. Registerast.KindCodeBlockwith a renderer that produces the same wrapper as the highlighting renderer so both syntaxes get the button.Extends
TestMarkdownFencedCodeBlockto assert the wrapper is emitted for indented blocks (and that HTML inside is escaped).This PR was written with the help of Claude Opus 4.7