Spaces:
Sleeping
Fix /mirror subtab clicks (HTML-escaped < in highlightCode regex broke entire script)
What this fixes
The Buddy mirror / AI emotions sub-tab buttons silently did nothing after PR #7 merged.
Root cause
In highlightCode(), the lookbehind regex was written into the HTML as (?<![a-zA-Z_])(\d+). The < got HTML-escaped to < and ended up inside the JS regex literal. When the browser parses the script, the JS engine sees (?<!...) inside the regex source, treats it as invalid, and throws a SyntaxError on script parse.
A parse-time SyntaxError kills the entire <script> block. None of it ever runs. That includes the line that registers the subtab click handler:
$("subtabs").querySelectorAll("button").forEach(b => b.addEventListener("click", () => setTab(b.dataset.tab)));
So clicks did nothing.
Fix
One-character change in mirror.html:
- .replace(/(?<![a-zA-Z_])(\d+)\b/g, '<span class="n">$1</span>');
+ .replace(/(?<![a-zA-Z_])(\d+)\b/g, '<span class="n">$1</span>');
Verified the script now parses cleanly. The remaining </> occurrences in the file are only inside the escapeHtml() mapping table where they belong as the actual entity strings.
Why a new PR
The fix was pushed to refs/pr/7 after PR #7 was merged, so it never reached main. This PR re-applies it on top of current main (92cd143c).