diff options
author | Giteabot <teabot@gitea.io> | 2024-02-02 05:06:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-01 21:06:21 +0000 |
commit | 5d1abdce3ea16064fe22e9bdaa436033bdd6698a (patch) | |
tree | f73d33b67462d977f1bee8c8140ec70a36001cef /web_src | |
parent | 2588d73ebfa39bbc5926e669c76a702c34daf7cd (diff) | |
download | gitea-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.js | 4 |
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); } } |