Skip to content

Commit b71850e

Browse files
authored
Strip trailing newline in markdown code copy (#29019)
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.
1 parent c3e4629 commit b71850e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

web_src/js/markup/codecopy.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ export function renderCodeCopy() {
1212
if (!els.length) return;
1313

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

0 commit comments

Comments
 (0)