diff --git a/example/dark-theme.css b/example/dark-theme.css new file mode 100644 index 00000000..1c0408bb --- /dev/null +++ b/example/dark-theme.css @@ -0,0 +1,186 @@ +body { + background: #3A3B46; + color: #F8F8F2; + font-family: Arial, serif; + font-size: 12px; +} + +pre { + width: 100%; + overflow: auto; +} + +a, a:visited { + color: #F8F8F2; +} + +/* + * HTML Renderers - General + */ + +.Differences { + width: 100%; + border-collapse: collapse; + border-spacing: 0; + empty-cells: show; +} + +.Differences thead th { + text-align: left; + border-bottom: 1px solid #000000; + background: #AAAAAA; + color: #000000; + padding: 4px; +} + +.Differences tbody th { + text-align: right; + background: #AAAAAA; + color: #272822; + width: 4em; + padding: 1px 2px; + border-right: 1px solid #000000; + vertical-align: top; + font-size: 13px; +} + +.Differences td { + padding: 1px 2px; + font-family: Consolas, monospace; + font-size: 13px; +} + +.Differences .Skipped { + background: #F7F7F7; +} + +/* + * HTML Side by Side Diff + */ +.DifferencesSideBySide .ChangeInsert td.Left { + background: green; +} + +.DifferencesSideBySide .ChangeInsert td.Right { + background: green; +} + +.DifferencesSideBySide .ChangeDelete td.Left { + background: #FF8888; + color: #272822; +} + +.DifferencesSideBySide .ChangeDelete td.Right { + background: #FFAAAA; + color: #272822; +} + +.DifferencesSideBySide .ChangeReplace .Left { + background: #FFEE99; + color: #272822; +} + +.DifferencesSideBySide .ChangeReplace .Right { + background: #FFDD88; + color: #272822; +} + +.Differences ins, +.Differences del { + text-decoration: none; +} + +.DifferencesSideBySide .ChangeReplace ins, +.DifferencesSideBySide .ChangeReplace del { + background: #EEBB00; +} + +/* + * HTML Inline Diff + */ + +.DifferencesInline .ChangeReplace { + color: #272822; +} + +.DifferencesInline .ChangeReplace .Left, +.DifferencesInline .ChangeDelete .Left { + background: #FFDDDD; + color: #272822; +} + +.DifferencesInline .ChangeReplace .Right, +.DifferencesInline .ChangeInsert .Right { + background: #DDFFDD; +} + +.DifferencesInline .ChangeReplace ins { + background: green; +} + +.DifferencesInline .ChangeReplace del { + background: #EE9999; + color: #272822; +} + +/* + * HTML Unified Diff + */ + +/* Line removed in new */ +.DifferencesUnified .ChangeDelete .Left::before { + content: "- \00a0"; +} + +.DifferencesUnified .ChangeDelete .Left { + background: #EE9999; + color: #272822; +} + +/* Line modified in old and new */ +.DifferencesUnified .ChangeReplace { + background: #FFEE99; + color: #272822; + display: table; +} + +/* Line in old replaced by line in new */ +.DifferencesUnified .ChangeReplace .Left:first-child:before { + content: "\250C \00a0"; +} + +.DifferencesUnified .ChangeReplace .Left:before { + content: "\251C \00a0"; +} + +.DifferencesUnified .ChangeReplace .Left { + background: #FFEE99; +} + +/* Line in new replaced line in old */ +.DifferencesUnified .ChangeReplace .Right:last-of-type:before { + content: "\2514 \00a0"; +} + +.DifferencesUnified .ChangeReplace .Right:before { + content: "\251C \00a0"; +} + +.DifferencesUnified .ChangeReplace .Right { + background: #FFEE99; +} + +/* Line inserted in new */ +.DifferencesUnified .ChangeInsert .Right:before { + content: "+ \00A0"; +} + +/* Character inserted in line of new */ +.DifferencesUnified .ChangeReplace ins { + background: #99EE99; +} + +/* Character removed from line in old */ +.DifferencesUnified .ChangeReplace del { + background: #EE9999; +} diff --git a/example/example.php b/example/example.php index 22eeecba..681f6869 100644 --- a/example/example.php +++ b/example/example.php @@ -32,10 +32,28 @@ PHP LibDiff - Examples - + +

PHP LibDiff - Examples

+

HTML Side by Side Diff

diff --git a/lib/Autoloader.php b/lib/Autoloader.php index 92491662..d2820528 100644 --- a/lib/Autoloader.php +++ b/lib/Autoloader.php @@ -13,7 +13,7 @@ * @author Mario Brandt * @copyright (c) 2015 Mario Brandt * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.17 + * @version 1.18 * @link https://github.com/JBlond/php-diff */ class Autoloader diff --git a/lib/jblond/Diff.php b/lib/jblond/Diff.php index 5845336b..4a77269f 100644 --- a/lib/jblond/Diff.php +++ b/lib/jblond/Diff.php @@ -23,10 +23,11 @@ * * @package jblond * @author Chris Boulton + * @author Mario Brandt * @author Ferry Cools * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.17 + * @version 1.18 * @link https://github.com/JBlond/php-diff */ class Diff diff --git a/lib/jblond/Diff/Renderer/Html/HtmlArray.php b/lib/jblond/Diff/Renderer/Html/HtmlArray.php index c15e98fd..0cd0d53c 100644 --- a/lib/jblond/Diff/Renderer/Html/HtmlArray.php +++ b/lib/jblond/Diff/Renderer/Html/HtmlArray.php @@ -13,10 +13,11 @@ * * @package jblond\Diff\Renderer\Html * @author Chris Boulton + * @author Mario Brandt * @author Ferry Cools * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.17 + * @version 1.18 * @link https://github.com/JBlond/php-diff */ class HtmlArray extends RendererAbstract diff --git a/lib/jblond/Diff/Renderer/Html/Inline.php b/lib/jblond/Diff/Renderer/Html/Inline.php index 1e8416ec..0b421622 100644 --- a/lib/jblond/Diff/Renderer/Html/Inline.php +++ b/lib/jblond/Diff/Renderer/Html/Inline.php @@ -11,10 +11,11 @@ * * @package jblond\Diff\Renderer\Html * @author Chris Boulton + * @author Mario Brandt * @author Ferry Cools * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.17 + * @version 1.18 * @link https://github.com/JBlond/php-diff */ class Inline extends HtmlArray diff --git a/lib/jblond/Diff/Renderer/Html/SideBySide.php b/lib/jblond/Diff/Renderer/Html/SideBySide.php index a334812c..128e8c98 100644 --- a/lib/jblond/Diff/Renderer/Html/SideBySide.php +++ b/lib/jblond/Diff/Renderer/Html/SideBySide.php @@ -11,10 +11,11 @@ * * @package jblond\Diff\Renderer\Html * @author Chris Boulton + * @author Mario Brandt * @author Ferry Cools * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.17 + * @version 1.18 * @link https://github.com/JBlond/php-diff */ class SideBySide extends HtmlArray diff --git a/lib/jblond/Diff/Renderer/Html/Unified.php b/lib/jblond/Diff/Renderer/Html/Unified.php index dcdbd8f4..6a60b11b 100644 --- a/lib/jblond/Diff/Renderer/Html/Unified.php +++ b/lib/jblond/Diff/Renderer/Html/Unified.php @@ -10,10 +10,11 @@ * PHP version 7.2 or greater * * @package jblond\Diff\Renderer\Html + * @author Mario Brandt * @author Ferry Cools * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.17 + * @version 1.18 * @link https://github.com/JBlond/php-diff */ class Unified extends HtmlArray diff --git a/lib/jblond/Diff/Renderer/RendererAbstract.php b/lib/jblond/Diff/Renderer/RendererAbstract.php index 50584fcd..f33ddc1c 100644 --- a/lib/jblond/Diff/Renderer/RendererAbstract.php +++ b/lib/jblond/Diff/Renderer/RendererAbstract.php @@ -13,10 +13,11 @@ * * @package jblond\Diff\Renderer * @author Chris Boulton + * @author Mario Brandt * @author Ferry Cools * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.17 + * @version 1.18 * @link https://github.com/JBlond/php-diff */ abstract class RendererAbstract diff --git a/lib/jblond/Diff/Renderer/Text/Context.php b/lib/jblond/Diff/Renderer/Text/Context.php index 7ace68fb..91d2c98f 100644 --- a/lib/jblond/Diff/Renderer/Text/Context.php +++ b/lib/jblond/Diff/Renderer/Text/Context.php @@ -13,10 +13,11 @@ * * @package jblond\Diff\Renderer\Text * @author Chris Boulton + * @author Mario Brandt * @author Ferry Cools * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.17 + * @version 1.18 * @link https://github.com/JBlond/php-diff */ class Context extends RendererAbstract diff --git a/lib/jblond/Diff/Renderer/Text/Unified.php b/lib/jblond/Diff/Renderer/Text/Unified.php index 9e922cd2..e1a8c616 100644 --- a/lib/jblond/Diff/Renderer/Text/Unified.php +++ b/lib/jblond/Diff/Renderer/Text/Unified.php @@ -13,9 +13,10 @@ * * @package jblond\Diff\Renderer\Text * @author Chris Boulton + * @author Mario Brandt * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.17 + * @version 1.18 * @link https://github.com/JBlond/php-diff */ diff --git a/lib/jblond/Diff/SequenceMatcher.php b/lib/jblond/Diff/SequenceMatcher.php index fdbbe367..2d7f0ce5 100644 --- a/lib/jblond/Diff/SequenceMatcher.php +++ b/lib/jblond/Diff/SequenceMatcher.php @@ -13,10 +13,11 @@ * * @package jblond\Diff * @author Chris Boulton + * @author Mario Brandt * @author Ferry Cools * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.17 + * @version 1.18 * @link https://github.com/JBlond/php-diff */ class SequenceMatcher @@ -566,14 +567,14 @@ public function getGroupedOpCodes(): array $lastItem = count($opCodes) - 1; if ($opCodes[$lastItem]['0'] == 'equal') { - [$tag, $i1, $i2, $j1, $j2] = $opCodes[$lastItem]; + [$tag, $item1, $item2, $item3, $item4] = $opCodes[$lastItem]; // Remove sequences at the end which are out of context. $opCodes[$lastItem] = [ $tag, - $i1, - min($i2, $i1 + $this->options['context']), - $j1, - min($j2, $j1 + $this->options['context']) + $item1, + min($item2, $item1 + $this->options['context']), + $item3, + min($item4, $item3 + $this->options['context']) ]; } } @@ -582,27 +583,27 @@ public function getGroupedOpCodes(): array $groups = []; $group = []; - foreach ($opCodes as [$tag, $i1, $i2, $j1, $j2]) { - if ($tag == 'equal' && $i2 - $i1 > $maxRange) { + foreach ($opCodes as [$tag, $item1, $item2, $item3, $item4]) { + if ($tag == 'equal' && $item2 - $item1 > $maxRange) { $group[] = [ $tag, - $i1, - min($i2, $i1 + $this->options['context']), - $j1, - min($j2, $j1 + $this->options['context']) + $item1, + min($item2, $item1 + $this->options['context']), + $item3, + min($item4, $item3 + $this->options['context']) ]; $groups[] = $group; $group = []; - $i1 = max($i1, $i2 - $this->options['context']); - $j1 = max($j1, $j2 - $this->options['context']); + $item1 = max($item1, $item2 - $this->options['context']); + $item3 = max($item3, $item4 - $this->options['context']); } $group[] = [ $tag, - $i1, - $i2, - $j1, - $j2 + $item1, + $item2, + $item3, + $item4 ]; }