Text_Diff
[ class tree: Text_Diff ] [ index: Text_Diff ] [ all elements ]

Source for file inline.php

Documentation is available at inline.php

  1. <?php
  2. /**
  3.  * "Inline" diff renderer.
  4.  *
  5.  * This class renders diffs in the Wiki-style "inline" format.
  6.  *
  7.  * $Horde: framework/Text_Diff/Diff/Renderer/inline.php,v 1.3 2004/10/13 09:30:20 jan Exp $
  8.  *
  9.  * @author  Ciprian Popovici
  10.  * @package Text_Diff
  11.  */
  12.  
  13.     /**
  14.      * Number of leading context "lines" to preserve.
  15.      */
  16.     var $_leading_context_lines = 10000;
  17.  
  18.     /**
  19.      * Number of trailing context "lines" to preserve.
  20.      */
  21.     var $_trailing_context_lines = 10000;
  22.  
  23.     /**
  24.      * Prefix for inserted text.
  25.      */
  26.     var $_ins_prefix '<ins>';
  27.  
  28.     /**
  29.      * Suffix for inserted text.
  30.      */
  31.     var $_ins_suffix '</ins>';
  32.  
  33.     /**
  34.      * Prefix for deleted text.
  35.      */
  36.     var $_del_prefix '<del>';
  37.  
  38.     /**
  39.      * Suffix for deleted text.
  40.      */
  41.     var $_del_suffix '</del>';
  42.  
  43.     /**
  44.      * Header for each change block.
  45.      */
  46.     var $_block_header '';
  47.  
  48.     /**
  49.      * What are we currently splitting on? Used to recurse to show word-level
  50.      * changes.
  51.      */
  52.     var $_split_level 'lines';
  53.  
  54.     function _lines($lines$prefix ' ')
  55.     {
  56.         if ($this->_split_level == 'words'{
  57.             echo implode($lines' ');
  58.         else {
  59.             echo implode($lines"\n""\n";
  60.         }
  61.     }
  62.  
  63.     function _blockHeader($xbeg$xlen$ybeg$ylen)
  64.     {
  65.         return $this->_block_header;
  66.     }
  67.  
  68.     function _startBlock($header)
  69.     {
  70.         echo $header;
  71.     }
  72.  
  73.     function _added($lines)
  74.     {
  75.         array_unshift($lines$this->_ins_prefix);
  76.         array_push($lines$this->_ins_suffix);
  77.         $this->_lines($lines);
  78.     }
  79.  
  80.     function _deleted($lines)
  81.     {
  82.         array_unshift($lines$this->_del_prefix);
  83.         array_push($lines$this->_del_suffix);
  84.         $this->_lines($lines);
  85.     }
  86.  
  87.     function _changed($orig$final)
  88.     {
  89.         /* If we've already split on words, don't try to do so again - just
  90.          * display. */
  91.         if ($this->_split_level == 'words'{
  92.             $this->_deleted($orig);
  93.             $this->_added($final);
  94.             echo "\n";
  95.             return;
  96.         }
  97.  
  98.         $text1 implode("\n"$orig);
  99.         $text2 implode("\n"$final);
  100.  
  101.         /* Pad to make sure we can split on word boundaries. */
  102.         $text1 str_replace("\n"" \n"$text1);
  103.         $text2 str_replace("\n"" \n"$text2);
  104.  
  105.         /* Non-printing newline marker. */
  106.         $nl "\0";
  107.  
  108.         /* Save newlines. */
  109.         $text1 str_replace("\n"$nl$text1);
  110.         $text2 str_replace("\n"$nl$text2);
  111.  
  112.         /* Create the diff, splitting on word boundaries (loosely defined as
  113.          * spaces). */
  114.         $diff &new Text_Diff(explode(' '$text1),
  115.                                explode(' '$text2));
  116.  
  117.         /* Get the diff in inline format.
  118.          * FIXME: should propogate other parameters here too. */
  119.         $renderer &new Text_Diff_Renderer_inline(array('split_level' => 'words'));
  120.  
  121.         /* Restore newlines and display the result. */
  122.         echo str_replace($nl"\n"$renderer->render($diff));
  123.     }
  124.  
  125. }

Documentation generated on Mon, 11 Mar 2019 13:56:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.