Fix syntax highlighting regex order in config editors
All checks were successful
Deploy GSM / deploy (push) Successful in 22s

The number regex was applied after the boolean regex, causing it to
match "400" in CSS class names like "text-orange-400" and corrupt
the HTML output. Now uses placeholder tokens to mark numbers before
adding any HTML tags.

Affected editors: Palworld, Zomboid, OpenTTD

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-12 03:31:20 +01:00
parent 8447484270
commit 66716279ad
3 changed files with 15 additions and 8 deletions

View File

@@ -122,12 +122,13 @@ export default function ZomboidConfigEditor({ token }) {
const comment = highlighted.substring(idx)
highlighted = `${code}<span class="text-emerald-500">${comment}</span>`
}
// Highlight true/false/nil
// Highlight numbers first (with placeholders), then booleans
// This prevents the regex from matching numbers in CSS class names like "text-orange-400"
highlighted = highlighted
.replace(/\b(\d+\.?\d*)\b/g, '%%%NUM_START%%%$1%%%NUM_END%%%')
.replace(/\b(true|false|nil)\b/g, '<span class="text-orange-400">$1</span>')
// Highlight numbers
highlighted = highlighted
.replace(/\b(\d+\.?\d*)\b/g, '<span class="text-cyan-400">$1</span>')
.replace(/%%%NUM_START%%%/g, '<span class="text-cyan-400">')
.replace(/%%%NUM_END%%%/g, '</span>')
} else {
// INI: # comments
if (line.trim().startsWith('#')) {