Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Revises interpolation code

Author Dave Jarvis <email>
Date 2026-02-18 20:07:22 GMT-0800
Commit 23c8ff4bbd4991f083c4bd7da6135ebc64a0e3fb
Parent f9f161e
render/Highlighter.php
return $this->processSegments( $content, $pattern, function( $part ) {
- $out = htmlspecialchars( $part );
-
- if( str_starts_with( $part, '${' ) && str_ends_with( $part, '}' ) ) {
- $inner = substr( $part, 2, -1 );
- $out = $this->wrap( '${', 'hl-interp-punct', false ) .
- $this->wrap( $inner, 'hl-variable' ) .
- $this->wrap( '}', 'hl-interp-punct', false );
- } elseif( str_starts_with( $part, '$' ) && strlen( $part ) > 1 ) {
- $inner = substr( $part, 1 );
- $out = $this->wrap( '$', 'hl-interp-punct', false ) .
- $this->wrap( $inner, 'hl-variable' );
- } else {
+ if( !str_starts_with( $part, '$' ) || strlen( $part ) <= 1 ) {
$out = $this->wrap( $part, 'hl-string' );
+ } else {
+ $isComplex = str_starts_with( $part, '${' ) &&
+ str_ends_with( $part, '}' );
+
+ $inner = $isComplex ? substr( $part, 2, -1 ) : substr( $part, 1 );
+ $prefix = $isComplex ? '${' : '$';
+ $suffix = $isComplex
+ ? $this->wrap( '}', 'hl-interp-punct', false )
+ : '';
+
+ $out = $this->wrap( $prefix, 'hl-interp-punct', false ) .
+ $this->wrap( $inner, 'hl-variable' ) .
+ $suffix;
}
Delta 14 lines added, 12 lines removed, 2-line increase