Skip to content

2. Parameters and Options

Ferry Cools edited this page Dec 3, 2022 · 5 revisions

Parameters & Options

As well as the Diff class as the Renderer classes have many parameters and options.

  • The parameters and options for the Diff class will mainly affect the comparing process of the input texts.
  • The parameters and options for the Renderer Classes will mainly affect the output of the renderer itself.

Diff Class

Parameters

When instantiating the Diff class, the constructor accepts the following arguments:

Parameter Type Mandatory Description
$version1 string | array * The 1st version of the text to compare.
When the value is of type array, it's expected to have one line of text per element.
E.g. $value = ['First Line', 'Second Line', ...].
$version2 string | array * The 2nd version of the text to compare.
When the value is of type array, it's expected to have one line of text per element.
E.g. $value = ['First Line', 'Second Line', ...].
$options array Array of options with option/value pairs as described below.

Options

Options can be set by passing them to the constructor or by calling method Diff::setOptions().

Name Type Default Description
context int 3 Amount of 'context' lines around a difference.
E.g. If line 5 differs, show line 2 to 8 (2 > 5 < 8).
trimEqual bool true If true, the first and the last equal parts of the compared texts are excluded from the result.
ignoreWhitespace bool false If true, tabs and spaces are ignored while comparing. The spacing of version 1 is leading.
ignoreCase bool false If true, character casing is ignored while comparing. The casing of version 1 is leading.

Main Renderer

Parameters

When instantiating the Main Renderer class, the constructor accepts the following arguments:

Parameter Type Mandatory Description
$options array Array of options with option/value pairs as described below.

Options

Options can be set by passing them to the constructor or by calling method MainRenderer::setOptions().

Note: Besides the predefined options, it's possible to pass 'custom' options. They will not be used, but once such options are set, it can't be removed anymore by using the above method.

Name Type Default Description
inlineMarking int 2 The level of how differences are marked.
  1. CHANGE_LEVEL_CHAR: Inline-Mark each different character.
  2. CHANGE_LEVEL_WORD: Inline-Mark each different word.
  3. CHANGE_LEVEL_LINE: Inline-Mark from first to last line diff.
Other values result in CHANGE_LEVEL_NONE: Don't Inline-Mark.
tabSize int | false 4 The amount of spaces to replace a tab character with.
If set to false the tabs won't be replaced.
format string 'plain' The format of the input texts.
If set to 'plain', the content will be treated as plain text.
If set to 'html', the content will be treated as HTML and the renderer will convert special characters to html enitites.
cliColor bool false Colorized output.
Meant for renderers which output to a cli.
deleteMarkers array ['', ''] Markers for removed text.
Text which exists in version 1, but not in version 2 will be surrounded by these markers.
insertMarkers array ['', ''] Markers for inserted text.
Text which doesn't exists in version 1, but is present in version 2 will be surrounded by these markers.
equalityMarkers array ['', ''] Markers for unchanged and changed lines.
Used for in front marking of a line to indicate a line is equal between the two versions or not.
insertColors array ['', ''] Fore- and background color for inserted text. Only when cliColor = true.
deleteColors array ['', ''] Fore- and background color for removed text. Only when cliColor = true.

Sub Renderers

Most of the included renderers extends the Main Renderer class. Therefore, these classes have at least the same options as the Main renderer.

The Sub Renderer classes may or may not override the default values. Options which aren't described for a Sub Renderer, but are present in the Main renderer, will have the default value as described at the Main Renderer paragraph.

HTML Inline Renderer

Parameters

When instantiating this Sub Renderer class, the constructor accepts the following arguments:

Parameter Type Mandatory Description
$options array Array of options with option/value pairs as described below.

Options

Name Type Default Description
format string 'html' The format of the input texts.
If set to 'plain', the content will be treated as plain text.
If set to 'html', the content will be treated as HTML and the renderer will convert special characters to html enitites.
deleteMarkers array ['<del>', '</del>'] Markers for removed text.
insertMarkers array ['<ins>', '</ins>'] Markers for inserted text.
title1 string 'Version1' Title of the 1st version
Used in the table header of the rendered output.
title2 string 'Version2' Title of the 2nd version
Used in the table header of the rendered output.

HTML Side By Side Renderer

Parameters

When instantiating this Sub Renderer class, the constructor accepts the following arguments:

Parameter Type Mandatory Description
$options array Array of options with option/value pairs as described below.

Options

Name Type Default Description
format string 'html' The format of the input texts.
If set to 'plain', the content will be treated as plain text.
If set to 'html', the content will be treated as HTML and the renderer will convert special characters to html enitites.
deleteMarkers array ['<del>', '</del>'] Markers for removed text.
insertMarkers array ['<ins>', '</ins>'] Markers for inserted text.
title1 string 'Version1' Title of the 1st version
Used in the table header of the rendered output.
title2 string 'Version2' Title of the 2nd version
Used in the table header of the rendered output.

HTML Unified Renderer

Parameters

When instantiating this Sub Renderer class, the constructor accepts the following arguments:

Parameter Type Mandatory Description
$options array Array of options with option/value pairs as described below.

Options

Name Type Default Description
format string 'html' The format of the input texts.
If set to 'plain', the content will be treated as plain text.
If set to 'html', the content will be treated as HTML and the renderer will convert special characters to html enitites.
deleteMarkers array ['<del>', '</del>'] Markers for removed text.
insertMarkers array ['<ins>', '</ins>'] Markers for inserted text.
title1 string 'Version1' Title of the 1st version
Used in the table header of the rendered output.
title2 string 'Version2' Title of the 2nd version
Used in the table header of the rendered output.

Text Inline CLI Renderer

Parameters

When instantiating this Sub Renderer class, the constructor accepts the following arguments:

Parameter Type Mandatory Description
$options array Array of options with option/value pairs as described below.

Options

Currently, this class doesn't override any of the default options of the Main Renderer class.

Text Unified CLI Renderer

Parameters

When instantiating this Sub Renderer class, the constructor accepts the following arguments:

Parameter Type Mandatory Description
$options array Array of options with option/value pairs as described below.

Currently, this class doesn't override any of the default options of the Main Renderer class.