From ce3f34bbc7b793b3c91a57056c9adf95d45d5a3e Mon Sep 17 00:00:00 2001 From: Simone <26844016+simonebortolin@users.noreply.github.com> Date: Tue, 27 Dec 2022 01:45:37 +0100 Subject: [PATCH] Add copy code button to code snippets (#945) Hello everyone, this is my implementation for the copy button on the snippet (requested in #924) The implementation is made 100% javascript as with or without a jekyll template modification you still have to execute some javascript code, and I consider it the best choice. the button only appears if the mouse is over it, to allow the entire line to be read the important CSS changes were made to make the copy button work even in the long code situation: ![image](https://user-images.githubusercontent.com/26844016/187731472-d4bf7828-2356-4d94-9c2d-9db863228f5f.png) to avoid this: ![image](https://user-images.githubusercontent.com/26844016/183292313-d7f73d7d-58c0-4c7b-b5ba-e08bd285514b.png) Co-authored-by: Matt Wang --- _config.yml | 3 + _includes/icons/code_copy.html | 15 +++++ _layouts/default.html | 1 + _sass/code.scss | 108 +++++++++++++++++++++++++-------- assets/js/just-the-docs.js | 41 +++++++++++++ docs/ui-components/code.md | 11 ++++ 6 files changed, 154 insertions(+), 25 deletions(-) create mode 100644 _includes/icons/code_copy.html diff --git a/_config.yml b/_config.yml index 86706fb..2273e8b 100644 --- a/_config.yml +++ b/_config.yml @@ -73,6 +73,9 @@ search: # Supports true or false (default) button: false +# For copy button on code +enable_copy_code_button: true + # To disable support for mermaid diagrams (https://mermaid-js.github.io/mermaid/), # comment out the `mermaid` and `version` keys below # By default, consuming the theme as a gem leaves mermaid disabled; it is opt-in diff --git a/_includes/icons/code_copy.html b/_includes/icons/code_copy.html new file mode 100644 index 0000000..02f5068 --- /dev/null +++ b/_includes/icons/code_copy.html @@ -0,0 +1,15 @@ + + + Copy + + + + + + + Copied + + + + + \ No newline at end of file diff --git a/_layouts/default.html b/_layouts/default.html index f80f52d..7ac9269 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -40,6 +40,7 @@ layout: table_wrappers {% include icons/external_link.html %} + {% include icons/code_copy.html %}