Fix double spacing with copy command

This commit is contained in:
Dave Gallant
2023-12-17 22:07:35 -05:00
parent bbf6a152e0
commit 1b2e976dc9
2 changed files with 8 additions and 6 deletions

View File

@@ -19,9 +19,10 @@ document
.forEach((highlightDiv) => createCopyButton(highlightDiv));
async function copyCodeToClipboard(button, highlightDiv) {
const codeToCopy = highlightDiv.querySelector(
"pre > code"
).innerText;
const codeToCopy = highlightDiv
.querySelector("pre > code ")
.innerText.replace(/\n\n/g, "\n") // Fix the double spacing
.replace(/\n$/, ""); // Clean up last empty line
try {
var result = await navigator.permissions.query({ name: "clipboard-write" });
if (result.state == "granted" || result.state == "prompt") {