highlightjs-badge icon indicating copy to clipboard operation
highlightjs-badge copied to clipboard

Trivial bug in detecting already applied badges.

Open h-tendy opened this issue 3 years ago • 2 comments

Hi Rick - Thanks for the great little library! Here's a small bug and suggested fix. Without it, more badges get overlayed on existing code-blocks... :

$ git diff highlightjs-badge.js
diff --git a/highlightjs-badge.js b/highlightjs-badge.js
index ddd4cc2..94880f6 100644
--- a/highlightjs-badge.js
+++ b/highlightjs-badge.js
@@ -154,9 +154,9 @@ function highlightJsBadge(opt) {
         var $codes = document.querySelectorAll("pre>code.hljs");
         for (var index = 0; index < $codes.length; index++) {
             var el = $codes[index];
-            if (el.querySelector(".code-badge"))
+            if (el.parentElement.querySelector(".code-badge"))
                 continue; // already exists
-
+
             var lang = "";

             for (var i = 0; i < el.classList.length; i++) {

h-tendy avatar Apr 12 '21 07:04 h-tendy

Nice PR, this looks like it might be worth committing?

cameronelliott avatar Oct 26 '21 03:10 cameronelliott

i ended up finding this problem as well. The problem is that the class code-badge is not added to the code tag. So find that line in the code and then add it to code tag. (hint : instead it's added to code.parent :( )

gillyspy avatar Feb 01 '22 15:02 gillyspy