mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-05-16 06:55:18 +00:00
clipboard: size inline code to fit surrounding text #1077
This commit is contained in:
parent
6e26088dc2
commit
330a25b51e
3 changed files with 25 additions and 10 deletions
assets/js
|
@ -698,6 +698,15 @@ function initCodeClipboard() {
|
|||
// avoid copy-to-clipboard for highlight shortcode in table lineno mode
|
||||
var isFirstLineCell = inTable && code.parentNode.parentNode.parentNode.querySelector('td:first-child > pre > code') == code;
|
||||
var isBlock = inTable || inPre;
|
||||
var inHeading = false;
|
||||
var parent = code.parentNode;
|
||||
while (parent && parent !== document) {
|
||||
if (/^h[1-6]$/i.test(parent.tagName)) {
|
||||
inHeading = true;
|
||||
break;
|
||||
}
|
||||
parent = parent.parentNode;
|
||||
}
|
||||
|
||||
if (!isFirstLineCell && (inPre || text.length > 5)) {
|
||||
code.classList.add('copy-to-clipboard-code');
|
||||
|
@ -714,7 +723,7 @@ function initCodeClipboard() {
|
|||
code = clone;
|
||||
}
|
||||
var button = null;
|
||||
if (isBlock || !window.relearn.disableInlineCopyToClipboard) {
|
||||
if (isBlock || (!window.relearn.disableInlineCopyToClipboard && !inHeading)) {
|
||||
button = document.createElement('button');
|
||||
var buttonPrefix = isBlock ? 'block' : 'inline';
|
||||
button.classList.add(buttonPrefix + '-copy-to-clipboard-button');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue