mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-03 14:06:40 -04:00
trim surrounding newlines from copied code
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import ClipboardJS from "clipboard";
|
||||
import trimNewlines from "trim-newlines";
|
||||
|
||||
// the default text of the copy button:
|
||||
const copyTerm = "Copy";
|
||||
@ -15,8 +16,12 @@ if (ClipboardJS.isSupported()) {
|
||||
highlightDiv.insertBefore(button, highlightDiv.firstChild);
|
||||
|
||||
new ClipboardJS(button, {
|
||||
// actual code element will have class "language-*", even if plaintext
|
||||
text: (trigger) => trigger.parentElement.querySelector('code[class^="language-"]').innerText, // eslint-disable-line quotes
|
||||
text: (trigger) => {
|
||||
// actual code element will (should) have class "language-*", even if plaintext
|
||||
const fenceElement = trigger.parentElement.querySelector('code[class^="language-"]'); // eslint-disable-line quotes
|
||||
|
||||
return fenceElement ? trimNewlines(fenceElement.innerText) : false;
|
||||
},
|
||||
}).on("success", (e) => {
|
||||
// show a subtle indication of success
|
||||
e.trigger.innerText = "✓";
|
||||
|
@ -50,6 +50,7 @@
|
||||
"node-fetch": "^2.6.1",
|
||||
"numeral": "2.0.6",
|
||||
"query-string": "^7.0.1",
|
||||
"trim-newlines": "4.0.2",
|
||||
"twemoji": "13.1.0",
|
||||
"twemoji-emojis": "14.1.0",
|
||||
"url-parse": "1.5.3"
|
||||
|
@ -10451,6 +10451,11 @@ totalist@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/totalist/-/totalist-1.1.0.tgz#a4d65a3e546517701e3e5c37a47a70ac97fe56df"
|
||||
integrity sha512-gduQwd1rOdDMGxFG1gEvhV88Oirdo2p+KjoYFU7k2g+i7n6AFFbDQ5kMPUsW0pNbfQsB/cwXvT1i4Bue0s9g5g==
|
||||
|
||||
trim-newlines@4.0.2:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-4.0.2.tgz#d6aaaf6a0df1b4b536d183879a6b939489808c7c"
|
||||
integrity sha512-GJtWyq9InR/2HRiLZgpIKv+ufIKrVrvjQWEj7PxAXNc5dwbNJkqhAUoAGgzRmULAnoOM5EIpveYd3J2VeSAIew==
|
||||
|
||||
trim-newlines@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"
|
||||
|
Reference in New Issue
Block a user