Skip to content

feat(ui): custom highlight rules (regex → color) - #58

Merged
ArianAr merged 2 commits into
mainfrom
feat/30-highlight-rules
Jul 15, 2026
Merged

feat(ui): custom highlight rules (regex → color)#58
ArianAr merged 2 commits into
mainfrom
feat/30-highlight-rules

Conversation

@ArianAr

@ArianAr ArianAr commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Summary

Implements roadmap v1.2.4 / issue #30.

  • Sidebar Highlights: add regex pattern + color, enable/disable, remove
  • Per-browser storage (papercut-highlight-rules); never sent to server
  • Match → HTML-escaped text with colored <mark> spans
  • No match → existing ANSI rendering
  • Cap 20 rules; invalid patterns rejected in UI; pathological match guard

Test plan

  • Unit tests: flags, compile, highlight, escape, storage, renderLineHtml
  • pnpm --filter @papercut/server test typecheck lint
  • Manual: add /error/i → error color, confirm matches; reload persistence

Closes #30

Browser-local highlight rules with regex patterns and color swatches.
Matching lines render plain text with escaped <mark> spans; non-matching
lines keep ANSI. Rules persist in localStorage (never server-side).

Closes #30
@ArianAr ArianAr added enhancement New feature or request area:ui Log canvas and web UI labels Jul 15, 2026
Address PR review: select non-overlapping spans by rule order (not only
start position), dedupe flag characters so duplicate flags do not throw,
and cap scan length on huge lines.

@ArianAr ArianAr left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Summary: Custom highlight rules are solid on privacy (localStorage only) and XSS (HTML-escaped text + whitelist mark classes). Unit tests cover compile, escape, storage, and rendering.

Findings and disposition

Severity Issue Status
bug Overlap used start-greedy selection; nested matches could prefer a later rule Fixed on branch (rule-order selection + test)
suggestion Match-count guard ≠ full ReDoS protection Accepted risk for client-only regex; scan capped at 16k chars
suggestion JSON lines use JsonInspector (no inline marks) Documented limitation; acceptable for v1
nit Duplicate flags (ii) could throw Fixed (dedupe in sanitizeHighlightFlags)
nit markClass must stay static for XSS Confirmed — colors from fixed options only

Verdict: LGTM after fixes; merge when CI green.

@ArianAr
ArianAr merged commit ea12c0e into main Jul 15, 2026
9 of 10 checks passed
@ArianAr
ArianAr deleted the feat/30-highlight-rules branch July 15, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ui Log canvas and web UI enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Canvas: custom highlight rules (regex → color)

1 participant