[web-doc] master: add diff-highlighting

From: Date: Tue, 18 May 2021 23:36:29 +0000
Subject: [web-doc] master: add diff-highlighting
Groups: php.doc.web 
Request: Send a blank email to doc-web+get-2475@lists.php.net to get a copy of this message
Author: Nilgün Belma Bugüner (nilgun) Date: 2021-05-19T02:36:32+03:00 Commit: https://github.com/php/web-doc/commit/18f34e4103e01c281056ae0591a1cbb1bbfdcb49 Raw diff: https://github.com/php/web-doc/commit/18f34e4103e01c281056ae0591a1cbb1bbfdcb49.diff add diff-highlighting Changed paths: M www/revcheck.php Diff: diff --git a/www/revcheck.php b/www/revcheck.php index 490155f..cd86030 100644 --- a/www/revcheck.php +++ b/www/revcheck.php @@ -354,12 +354,13 @@ $key = $r['name'] . '/' . $r['file']; if ($r['name'] == '/') $key = $r['file']; - + //plaintext -color + $d1 = "?p=plain&amp;lang={$lang}&amp;hbp={$r['trans_rev']}&amp;f=$key&amp;c=on"; // GitHub web diff -- May not work with very old commits - $kh = hash( 'sha256' , $key ); - $d1 = "https://github.com/php/doc-en/compare/{$r['trans_rev']}..{$r['en_rev']}#diff-{$kh}"; - //plaintext -- Always work - $d2 = "?p=plain&amp;lang={$lang}&amp;hbp={$r['trans_rev']}&amp;f=$key"; + //$kh = hash( 'sha256' , $key ); + //"https://github.com/php/doc-en/compare/{$r['trans_rev']}..{$r['en_rev']}#diff-{$kh}"; + //plaintext + $d2 = "?p=plain&amp;lang={$lang}&amp;hbp={$r['trans_rev']}&amp;f=$key&amp;c=off"; $h1 = "<a href='https://github.com/php/doc-en/blob/{$r['en_rev']}/$key'>{$r['en_rev']}</a>"; @@ -381,15 +382,38 @@ break; case 'plain': - if (isset($_GET['f'])) { - $gitfile = $_GET['f']; - if (isset($_GET['hbp'])) $h2 = $_GET['hbp']; - $cwd = getcwd(); - chdir( GIT_DIR . 'en' ); - $file = git diff {$h2} -- {$gitfile}; - echo "<pre>", htmlspecialchars($file, ENT_QUOTES, 'UTF-8'), "</pre>"; - chdir( $cwd ); - } + if (isset($_GET['f'])) { + $gitfile = $_GET['f']; + if (isset($_GET['hbp'])) + $h2 = $_GET['hbp']; + $cwd = getcwd(); + chdir( GIT_DIR . 'en' ); + $file = git diff {$h2} -- {$gitfile}; + chdir( $cwd ); + $raw = htmlspecialchars($file, ENT_XML1, 'UTF-8'); + if (isset($_GET['c'])) + $c = $_GET['c']; + if ( $c == 'on' ) { + $trans = [ " " => "&nbsp;" ]; + $lines = explode ( "\n" , $raw ); + foreach ($lines as $line) { + $inline = strtr($line , $trans); + $fc = substr($inline , 0 , 1); + if ( $fc == "+" ) { + echo "<div style='color:green;font-family:mono'>"; + } elseif ( $fc == "-" ) { + echo "<div style='color:red;font-family:mono'>"; + } elseif ( $fc == "@" ) { + echo "<div style='color:blue;font-family:mono'>"; + } else + echo "<div style='color:gray;font-family:mono'>"; + echo "$inline</div>\n"; + } + echo "<p></p>"; + } else + echo "<pre style='font-family:mono'>" , $raw , "</pre>"; + } + echo gen_date($DBLANG); break;

« previous php.doc.web (#2475) next »