From 87d8826eada54d42fe0f701075283e00ecdec35d Mon Sep 17 00:00:00 2001 From: KJyang-0114 Date: Tue, 3 Mar 2026 20:49:37 +0800 Subject: [PATCH] fix: skip re-highlighting to avoid false unescaped HTML warnings When highlightElement is called on already-highlighted code (e.g., consecutive hljs.highlightAll() calls), the existing tags from the previous highlighting are incorrectly flagged as "unescaped HTML" - a false positive security warning. This fix checks for the data-highlighted attribute early and silently skips re-highlighting, matching the proposed solution in issue #3761. --- src/highlight.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/highlight.js b/src/highlight.js index b7cea52485..afcb33c2dc 100644 --- a/src/highlight.js +++ b/src/highlight.js @@ -751,7 +751,8 @@ const HLJS = function(hljs) { { el: element, language }); if (element.dataset.highlighted) { - console.log("Element previously highlighted. To highlight again, first unset `dataset.highlighted`.", element); + // Already highlighted - skip to avoid false "unescaped HTML" warnings + // caused by hljs's own tags from previous highlighting return; }