Skip to content

Commit

Permalink
Strip trailing newline in markdown code copy (#29019) (#29022)
Browse files Browse the repository at this point in the history
Behaviour now matches GH. Safeguard added in the for loop because
`textContent` may be null in which case it does not make sense to render
the copy button.

Co-authored-by: silverwind <me@silverwind.io>
  • Loading branch information
GiteaBot and silverwind authored Feb 1, 2024
1 parent 2588d73 commit 5d1abdc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion web_src/js/markup/codecopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export function renderCodeCopy() {
if (!els.length) return;

for (const el of els) {
if (!el.textContent) continue;
const btn = makeCodeCopyButton();
btn.setAttribute('data-clipboard-text', el.textContent);
// remove final trailing newline introduced during HTML rendering
btn.setAttribute('data-clipboard-text', el.textContent.replace(/\r?\n$/, ''));
el.after(btn);
}
}

0 comments on commit 5d1abdc

Please sign in to comment.