giteabot backport / giteabot (push) Canceled after 0s
giteabot / giteabot (push) Canceled after 0s
release-nightly / nightly-binary (push) Canceled after 0s
release-nightly / nightly-container (push) Canceled after 0s
cache-seeder / gobuild (push) Canceled after 0s
cache-seeder / lint (bindata, lint-backend) (push) Canceled after 0s
release-nightly-snapcraft / build-and-publish (push) Canceled after 0s
Includes direct password setup links in registration emails. Assisted-by: Codex:GPT-5
26 lines
999 B
TypeScript
26 lines
999 B
TypeScript
import {svg} from '../svg.ts';
|
|
import {createElementFromAttrs, queryElems} from '../utils/dom.ts';
|
|
|
|
export function makeCodeCopyButton(attrs: Record<string, string> = {}): HTMLButtonElement {
|
|
const btn = createElementFromAttrs<HTMLButtonElement>('button', {
|
|
class: 'ui compact icon button code-copy auto-hide-control',
|
|
...attrs,
|
|
});
|
|
btn.innerHTML = svg('octicon-copy');
|
|
return btn;
|
|
}
|
|
|
|
export function initMarkupCodeCopy(elMarkup: HTMLElement): void {
|
|
// .markup .code-block code
|
|
queryElems(elMarkup, '.code-block code', (el) => {
|
|
if (!el.textContent) return;
|
|
// remove final trailing newline introduced during HTML rendering
|
|
const btn = makeCodeCopyButton({
|
|
'data-clipboard-text': el.textContent.replace(/\r?\n$/, ''),
|
|
});
|
|
// we only want to use `.code-block-container` if it exists, no matter `.code-block` exists or not.
|
|
const btnContainer = el.closest('.code-block-container') ?? el.closest('.code-block')!;
|
|
btnContainer.append(btn);
|
|
});
|
|
}
|