Skip to content

Commit 84ce0c6

Browse files
authored
Add syntax highlighting for variables on PHP 8.5 release page (#1626)
1 parent 26d39a1 commit 84ce0c6

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

include/layout.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ function highlight_php_trimmed($code, $return = false)
4747
$highlighted_code = highlight_php($code, true);
4848
$highlighted_code = preg_replace("!&lt;\?php(<br />)+!", '', $highlighted_code, 1);
4949

50+
// add syntax highlighting for variables
51+
$variableReplacer = function (array $matches) {
52+
if ($matches[1] !== '') {
53+
$replacement = '<span class="default">' . $matches[1] . '</span>';
54+
} else {
55+
$replacement = '';
56+
}
57+
return $replacement . '<span class="variable">' . $matches[2] . '</span>';
58+
};
59+
60+
$pattern = '!<span class="default">([\w\s]*)(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*\s*)</span>!';
61+
$highlighted_code = preg_replace_callback($pattern, $variableReplacer, $highlighted_code);
62+
5063
if ($return) { return $highlighted_code; }
5164
echo $highlighted_code;
5265
return null;

releases/8.5/release.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ final class PostsController
509509
)]
510510
public function update(
511511
Request $request,
512-
Post $post
512+
Post $post,
513513
): Response {
514514
// ...
515515
}
@@ -545,7 +545,7 @@ final class PostsController
545545
})]
546546
public function update(
547547
Request $request,
548-
Post $post
548+
Post $post,
549549
): Response {
550550
// ...
551551
}

styles/php85.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3564,6 +3564,11 @@ footer p:where(.dark,.dark *) {
35643564
background-color: transparent;
35653565
}
35663566

3567+
.php85 .phpcode span.variable {
3568+
color: #7d55ba;
3569+
background-color: transparent;
3570+
}
3571+
35673572
.php85 .phpcode span.keyword {
35683573
color: #07a;
35693574
background-color: transparent;
@@ -3585,13 +3590,18 @@ footer p:where(.dark,.dark *) {
35853590
background-color: transparent;
35863591
}
35873592

3593+
.dark .php85 .phpcode span.variable {
3594+
color: #a5d6ff;
3595+
background-color: transparent;
3596+
}
3597+
35883598
.dark .php85 .phpcode span.keyword {
35893599
color: #ff7b72;
35903600
background-color: transparent;
35913601
}
35923602

35933603
.dark .php85 .phpcode span.string {
3594-
color: #a5d6ff;
3604+
color: #80b83c;
35953605
background-color: transparent;
35963606
}
35973607

styles/theme-medium.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ div.warning a:focus {
832832
color: var(--dark-blue-color);
833833
background-color: transparent;
834834
}
835-
div.phpcode span.default {
835+
div.phpcode span.default, div.phpcode span.variable {
836836
color: #369;
837837
background-color: transparent;
838838
}

0 commit comments

Comments
 (0)