Skip to content
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

markup: improve code block readability and isolate copy button #34009

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

bigdeejay
Copy link

Summary

This PR improves the rendering of code blocks in markdown content (e.g., README.md) for better readability and UI stability across screen sizes.

Problem

  • Code blocks previously used soft wrapping (pre-wrap), which caused line breaks on narrow or mobile displays.
  • This significantly reduced code readability.
  • The copy button overlapped or misaligned when horizontal scrolling was applied, due to its placement inside the scrolling container.

Changes

  • Updated HTML structure and CSS to:
    • Enable horizontal scrolling (overflow-x: auto) for code blocks
    • Prevent forced line-wrapping by setting white-space: pre
    • Move the copy button into a separate absolutely-positioned container, outside the scrollable area

Result

  • Code remains readable on all screen sizes via scroll instead of wrapping
  • Copy button is visually stable and no longer affected by code block overflow

Affected Files

  • modules/highlight/highlight.go — changed rendered HTML structure
  • modules/markup/markdown/markdown.go — passed format options
  • web_src/css/markup/codecopy.css — copy button isolation
  • web_src/css/markup/content.css — horizontal scroll and white-space handling
  • web_src/js/markup/codecopy.ts — adjusted to handle isolated copy area

Notes

This is a UI/UX refinement that improves the usability of code blocks, especially for developers reading source code on mobile devices or narrow displays.

Animation

Previously, code blocks did not support horizontal scrolling, leading to poor

readability on mobile or narrow displays due to forced line wrapping.

This patch updates the HTML structure and CSS so that:

- Code blocks now scroll horizontally instead of wrapping lines

- The copy button is placed in a separate wrapper to avoid layout interference

These changes improve overall accessibility and usability for markdown-rendered

content in the Gitea interface.
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 25, 2025
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 25, 2025
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/frontend labels Mar 25, 2025
@kyeongkwan
Copy link

Awesome

@silverwind
Copy link
Member

silverwind commented Mar 25, 2025

There are people who prefer to always wrap code (me), and ones who don't. I think instead of this, we need a per-user preference that controls whether we wrap code everywhere or not. Singling out these inline blocks to not wrap seems a bad solution to me, we should either wrap everything or nothing.

PS: Reason I prefer to always wrap is because I think vertical scrollbars are bad UX.

@bigdeejay
Copy link
Author

To be clear, are you saying we should apply code wrapping consistently—either everywhere or nowhere—based on a user preference?

@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/frontend modifies/go Pull requests that update Go code size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants