-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite and simplify the package, add tests
No support for plaintext mode, no classes in del/ins tags Signed-off-by: Peter Legierski <[email protected]>
- Loading branch information
Peter Legierski
committed
Jul 31, 2014
1 parent
472213b
commit 889dff6
Showing
10 changed files
with
547 additions
and
865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace GatherContent\Htmldiff; | ||
|
||
use \cogpowered\FineDiff\Diff; | ||
use \cogpowered\FineDiff\Granularity\Paragraph as Granularity; | ||
|
||
class Differ implements DifferInterface | ||
{ | ||
private $diff; | ||
|
||
public function __construct(Processor $processor = null, Diff $diff = null) | ||
{ | ||
$this->diff = $diff ?: new Diff(new Granularity, new GitDiffRenderer); | ||
} | ||
|
||
public function diff($old, $new) | ||
{ | ||
return $this->diff->render($old, $new); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace GatherContent\Htmldiff; | ||
|
||
interface DifferInterface | ||
{ | ||
public function diff($old, $new); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* Here we try to end up with an output that looks like Git's diff. | ||
* It's a modified version of \cogpowered\FineDiff\Render\Html | ||
*/ | ||
|
||
namespace GatherContent\Htmldiff; | ||
|
||
use \cogpowered\FineDiff\Parser\OpcodeInterface; | ||
use \cogpowered\FineDiff\Render\Renderer; | ||
|
||
class GitDiffRenderer extends Renderer | ||
{ | ||
public function callback($opcode, $from, $from_offset, $from_len) | ||
{ | ||
if ($opcode === 'c') { | ||
|
||
$str = ' '.implode("\n ", explode("\n", substr($from, $from_offset, $from_len)))."\n"; | ||
$str = rtrim($str, "\n ")."\n"; | ||
|
||
} elseif ($opcode === 'd') { | ||
|
||
$deletion = substr($from, $from_offset, $from_len); | ||
|
||
if (strcspn($deletion, " \n\r") === 0) { | ||
|
||
$deletion = str_replace(array("\n","\r"), array('\n','\r'), $deletion); | ||
} | ||
|
||
$str = '-'.implode("\n-", explode("\n", $deletion))."\n"; | ||
$str = rtrim($str, "-\n")."\n"; | ||
|
||
} else /* if ( $opcode === 'i' ) */ { | ||
|
||
$str = '+'.implode("\n+", explode("\n", substr($from, $from_offset, $from_len)))."\n"; | ||
$str = rtrim($str, "+\n")."\n"; | ||
|
||
} | ||
|
||
return $str; | ||
} | ||
} |
Oops, something went wrong.