Text_Diff_Renderer
- Source
wp-includes/Text/Diff/Renderer.php:15
A class to render Diffs in different formats.
Description
This class renders the diff in classic diff format. It is intended that this class be customized via inheritance, to obtain fancier outputs.
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 https://opensource.org/license/lgpl-2-1/.
Compatibility
- WordPress
- core
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Properties · 2
$_leading_context_linespublic- Number of leading context "lines" to preserve.
$_trailing_context_linespublic- Number of trailing context "lines" to preserve.
Methods · 15
- __construct()Constructor.
- Text_Diff_Renderer()PHP4 constructor.
- getParams()Get any renderer parameters.
- render()Renders a diff.
- _block()
- _startDiff()
- _endDiff()
- _blockHeader()
- _startBlock()
- _endBlock()
- _lines()
- _context()
- _added()
- _deleted()
- _changed()
Source code
class Text_Diff_Renderer { /** * Number of leading context "lines" to preserve. * * This should be left at zero for this class, but subclasses may want to * set this to other values. */ var $_leading_context_lines = 0; /** * Number of trailing context "lines" to preserve. * * This should be left at zero for this class, but subclasses may want to * set this to other values. */ var $_trailing_context_lines = 0; /** * Constructor. */ function __construct( $params = array() ) { foreach ($params as $param => $value) { $v = '_' . $param; if (isset($this->$v)) { $this->$v = $value; } } } /** * PHP4 constructor. */ public function Text_Diff_Renderer( $params = array() ) { self::__construct( $params ); } /** * Get any renderer parameters. * * @return array All parameters of this renderer object. */ function getParams() { $params = array(); foreach (get_object_vars($this) as $k => $v) { if ($k[0] == '_') { $params[substr($k, 1)] = $v; } } return $params; } /** * Renders a diff. * * @param Text_Diff $diff A Text_Diff object. * * @return string The formatted output. */ function render($diff) { $xi = $yi = 1; $block = false; $context = array(); $nlead = $this->_leading_context_lines; $ntrail = $this->_trailing_context_lines; $output = $this->_startDiff(); $diffs = $diff->getDiff(); foreach ($diffs as $i => $edit) { /* If these are unchanged (copied) lines, and we want to keep * leading or trailing context lines, extract them from the copy * block. */ if (is_a($edit, 'Text_Diff_Op_copy')) { /* Do we have any diff blocks yet? */Changelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/Text/Diff/Renderer.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.