Skip to content

Commit ddf75db

Browse files
committed
collect code content without line numbers and connect together with single line breaks
1 parent 40be783 commit ddf75db

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

ui/src/js/04-copy-to-clipboard.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,20 @@
5353
}
5454

5555
function writeToClipboard (code) {
56-
var text = code.innerText.replace(TRAILING_SPACE_RX, '')
56+
var text
57+
// Check if this is a line-numbered code block (table structure)
58+
var table = code.querySelector('table.hljs-ln')
59+
if (table) {
60+
// Extract text only from code cells (not line number cells)
61+
var codeCells = table.querySelectorAll('td.hljs-ln-code')
62+
text = Array.prototype.slice.call(codeCells).map(function (cell) {
63+
return cell.textContent
64+
}).join('\n')
65+
} else {
66+
// Fallback to original method for non-line-numbered blocks
67+
text = code.innerText
68+
}
69+
text = text.replace(TRAILING_SPACE_RX, '')
5770
if (code.dataset.lang === 'console' && text.startsWith('$ ')) text = extractCommands(text)
5871
window.navigator.clipboard.writeText(text).then(
5972
function () {

0 commit comments

Comments
 (0)