From b26b34f3c0d674e5e2a35b12c1fb71d874d72d3d Mon Sep 17 00:00:00 2001 From: Neil Dewhurst Date: Mon, 11 Dec 2023 15:16:46 +0000 Subject: [PATCH 1/4] remove trailing space in codeblock lines --- preview-src/code.adoc | 15 +++++++++++++++ src/js/06-code.js | 2 ++ 2 files changed, 17 insertions(+) diff --git a/preview-src/code.adoc b/preview-src/code.adoc index 7c4cd523..ebbec9e7 100644 --- a/preview-src/code.adoc +++ b/preview-src/code.adoc @@ -4,6 +4,21 @@ The **Copy To Clipboard** button will appear on all code blocks: + +[source,shell] +---- +Copy me! +Do something else +Callout # <1> +Callout # <2> +Comment # Just a regular comment after some code +---- + +<1> Callout +<2> Callout + + + [source,adoc] ---- [source,adoc] diff --git a/src/js/06-code.js b/src/js/06-code.js index e47eeb48..ec52dffd 100644 --- a/src/js/06-code.js +++ b/src/js/06-code.js @@ -46,6 +46,8 @@ document.addEventListener('DOMContentLoaded', function () { input = window.neo4jDocs.copyableCommand(input) } + input = input.replace(/[ ]+\n/g, '\n').trimEnd() + return input } From e67ac8f86fdd48f5d25824098550607631e38141 Mon Sep 17 00:00:00 2001 From: Neil Dewhurst Date: Thu, 21 Dec 2023 16:43:39 +0000 Subject: [PATCH 2/4] Catch tabs and manual copying --- preview-src/code.adoc | 2 ++ src/js/06-code.js | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/preview-src/code.adoc b/preview-src/code.adoc index ebbec9e7..ecea6fc6 100644 --- a/preview-src/code.adoc +++ b/preview-src/code.adoc @@ -11,11 +11,13 @@ 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 diff --git a/src/js/06-code.js b/src/js/06-code.js index ec52dffd..0b18a8f6 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'] @@ -46,11 +50,13 @@ document.addEventListener('DOMContentLoaded', function () { input = window.neo4jDocs.copyableCommand(input) } - input = input.replace(/[ ]+\n/g, '\n').trimEnd() + input = cleanCallouts(input) + + // input = input.replace(/[ |\t]+\n/g, '\n').trimEnd() return input } - + var copyToClipboard = function (code, language) { var textarea = document.createElement('textarea') textarea.value = cleanCode(code, language) @@ -75,6 +81,16 @@ document.addEventListener('DOMContentLoaded', function () { } } + // capture copy command + let 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) } From 678379d68d2e76d51e540b3ea720d28650370270 Mon Sep 17 00:00:00 2001 From: Neil Dewhurst Date: Thu, 21 Dec 2023 16:44:13 +0000 Subject: [PATCH 3/4] great linting --- src/js/06-code.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/js/06-code.js b/src/js/06-code.js index 0b18a8f6..86dfa794 100644 --- a/src/js/06-code.js +++ b/src/js/06-code.js @@ -56,7 +56,7 @@ document.addEventListener('DOMContentLoaded', function () { return input } - + var copyToClipboard = function (code, language) { var textarea = document.createElement('textarea') textarea.value = cleanCode(code, language) @@ -82,14 +82,14 @@ document.addEventListener('DOMContentLoaded', function () { } // capture copy command - let copyThis = document.querySelectorAll("pre code") + 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())) + 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) From 7d2542d6657eae77e7cd13628c110a3193c3f71a Mon Sep 17 00:00:00 2001 From: Neil Dewhurst Date: Fri, 22 Dec 2023 14:00:33 +0000 Subject: [PATCH 4/4] remove commented out line --- src/js/06-code.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/js/06-code.js b/src/js/06-code.js index 86dfa794..f3d9f0e7 100644 --- a/src/js/06-code.js +++ b/src/js/06-code.js @@ -49,11 +49,7 @@ document.addEventListener('DOMContentLoaded', function () { if (language === 'bash' || language === 'sh' || language === 'shell' || language === 'console') { input = window.neo4jDocs.copyableCommand(input) } - input = cleanCallouts(input) - - // input = input.replace(/[ |\t]+\n/g, '\n').trimEnd() - return input }