Skip to content

Commit 5d1abdc

Browse files
GiteaBotsilverwind
andauthored
Strip trailing newline in markdown code copy (#29019) (#29022)
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 <[email protected]>
1 parent 2588d73 commit 5d1abdc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

web_src/js/markup/codecopy.js

+3-1
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)