diff options
author | silverwind <me@silverwind.io> | 2024-02-01 22:01:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-01 15:01:48 -0600 |
commit | b71850ea731ffd04f87f32fe25373a9c103ed669 (patch) | |
tree | 2657a482b40d6721af59117e51a8293a5f761caf /web_src/js/markup/codecopy.js | |
parent | c3e462921ee31536e59b37e654ed20e92a37ffe6 (diff) | |
download | gitea-b71850ea731ffd04f87f32fe25373a9c103ed669.tar.gz gitea-b71850ea731ffd04f87f32fe25373a9c103ed669.zip |
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.
Diffstat (limited to 'web_src/js/markup/codecopy.js')
-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); } } |