From a07231f41af88153e195ce69138bb38a89982d30 Mon Sep 17 00:00:00 2001 From: iBug Date: Sun, 5 May 2024 19:43:24 +0800 Subject: [PATCH] LCS: Attempt to cherry-pick 0527e17 to get copy-to-clipboard Add "copy to clipboard" button for code blocks (#2812) * Add copy-to-clipboard button and JS * Ignore line numbers if present * Rewrite heading permalink code to use vanilla JS * README: Add credits to zenorocha/clipboard.js (MIT License) @iBug really wants a place here in the Credits section :P * Add .no-copy for hiding the button, update docs * Add td.rouge-code to selectors * Fix navigator.clipboard branch * Add screenreader text for copy button * Restore focus to the button after copying * Add site-wide enable switch --- _config.yml | 1 + _includes/head.html | 5 +- _sass/_utilities.scss | 57 ++++++++++++++++++++++ assets/js/_main.js | 107 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 164 insertions(+), 6 deletions(-) diff --git a/_config.yml b/_config.yml index f63c9038c952..40529b8569a0 100644 --- a/_config.yml +++ b/_config.yml @@ -17,6 +17,7 @@ repository : # GitHub username/repo-name e.g. "mmistakes/minimal-m teaser : # filename of teaser fallback teaser image placed in /images/, .e.g. "500x300.png" # breadcrumbs : false # true, false (default) words_per_minute : 200 +enable_copy_code_button : # true, false (default) comments: provider : # false (default), "disqus", "discourse", "facebook", "google-plus", "staticman", "custom" disqus: diff --git a/_includes/head.html b/_includes/head.html index ffcc741629ae..96eff1170ab9 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -11,8 +11,11 @@ - diff --git a/_sass/_utilities.scss b/_sass/_utilities.scss index 6776e9df6871..c6bd268961db 100644 --- a/_sass/_utilities.scss +++ b/_sass/_utilities.scss @@ -484,3 +484,60 @@ a.reversefootnote { color: $danger-color; font-weight: bold; } + +/* + Copy
 block to clipboard
+   ========================================================================== */
+
+// a