clipboard: size inline code to fit surrounding text

This commit is contained in:
Sören Weber 2025-03-29 22:21:58 +01:00
parent 6e26088dc2
commit 330a25b51e
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
3 changed files with 25 additions and 10 deletions
assets/js

View file

@ -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');