Skip to content

Commit

Permalink
Add checks for adding the copy button in code-blocks
Browse files Browse the repository at this point in the history
- adds checks to put copy button for code
 inside table and highlight code block

- Fixes adityatelange#363
  • Loading branch information
adityatelange committed Apr 16, 2021
1 parent 687fa25 commit 31ca3a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions assets/css/common/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ code {
direction: ltr;
}

div.highlight {
div.highlight, pre {
position: relative;
}

Expand All @@ -60,6 +60,7 @@ div.highlight {
font-size: 14px;
}

div.highlight:hover .copy-code {
div.highlight:hover .copy-code,
pre:hover .copy-code {
display: block;
}
12 changes: 11 additions & 1 deletion layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,17 @@
selection.removeRange(range);
});

container.appendChild(copybutton);
if (container.classList.contains("highlight")) {
container.appendChild(copybutton);
} else if (container.parentNode.firstChild == container) {
// td containing LineNos
} else if (codeblock.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "TABLE") {
// table containing LineNos and code
codeblock.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(copybutton);
} else {
// code blocks not having highlight as parent class
codeblock.parentNode.appendChild(copybutton);
}
});
</script>
{{- end }}

0 comments on commit 31ca3a8

Please sign in to comment.