Skip to content

Conversation

@d0ngjini
Copy link
Contributor

Summary

This PR improves the rendering and structure of code blocks in markdown files to enhance readability and layout stability across various screen sizes.

Before

  • Code blocks wrapped lines via white-space: pre-wrap, making long code hard to read on mobile and narrow displays.
  • The "Copy" button was placed inside the scrollable container, which caused layout shift or misalignment when horizontal scrolling occurred.

After

  • Code blocks are now rendered with white-space: pre and overflow-x: auto to support horizontal scrolling without line wrapping.
  • A new code-block class is applied to both <pre> and <code> elements for consistent targeting.
  • The copy button is moved to a separate container (.copy-button-container) positioned absolutely, preventing it from being affected by scrolling.

Affected Files

  • modules/highlight/highlight.go: modifies rendered HTML for code blocks
  • modules/markup/markdown/markdown.go: ensures correct formatter options passed
  • web_src/css/markup/codecopy.css: handles absolute positioning for the copy button
  • web_src/css/markup/content.css: applies horizontal scroll and no-wrap for .code-block
  • web_src/js/markup/codecopy.ts: adapts JS logic to target the updated structure

Motivation

This change improves UX for reading markdown code on mobile and prevents UI overlap between scrolling code and fixed-position buttons. It also brings the structure closer to best practices for developer tools and documentation interfaces.


Tested on modern Chromium and WebKit browsers.

스크린샷 2025-03-25 153528

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
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/frontend labels Mar 25, 2025
@pull-request-size pull-request-size bot added size/L and removed size/M labels Mar 25, 2025
@d0ngjini d0ngjini closed this Mar 25, 2025
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jun 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants