-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
markup: improve code block readability and isolate copy button #34009
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
Conversation
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.
This reverts commit 95f7abb.
Awesome |
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. |
To be clear, are you saying we should apply code wrapping consistently—either everywhere or nowhere—based on a user preference? |
I can see indeed there are bugs in current layout and this PR's approach is overall right. However we need to improve more details to make the markup layout work for all cases, will try to figure out the details and make some changes here. |
# Conflicts: # web_src/css/markup/content.css # web_src/js/markup/codecopy.ts
I guess we can have these scrolling for now, but in the future, we definitely want one or two per-user options:
Personally, I prefer to always wrap, e.g. both options enabled. |
That's why I use different CSS classes for wrap/scroll, it's flexible enough and could be configurable in the future. At the moment, default to "scroll" should be good enough for most users, because it is the GitHub's behavior. |
Did you test mermaid blocks? Loading state and rendering. |
Which one? Maybe because you are working on the main branch in your fork, while Gitea repo's main branch doesn't contain any fix yet? I didn't see any related commit on the upstream's main branch. When this PR would be merged (there will be a squash merge), you are the "author", not just only "co-author" 😄 |
Thanks, that makes sense — I misunderstood the situation. |
* giteaofficial/main: Add API routes to lock and unlock issues (go-gitea#34165) Make ROOT_URL support using request Host header (go-gitea#32564) Valid email address should only start with alphanumeric (go-gitea#28174) Fix notify watch failure when the content is too long (go-gitea#34233) Add "--fullname" arg to gitea admin user create (go-gitea#34241) Fix various UI problems (go-gitea#34243) markup: improve code block readability and isolate copy button (go-gitea#34009) Don't assume the default wiki branch is master in the wiki API (go-gitea#34244) [skip ci] Updated translations via Crowdin Optimize the calling code of queryElems (go-gitea#34235) Actions Runner rest api (go-gitea#33873) Fix some trivial problems (go-gitea#34237) Swift files can be passed either as file or as form value (go-gitea#34068) # Conflicts: # templates/repo/wiki/revision.tmpl
Fix #33197
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
pre-wrap
), which caused line breaks on narrow or mobile displays.Changes
overflow-x: auto
) for code blockswhite-space: pre
Result
Affected Files
modules/highlight/highlight.go
— changed rendered HTML structuremodules/markup/markdown/markdown.go
— passed format optionsweb_src/css/markup/codecopy.css
— copy button isolationweb_src/css/markup/content.css
— horizontal scroll and white-space handlingweb_src/js/markup/codecopy.ts
— adjusted to handle isolated copy areaNotes
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.