pulsante copia codice (#169)

#167

Reviewed-on: BgLUG/bglug.it#169
Co-authored-by: paspo <paolo@asperti.com>
Co-committed-by: paspo <paolo@asperti.com>
This commit is contained in:
Paolo Asperti 2024-07-30 21:57:17 +00:00 committed by Paolo Asperti
parent 8a1cbf0235
commit 0c8a1049be
3 changed files with 107 additions and 2 deletions

View File

@ -57,3 +57,66 @@ figcaption {
font-size: smaller;
font-style: italic;
}
/* pulsante copia codice */
.copy-code-button {
color: #272822;
background-color: #f7990e,;
border-color: #272822;
border: 2px solid;
border-radius: 4px 4px 0px 0px;
min-width: auto;
/* right-align */
display: block;
margin-left: auto;
margin-right: 0;
margin-top: 5px;
margin-bottom: -2px;
padding: 0px 3px;
font-size: 0.5em;
font-variant-caps: small-caps;
}
.copy-code-button:hover {
cursor: pointer;
color: #fff;
border-color: #272822;
}
.copy-code-button:focus {
/* Avoid an ugly focus outline on click in Chrome,
but darken the button for accessibility.
See https://stackoverflow.com/a/25298082/1481479 */
background-color: #272822;
outline: 0;
}
.copy-code-button:active {
background-color: #272822;
}
.highlight pre {
/* Avoid pushing up the copy buttons. */
margin: 0;
}
/* numerazione linee */
div.highlight pre {
counter-reset: line;
white-space: pre-wrap;
}
div.highlight pre code > span {
counter-increment: line;
padding-left: 1.5em;
}
div.highlight pre code > span::before {
font-size: 0.8em;
color: #999;
content: counter(line) ". ";
display: inline-block;
padding-right: 0.2em;
}

View File

@ -44,7 +44,7 @@ smtp_helo_name = pve.nomedominio.it
Creare il file `/etc/postfix/sasl_passwd` inserendo:
```conf
```text
[smtp.gmail.com]:587 mia_mail@gmail.com:PASSWD
```
@ -70,7 +70,7 @@ Inviare una mail di prova:
echo "Test mail from postfix" | mail -s "Test Postfix" test@test.com
```
```conf
```text
/var/log/mail.log
/var/log/mail.info
/var/log/mail.warn

View File

@ -41,4 +41,46 @@
{{ end }}
{{- .Content }}
{{ if (findRE "<pre" .Content 1) }}
<script>
function addCopyButtons(clipboard) {
document.querySelectorAll('pre > code').forEach(function (codeBlock) {
var button = document.createElement('button');
button.className = 'copy-code-button';
button.type = 'button';
button.innerText = 'Copy';
button.addEventListener('click', function () {
clipboard.writeText(codeBlock.innerText).then(function () {
/* Chrome doesn't seem to blur automatically,
leaving the button in a focused state. */
button.blur();
button.innerText = 'Copied!';
setTimeout(function () {
button.innerText = 'Copy';
}, 2000);
}, function (error) {
button.innerText = 'Error';
});
});
var pre = codeBlock.parentNode;
if (pre.parentNode.classList.contains('highlight')) {
var highlight = pre.parentNode;
highlight.parentNode.insertBefore(button, highlight);
} else {
pre.parentNode.insertBefore(button, pre);
}
});
}
if (navigator && navigator.clipboard) {
addCopyButtons(navigator.clipboard);
}
</script>
{{ end }}
{{ end }}