Skip to content

Commit

Permalink
fix line numbers and copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
phtournier committed Sep 1, 2023
1 parent ee75380 commit a8baf97
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 50 deletions.
22 changes: 15 additions & 7 deletions source/_static/css/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ p {

/** CODE TABLES **/
.linenos {
background-color: #E0E0E5;
background-color: #EFEFEF;
color: rgba(0,0,0,.26);
border-radius: .125rem 0 0 .125rem;
padding: 0 .75rem !important;
Expand All @@ -78,7 +78,7 @@ p {
margin: 0;
}

table.highlighttable {
div.highlight {
display: block;
background-color: #EFEFEF !important;
border-radius: .125rem;
Expand All @@ -87,21 +87,21 @@ table.highlighttable {
position: relative;
}

table.highlighttable tbody {
div.highlight tbody {
display: block;
}

table.highlighttable tr {
div.highlight tr {
display: flex;
}

table.highlighttable .code {
div.highlight .code {
flex: 1;
overflow: hidden;
padding: 0 .55rem;
}

table.highlighttable pre {
div.highlight pre {
display: block;
margin: 0;
overflow: auto;
Expand All @@ -110,9 +110,17 @@ table.highlighttable pre {
padding: .55rem 0;
}

div.highlight td.linenos,
span.linenos,
div.doctest > div.highlight span.gp { /* gp: Generic.Prompt */
user-select: none;
}

.highlight {
background-color: #EFEFEF !important;
margin: 0;
overflow-x: auto;
vertical-align:top;
}

.highlight .nf {
Expand Down Expand Up @@ -151,7 +159,7 @@ table.highlighttable pre {
position: absolute;
top: .01rem;
right: 2.1rem;
padding: .375rem .625rem;
padding: .375rem .625rem;
-webkit-transform: translateX(.8rem);
transform: translateX(.8rem);
transition: opacity .175s,-webkit-transform .25s cubic-bezier(.9,.1,.9,0);
Expand Down
10 changes: 7 additions & 3 deletions source/_static/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ window.onclick = function (e) {
// Copy/paste button in code
function copy(event) {
const table = event.parentNode.parentNode
const codeContainer = table.querySelector('td.code pre')
const code = codeContainer.textContent
const codeContainer = table.querySelector('pre')

const clone = codeContainer.cloneNode(true);
clone.querySelectorAll('.linenos').forEach(node => node.remove());
clone.querySelectorAll('.copy-button').forEach(node => node.remove());
const code = clone.textContent

const textarea = document.createElement('textarea')
textarea.value = code
Expand All @@ -27,7 +31,7 @@ function copy(event) {
}

function addCopyPaste() {
const codeTables = document.getElementsByClassName('highlighttable')
const codeTables = document.querySelectorAll("div.highlight pre")

for (let i = 0; i < codeTables.length; i++) {
const button = document.createElement('button')
Expand Down
Loading

0 comments on commit a8baf97

Please sign in to comment.