You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

codecopy.js 646B

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