Skip to content

fix: skip re-highlighting to avoid false unescaped HTML warnings fixes #3761#4368

Open
KJyang-0114 wants to merge 1 commit intohighlightjs:mainfrom
KJyang-0114:fix/issue-3761-rehighlight
Open

fix: skip re-highlighting to avoid false unescaped HTML warnings fixes #3761#4368
KJyang-0114 wants to merge 1 commit intohighlightjs:mainfrom
KJyang-0114:fix/issue-3761-rehighlight

Conversation

@KJyang-0114
Copy link
Copy Markdown

Summary

When highlightElement is called on already-highlighted code (e.g., consecutive hljs.highlightAll() calls), the existing <span class="hljs-*"> tags from the previous highlighting are incorrectly flagged as "unescaped HTML" - a false positive security warning.

Fix

This fix checks for the data-highlighted attribute early and silently skips re-highlighting, matching the proposed solution in issue #3761.

Test

The fix prevents the false warning when calling hljs.highlightAll() multiple times on the same code blocks.

Fixes #3761

When highlightElement is called on already-highlighted code (e.g., consecutive
hljs.highlightAll() calls), the existing <span class="hljs-*"> 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 highlightjs#3761.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant