Skip to content

Commit

Permalink
remove trailing space in codeblock lines (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
recrwplay authored Dec 22, 2023
1 parent 203d182 commit 6db4a28
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
17 changes: 17 additions & 0 deletions preview-src/code.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

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


[source,shell]
----
Copy me!
Do something else
Callout # <1>
Callout # <2>
Callout tab # <3>
Comment # Just a regular comment after some code
----

<1> Callout
<2> Callout
<3> Callout after a tab



[source,adoc]
----
[source,adoc]
Expand Down
16 changes: 15 additions & 1 deletion src/js/06-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import { createElement } from './modules/dom'
}
})()

var cleanCallouts = function (code) {
return code.replace(/[ |\t]+\n/g, '\n').trimEnd()
}

document.addEventListener('DOMContentLoaded', function () {
var body = document.querySelectorAll('body')
var ignore = ['gram']
Expand All @@ -45,7 +49,7 @@ document.addEventListener('DOMContentLoaded', function () {
if (language === 'bash' || language === 'sh' || language === 'shell' || language === 'console') {
input = window.neo4jDocs.copyableCommand(input)
}

input = cleanCallouts(input)
return input
}

Expand Down Expand Up @@ -73,6 +77,16 @@ document.addEventListener('DOMContentLoaded', function () {
}
}

// capture copy command
const copyThis = document.querySelectorAll('pre code')
copyThis.forEach((code) => {
code.addEventListener('copy', (e) => {
const selection = document.getSelection()
e.clipboardData.setData('text/plain', cleanCallouts(selection.toString()))
e.preventDefault()
})
})

function capitalizeFirstLetter (string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}
Expand Down

0 comments on commit 6db4a28

Please sign in to comment.