Skip to content

Commit 31ca3a8

Browse files
committed
Add checks for adding the copy button in code-blocks
- adds checks to put copy button for code inside table and highlight code block - Fixes adityatelange#363
1 parent 687fa25 commit 31ca3a8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

assets/css/common/main.css

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ code {
4444
direction: ltr;
4545
}
4646

47-
div.highlight {
47+
div.highlight, pre {
4848
position: relative;
4949
}
5050

@@ -60,6 +60,7 @@ div.highlight {
6060
font-size: 14px;
6161
}
6262

63-
div.highlight:hover .copy-code {
63+
div.highlight:hover .copy-code,
64+
pre:hover .copy-code {
6465
display: block;
6566
}

layouts/partials/footer.html

+11-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@
120120
selection.removeRange(range);
121121
});
122122

123-
container.appendChild(copybutton);
123+
if (container.classList.contains("highlight")) {
124+
container.appendChild(copybutton);
125+
} else if (container.parentNode.firstChild == container) {
126+
// td containing LineNos
127+
} else if (codeblock.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "TABLE") {
128+
// table containing LineNos and code
129+
codeblock.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(copybutton);
130+
} else {
131+
// code blocks not having highlight as parent class
132+
codeblock.parentNode.appendChild(copybutton);
133+
}
124134
});
125135
</script>
126136
{{- end }}

0 commit comments

Comments
 (0)