1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-04 01:27:20 +00:00

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

Fix #33197

Improve the rendering of code blocks in markdown content 
for better readability and UI stability across screen sizes.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
D
2025-04-19 14:53:39 +09:00
committed by GitHub
parent f0544dbfca
commit eda6d65818
5 changed files with 95 additions and 25 deletions

View File

@ -15,6 +15,8 @@ export function initMarkupCodeCopy(elMarkup: HTMLElement): void {
const btn = makeCodeCopyButton();
// remove final trailing newline introduced during HTML rendering
btn.setAttribute('data-clipboard-text', el.textContent.replace(/\r?\n$/, ''));
el.after(btn);
// we only want to use `.code-block-container` if it exists, no matter `.code-block` exists or not.
const btnContainer = el.closest('.code-block-container') ?? el.closest('.code-block');
btnContainer.append(btn);
});
}