summaryrefslogtreecommitdiffstats
path: root/web_src
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2024-02-02 05:06:21 +0800
committerGitHub <noreply@github.com>2024-02-01 21:06:21 +0000
commit5d1abdce3ea16064fe22e9bdaa436033bdd6698a (patch)
treef73d33b67462d977f1bee8c8140ec70a36001cef /web_src
parent2588d73ebfa39bbc5926e669c76a702c34daf7cd (diff)
downloadgitea-5d1abdce3ea16064fe22e9bdaa436033bdd6698a.tar.gz
gitea-5d1abdce3ea16064fe22e9bdaa436033bdd6698a.zip
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 <me@silverwind.io>
Diffstat (limited to 'web_src')
-rw-r--r--web_src/js/markup/codecopy.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/web_src/js/markup/codecopy.js b/web_src/js/markup/codecopy.js
index a12802ef73..078d741253 100644
--- a/web_src/js/markup/codecopy.js
+++ b/web_src/js/markup/codecopy.js
@@ -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);
}
}