Skip to content

fix(markup): wrap indented code blocks for the code-copy button#37748

Merged
silverwind merged 7 commits into
go-gitea:mainfrom
silverwind:markdown-indented-code-wrapper
May 19, 2026
Merged

fix(markup): wrap indented code blocks for the code-copy button#37748
silverwind merged 7 commits into
go-gitea:mainfrom
silverwind:markdown-indented-code-wrapper

Conversation

@silverwind
Copy link
Copy Markdown
Member

@silverwind silverwind commented May 18, 2026

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.

Extends TestMarkdownFencedCodeBlock to 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

silverwind and others added 2 commits May 18, 2026 02:07
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>
silverwind added a commit to silverwind/gitea that referenced this pull request May 18, 2026
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>
@silverwind silverwind requested a review from Copilot May 18, 2026 00:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.KindCodeBlock to wrap indented code blocks with code-block-container.
  • Implement renderCodeBlock to 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.

Comment thread modules/markup/markdown/goldmark.go
Comment thread tests/e2e/code-copy.test.ts Outdated
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label May 18, 2026
@lunny
Copy link
Copy Markdown
Member

lunny commented May 19, 2026

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 e2e test verifying the copy button on both block types.

This PR was written with the help of Claude Opus 4.7

I couldn't reproduce goldmark will emit the Indented (4-space) code blocks. Could you have an example at gitea.com ?

@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented May 19, 2026

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

image

@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented May 19, 2026

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

@silverwind
Copy link
Copy Markdown
Member Author

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>
@silverwind
Copy link
Copy Markdown
Member Author

unit test added, e2e test removed

…lock

Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 19, 2026
@silverwind silverwind merged commit 621aa67 into go-gitea:main May 19, 2026
22 checks passed
@silverwind silverwind deleted the markdown-indented-code-wrapper branch May 19, 2026 13:09
@GiteaBot GiteaBot added this to the 1.27.0 milestone May 19, 2026
silverwind added a commit to silverwind/gitea that referenced this pull request May 19, 2026
* 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
silverwind added a commit that referenced this pull request May 21, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants