From 87d8826eada54d42fe0f701075283e00ecdec35d Mon Sep 17 00:00:00 2001 From: KJyang-0114 Date: Tue, 3 Mar 2026 20:49:37 +0800 Subject: [PATCH 1/2] 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; } From 898b3cf982b5d51967286f7d06f829534861ab6c Mon Sep 17 00:00:00 2001 From: KJyang-0114 Date: Tue, 3 Mar 2026 23:06:33 +0800 Subject: [PATCH 2/2] fix(bash): highlight command-line options (--option and -o) Add OPTIONS pattern to highlight command-line options like --project, --deployment-package, -f, etc. This fixes inconsistent highlighting where some options were highlighted as built_in while others had no highlighting at all. Fixes: #4288 --- pr-body.md | 13 +++++++++++++ src/languages/bash.js | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 pr-body.md diff --git a/pr-body.md b/pr-body.md new file mode 100644 index 0000000000..7893b328b4 --- /dev/null +++ b/pr-body.md @@ -0,0 +1,13 @@ +## Summary + +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. + +## 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 \ No newline at end of file diff --git a/src/languages/bash.js b/src/languages/bash.js index 44f9beba97..7f1ead88fe 100644 --- a/src/languages/bash.js +++ b/src/languages/bash.js @@ -369,6 +369,12 @@ export default function(hljs) { "yes" ]; + // Match command-line options like --project, --deployment-package, -f, etc. + const OPTIONS = { + className: 'attribute', + begin: /--[\w-]+|-\w(?!\s*=)/, + }; + return { name: 'Bash', aliases: [ @@ -401,7 +407,8 @@ export default function(hljs) { ESCAPED_QUOTE, APOS_STRING, ESCAPED_APOS, - VAR + VAR, + OPTIONS ] }; }