diff --git a/preview-src/code.adoc b/preview-src/code.adoc index 75ff16f0..f8ce8738 100644 --- a/preview-src/code.adoc +++ b/preview-src/code.adoc @@ -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] diff --git a/src/js/06-code.js b/src/js/06-code.js index ad6000b4..b43e5a40 100644 --- a/src/js/06-code.js +++ b/src/js/06-code.js @@ -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'] @@ -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 } @@ -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) }