File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 53
53
}
54
54
55
55
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 , '' )
57
70
if ( code . dataset . lang === 'console' && text . startsWith ( '$ ' ) ) text = extractCommands ( text )
58
71
window . navigator . clipboard . writeText ( text ) . then (
59
72
function ( ) {
You can’t perform that action at this time.
0 commit comments