Skip to content

Commit 6db4a28

Browse files
authored
remove trailing space in codeblock lines (#204)
1 parent 203d182 commit 6db4a28

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

preview-src/code.adoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44

55
The **Copy To Clipboard** button will appear on all code blocks:
66

7+
8+
[source,shell]
9+
----
10+
Copy me!
11+
Do something else
12+
Callout # <1>
13+
Callout # <2>
14+
Callout tab # <3>
15+
Comment # Just a regular comment after some code
16+
----
17+
18+
<1> Callout
19+
<2> Callout
20+
<3> Callout after a tab
21+
22+
23+
724
[source,adoc]
825
----
926
[source,adoc]

src/js/06-code.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ import { createElement } from './modules/dom'
3535
}
3636
})()
3737

38+
var cleanCallouts = function (code) {
39+
return code.replace(/[ |\t]+\n/g, '\n').trimEnd()
40+
}
41+
3842
document.addEventListener('DOMContentLoaded', function () {
3943
var body = document.querySelectorAll('body')
4044
var ignore = ['gram']
@@ -45,7 +49,7 @@ document.addEventListener('DOMContentLoaded', function () {
4549
if (language === 'bash' || language === 'sh' || language === 'shell' || language === 'console') {
4650
input = window.neo4jDocs.copyableCommand(input)
4751
}
48-
52+
input = cleanCallouts(input)
4953
return input
5054
}
5155

@@ -73,6 +77,16 @@ document.addEventListener('DOMContentLoaded', function () {
7377
}
7478
}
7579

80+
// capture copy command
81+
const copyThis = document.querySelectorAll('pre code')
82+
copyThis.forEach((code) => {
83+
code.addEventListener('copy', (e) => {
84+
const selection = document.getSelection()
85+
e.clipboardData.setData('text/plain', cleanCallouts(selection.toString()))
86+
e.preventDefault()
87+
})
88+
})
89+
7690
function capitalizeFirstLetter (string) {
7791
return string.charAt(0).toUpperCase() + string.slice(1)
7892
}

0 commit comments

Comments
 (0)