From 9227867b1fbc4a8a56e0405d2f67303d8a63c33e Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 1 Jan 2024 12:52:13 +0100 Subject: [PATCH] fix code copy for snippets of code with line numbers --- README.md | 2 +- templates/partials/footer.html | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f0160c9..807be6e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Demo @ https://cydave.github.io/zola-theme-papermod/ + [ ] Regular Mode + [ ] Home-Info Mode + [ ] Profile Mode -+ [ ] Code copy buttons ++ [x] Code copy buttons + [ ] Search page + [ ] SEO Metadata + [ ] Language switcher (multi-language support) diff --git a/templates/partials/footer.html b/templates/partials/footer.html index 405f394..4b445e7 100644 --- a/templates/partials/footer.html +++ b/templates/partials/footer.html @@ -98,7 +98,12 @@ copybutton.addEventListener('click', (cb) => { if ('clipboard' in navigator) { - navigator.clipboard.writeText(codeblock.textContent); + var content = codeblock.textContent; + if(codeblock.firstChild.tagName == 'TABLE') { + content = Array(...codeblock.firstChild.getElementsByTagName('span')).map((span) => { return span.textContent; }).join(''); + } + console.log(content); + navigator.clipboard.writeText(content); copyingDone(); return; }