Author: Jim Winstead (jimwins) Date: 2024-08-23T17:38:24-07:00 Commit: https://github.com/php/web-news/commit/bc3530e6d26e3596ecb88abe0c741d158467aa8c Raw diff: https://github.com/php/web-news/commit/bc3530e6d26e3596ecb88abe0c741d158467aa8c.diff
Add highlighting for Git commit message diffs, too Changed paths: M article.php M style.css Diff: diff --git a/article.php b/article.php index 2da7d6d..a2f0fa5 100644 --- a/article.php +++ b/article.php @@ -117,7 +117,7 @@ echo " <pre>\n"; $lines = preg_split("@(?<=\r\n|\n)@", $mail['text']); -$insig = 0; +$insig = $is_commit = $is_diff = 0; foreach ($lines as $line) { # fix lines that started with a period and got escaped @@ -125,6 +125,11 @@ $line = substr($line, 1); } + # Notice commit messages so we can highlight the diffs + if (str_starts_with($line, 'Commit: https://github.com/php')) { + $is_commit = 1; + } + # this is some amazingly simplistic code to color quotes/signatures # differently, and turn links into real links. it actually appears # to work fairly well, but could easily be made more sophistimicated. @@ -139,12 +144,20 @@ echo "<span class=\"signature\">"; $insig = 1; } + if (!$insig && $is_commit && preg_match('/^[-+]/', $line, $m)) { + $is_diff = 1; + echo '<span class="' . ($m[0] == '+' ? 'added' : 'removed') . '">'; + } if (!$insig && preg_match('/^((\w*?> ?)+)/', $line, $m)) { $level = substr_count($m[1], '>') % 4; echo "<span class=\"quote$level\">", wordwrap($line, 90, "\n" . $m[1]), "</span>"; } else { echo wordwrap($line, 90); } + if ($is_diff) { + $is_diff = 0; + echo '</span>'; + } } if ($insig) { diff --git a/style.css b/style.css index cb41eec..92ab9e3 100644 --- a/style.css +++ b/style.css @@ -370,6 +370,10 @@ table.standard th.subr { .quote3 { color: #a36008; } .quote0 { color: #909; } +/* Highlight of diffs in commit messages */ +.added { color: #000099; } +.removed { color: #990000; } + /* Dim signatures */ .signature { font-size: smaller; color: gray; } .signature a:link { color: #9999ff; }