code.gitea.io/gitea@v1.21.7/web_src/js/markup/codecopy.js (about) 1 import {svg} from '../svg.js'; 2 3 export function makeCodeCopyButton() { 4 const button = document.createElement('button'); 5 button.classList.add('code-copy', 'ui', 'button'); 6 button.innerHTML = svg('octicon-copy'); 7 return button; 8 } 9 10 export function renderCodeCopy() { 11 const els = document.querySelectorAll('.markup .code-block code'); 12 if (!els.length) return; 13 14 for (const el of els) { 15 if (!el.textContent) continue; 16 const btn = makeCodeCopyButton(); 17 // remove final trailing newline introduced during HTML rendering 18 btn.setAttribute('data-clipboard-text', el.textContent.replace(/\r?\n$/, '')); 19 el.after(btn); 20 } 21 }