From 4425e21596053853723f1a00042c4eb3795fae61 Mon Sep 17 00:00:00 2001 From: Kian Kasad Date: Sat, 3 Apr 2021 18:24:39 -0700 Subject: [PATCH] add buttons to copy code block contents Adds a clickable "copy" link in the top-right corner of each code block. If available, uses the navigator.clipboard API. Falls back to selecting the text and calling document.execCommand('copy') to copy text. --- assets/css/common/main.css | 18 +++++++++++++++++- layouts/partials/footer.html | 31 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/assets/css/common/main.css b/assets/css/common/main.css index a22329e7..b3279aab 100644 --- a/assets/css/common/main.css +++ b/assets/css/common/main.css @@ -41,5 +41,21 @@ } code { - direction: ltr + direction: ltr; +} + +div.highlight { + position: relative; +} + +.copy-code { + position: absolute; + top: 4px; + right: 16px; + color: var(--secondary); +} + +.copy-code:hover { + cursor: pointer; + text-decoration: underline; } diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index eb87737e..6ab425f5 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -96,3 +96,34 @@ {{- end }} + +{{- if (not .Site.Params.disableCodeCopy) }} + +{{- end }}