0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-09 19:42:09 +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);
}
}