highlightjs-badge
highlightjs-badge copied to clipboard
Trivial bug in detecting already applied badges.
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++) {
Nice PR, this looks like it might be worth committing?
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
:( )