Skip to content

Commit

Permalink
Strip trailing newline in markdown code copy (go-gitea#29019)
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.
  • Loading branch information
silverwind authored and GiteaBot committed Feb 1, 2024
1 parent 2588d73 commit 6c3bc52
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 6c3bc52

Please sign in to comment.