0
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-05 05:07:58 +01:00
gitea/web_src/js/markup/codecopy.js

20 lines
519 B
JavaScript
Raw Normal View History

import {svg} from '../svg.js';
export function makeCodeCopyButton() {
const button = document.createElement('button');
button.classList.add('code-copy', 'ui', 'button');
button.innerHTML = svg('octicon-copy');
return button;
}
export function renderCodeCopy() {
const els = document.querySelectorAll('.markup .code-block code');
if (!els.length) return;
for (const el of els) {
const btn = makeCodeCopyButton();
btn.setAttribute('data-clipboard-text', el.textContent);
el.after(btn);
}
}