show less for large blocks
This commit is contained in:
parent
7d6fe1b27b
commit
434db03ab0
1 changed files with 16 additions and 2 deletions
|
|
@ -421,10 +421,24 @@ function truncateCodeBlock(block, maxLines = 100) {
|
||||||
// Reapply syntax highlighting
|
// Reapply syntax highlighting
|
||||||
hljs.highlightElement(block);
|
hljs.highlightElement(block);
|
||||||
addLineNumbers(block);
|
addLineNumbers(block);
|
||||||
// Remove the expand button
|
// Change the button text to "Show Less"
|
||||||
expandButton.remove();
|
expandButton.textContent = 'Show Less';
|
||||||
|
// Change the onclick function to truncate the block again
|
||||||
|
expandButton.onclick = function() {
|
||||||
|
block.textContent = truncatedText;
|
||||||
|
// Reapply syntax highlighting
|
||||||
|
hljs.highlightElement(block);
|
||||||
|
addLineNumbers(block);
|
||||||
|
// Change the button text back to "Show More"
|
||||||
|
expandButton.textContent = 'Show More';
|
||||||
|
// Set the onclick function back to the original expand function
|
||||||
|
expandButton.onclick = originalExpandFunction;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Keep a reference to the original expand function
|
||||||
|
const originalExpandFunction = expandButton.onclick;
|
||||||
|
|
||||||
// Insert the expand button after the code block
|
// Insert the expand button after the code block
|
||||||
block.parentNode.insertBefore(expandButton, block.nextSibling);
|
block.parentNode.insertBefore(expandButton, block.nextSibling);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue