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 committed Feb 20, 2024
1 parent 1657bfd commit b5b8ae5
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 b5b8ae5

Please sign in to comment.