Improve display of source blocks

This commit is contained in:
Thomas Dehaeze 2020-11-26 15:58:26 +01:00
parent 602309beae
commit bed29b6ab4
2 changed files with 27 additions and 3 deletions

View File

@ -26,16 +26,23 @@ docReady(function() {
// Copy Source Block // Copy Source Block
docReady(function() { docReady(function() {
let srcContainers = document.querySelectorAll('div.org-src-container') let srcContainers = document.querySelectorAll('pre.src')
for (let srcContrainer of srcContainers) { for (let srcContrainer of srcContainers) {
let boxCopy = document.createElement('div') let boxCopy = document.createElement('div')
boxCopy.className = "src-copy" boxCopy.className = "src-copy"
boxCopy.textContent = "Copy" boxCopy.textContent = "Copy"
boxCopy.onclick = function() { boxCopy.onclick = function() {
navigator.clipboard.writeText(this.nextElementSibling.textContent).then(function() { // Get text inside (remove 4 first char corresponding to "Copy")
let srcText = this.parentNode.textContent.slice(4)
navigator.clipboard.writeText(srcText).then(function() {
boxCopy.textContent = "Copied" boxCopy.textContent = "Copied"
setTimeout(function() { boxCopy.textContent = "Copy" },1000); boxCopy.classList.add("src-copied")
setTimeout(function() {
boxCopy.textContent = "Copy"
boxCopy.classList.remove("src-copied")
},1000);
}); });
} }

View File

@ -17,12 +17,28 @@
overflow: visible; overflow: visible;
margin-top: 1em; margin-top: 1em;
// Caption
label {
text-align: center;
cursor: text;
.listing-number {
font-weight: bold;
color: #343131;
}
}
// Copy Button // Copy Button
div.src-copy { div.src-copy {
@include src-box; @include src-box;
line-height:1.5; line-height:1.5;
right: 10px; right: 10px;
cursor: pointer; cursor: pointer;
// When button is clicked
&.src-copied {
background-color: #d6e9ff;
}
} }
// Code Block // Code Block
@ -54,6 +70,7 @@
&.src-python:before { content: 'Python'; } &.src-python:before { content: 'Python'; }
&.src-latex:before { content: 'LaTeX'; } &.src-latex:before { content: 'LaTeX'; }
&.src-matlab:before { content: 'Matlab'; } &.src-matlab:before { content: 'Matlab'; }
&.src-bibtex:before { content: 'BibTeX'; }
} }
} }