mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Update Text_Diff. Props simek. Fixes #9467
git-svn-id: https://develop.svn.wordpress.org/trunk@13211 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
/**
|
||||
* "Inline" diff renderer.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Renderer/inline.php,v 1.21 2008/01/04 10:07:51 jan Exp $
|
||||
*
|
||||
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
|
||||
* Copyright 2004-2010 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
@@ -30,42 +28,65 @@ class Text_Diff_Renderer_inline extends Text_Diff_Renderer {
|
||||
|
||||
/**
|
||||
* Number of leading context "lines" to preserve.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
var $_leading_context_lines = 10000;
|
||||
|
||||
/**
|
||||
* Number of trailing context "lines" to preserve.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
var $_trailing_context_lines = 10000;
|
||||
|
||||
/**
|
||||
* Prefix for inserted text.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_ins_prefix = '<ins>';
|
||||
|
||||
/**
|
||||
* Suffix for inserted text.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_ins_suffix = '</ins>';
|
||||
|
||||
/**
|
||||
* Prefix for deleted text.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_del_prefix = '<del>';
|
||||
|
||||
/**
|
||||
* Suffix for deleted text.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_del_suffix = '</del>';
|
||||
|
||||
/**
|
||||
* Header for each change block.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_block_header = '';
|
||||
|
||||
/**
|
||||
* Whether to split down to character-level.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
var $_split_characters = false;
|
||||
|
||||
/**
|
||||
* What are we currently splitting on? Used to recurse to show word-level
|
||||
* changes.
|
||||
* or character-level changes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_split_level = 'lines';
|
||||
|
||||
@@ -85,10 +106,10 @@ class Text_Diff_Renderer_inline extends Text_Diff_Renderer {
|
||||
array_walk($lines, array(&$this, '_encode'));
|
||||
}
|
||||
|
||||
if ($this->_split_level == 'words') {
|
||||
return implode('', $lines);
|
||||
} else {
|
||||
if ($this->_split_level == 'lines') {
|
||||
return implode("\n", $lines) . "\n";
|
||||
} else {
|
||||
return implode('', $lines);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,8 +131,13 @@ class Text_Diff_Renderer_inline extends Text_Diff_Renderer {
|
||||
|
||||
function _changed($orig, $final)
|
||||
{
|
||||
/* If we've already split on words, don't try to do so again - just
|
||||
* display. */
|
||||
/* If we've already split on characters, just display. */
|
||||
if ($this->_split_level == 'characters') {
|
||||
return $this->_deleted($orig)
|
||||
. $this->_added($final);
|
||||
}
|
||||
|
||||
/* If we've already split on words, just display. */
|
||||
if ($this->_split_level == 'words') {
|
||||
$prefix = '';
|
||||
while ($orig[0] !== false && $final[0] !== false &&
|
||||
@@ -130,15 +156,23 @@ class Text_Diff_Renderer_inline extends Text_Diff_Renderer {
|
||||
/* Non-printing newline marker. */
|
||||
$nl = "\0";
|
||||
|
||||
/* We want to split on word boundaries, but we need to
|
||||
* preserve whitespace as well. Therefore we split on words,
|
||||
* but include all blocks of whitespace in the wordlist. */
|
||||
$diff = new Text_Diff($this->_splitOnWords($text1, $nl),
|
||||
$this->_splitOnWords($text2, $nl));
|
||||
if ($this->_split_characters) {
|
||||
$diff = new Text_Diff('native',
|
||||
array(preg_split('//', $text1),
|
||||
preg_split('//', $text2)));
|
||||
} else {
|
||||
/* We want to split on word boundaries, but we need to preserve
|
||||
* whitespace as well. Therefore we split on words, but include
|
||||
* all blocks of whitespace in the wordlist. */
|
||||
$diff = new Text_Diff('native',
|
||||
array($this->_splitOnWords($text1, $nl),
|
||||
$this->_splitOnWords($text2, $nl)));
|
||||
}
|
||||
|
||||
/* Get the diff in inline format. */
|
||||
$renderer = new Text_Diff_Renderer_inline(array_merge($this->getParams(),
|
||||
array('split_level' => 'words')));
|
||||
$renderer = new Text_Diff_Renderer_inline
|
||||
(array_merge($this->getParams(),
|
||||
array('split_level' => $this->_split_characters ? 'characters' : 'words')));
|
||||
|
||||
/* Run the diff and get the output. */
|
||||
return str_replace($nl, "\n", $renderer->render($diff)) . "\n";
|
||||
|
||||
Reference in New Issue
Block a user