Skip to content

lineNumber option #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Renderer/AbstractRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ abstract class AbstractRenderer implements RendererInterface
'tabSize' => 4,
// show a separator between different diff hunks in HTML renderers
'separateBlock' => true,
// show line numbers in HTML renderers
'lineNumbers' => true,
// the frontend HTML could use CSS "white-space: pre;" to visualize consecutive whitespaces
// but if you want to visualize them in the backend with " ", you can set this to true
'spacesToNbsp' => false,
Expand Down
52 changes: 37 additions & 15 deletions src/Renderer/Html/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,18 @@ protected function redererChanges(array $changes): string
*/
protected function renderTableHeader(): string
{
$colspan = (!$this->options['lineNumbers'] ? ' colspan="2"' : '');

return
'<thead>' .
'<tr>' .
'<th>' . $this->_('old_version') . '</th>' .
'<th>' . $this->_('new_version') . '</th>' .
'<th></th>' .
'<th>' . $this->_('differences') . '</th>' .
($this->options['lineNumbers'] ?
'<th>' . $this->_('old_version') . '</th>' .
'<th>' . $this->_('new_version') . '</th>' .
'<th></th>'
: ''
) .
'<th' . $colspan . '>' . $this->_('differences') . '</th>' .
'</tr>' .
'</thead>';
}
Expand All @@ -71,10 +76,12 @@ protected function renderTableHeader(): string
*/
protected function renderTableSeparateBlock(): string
{
$colspan = (!$this->options['lineNumbers'] ? '2' : '4');

return
'<tbody class="skipped">' .
'<tr>' .
'<td colspan="4"></td>' .
'<td colspan="' . $colspan . '"></td>' .
'</tr>' .
'</tbody>';
}
Expand Down Expand Up @@ -119,8 +126,11 @@ protected function renderTableEqual(array $change): string

$html .=
'<tr data-type="=">' .
'<th class="n-old">' . $oldLineNum . '</th>' .
'<th class="n-new">' . $newLineNum . '</th>' .
($this->options['lineNumbers'] ?
'<th class="n-old">' . $oldLineNum . '</th>' .
'<th class="n-old">' . $newLineNum . '</th>'
: ''
) .
'<th class="sign"></th>' .
'<td class="old">' . $oldLine . '</td>' .
'</tr>';
Expand All @@ -143,8 +153,11 @@ protected function renderTableInsert(array $change): string

$html .=
'<tr data-type="+">' .
'<th></th>' .
'<th class="n-new">' . $newLineNum . '</th>' .
($this->options['lineNumbers'] ?
'<th></th>' .
'<th class="n-new">' . $newLineNum . '</th>'
: ''
) .
'<th class="sign ins">+</th>' .
'<td class="new">' . $newLine . '</td>' .
'</tr>';
Expand All @@ -167,8 +180,11 @@ protected function renderTableDelete(array $change): string

$html .=
'<tr data-type="-">' .
'<th class="n-old">' . $oldLineNum . '</th>' .
'<th></th>' .
($this->options['lineNumbers'] ?
'<th class="n-old">' . $oldLineNum . '</th>' .
'<th></th>'
: ''
) .
'<th class="sign del">-</th>' .
'<td class="old">' . $oldLine . '</td>' .
'</tr>';
Expand All @@ -191,8 +207,11 @@ protected function renderTableReplace(array $change): string

$html .=
'<tr data-type="-">' .
'<th class="n-old">' . $oldLineNum . '</th>' .
'<th></th>' .
($this->options['lineNumbers'] ?
'<th class="n-old">' . $oldLineNum . '</th>' .
'<th></th>'
: ''
) .
'<th class="sign del">-</th>' .
'<td class="old">' . $oldLine . '</td>' .
'</tr>';
Expand All @@ -203,8 +222,11 @@ protected function renderTableReplace(array $change): string

$html .=
'<tr data-type="+">' .
'<th></th>' .
'<th class="n-new">' . $newLineNum . '</th>' .
($this->options['lineNumbers'] ?
'<th></th>' .
'<th class="n-new">' . $newLineNum . '</th>'
: ''
) .
'<th class="sign ins">+</th>' .
'<td class="new">' . $newLine . '</td>' .
'</tr>';
Expand Down
60 changes: 47 additions & 13 deletions src/Renderer/Html/SideBySide.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ protected function redererChanges(array $changes): string
*/
protected function renderTableHeader(): string
{
$colspan = ($this->options['lineNumbers'] ? ' colspan="2"' : '');

return
'<thead>' .
'<tr>' .
'<th colspan="2">' . $this->_('old_version') . '</th>' .
'<th colspan="2">' . $this->_('new_version') . '</th>' .
'<th' . $colspan . '>' . $this->_('old_version') . '</th>' .
'<th' . $colspan . '>' . $this->_('new_version') . '</th>' .
'</tr>' .
'</thead>';
}
Expand All @@ -69,10 +71,12 @@ protected function renderTableHeader(): string
*/
protected function renderTableSeparateBlock(): string
{
$colspan = (!$this->options['lineNumbers'] ? '2' : '4');

return
'<tbody class="skipped">' .
'<tr>' .
'<td colspan="4"></td>' .
'<td colspan="' . $colspan . '"></td>' .
'</tr>' .
'</tbody>';
}
Expand Down Expand Up @@ -117,9 +121,15 @@ protected function renderTableEqual(array $change): string

$html .=
'<tr>' .
'<th class="n-old">' . $oldLineNum . '</th>' .
($this->options['lineNumbers'] ?
'<th class="n-old">' . $oldLineNum . '</th>'
: ''
) .
'<td class="old">' . $oldLine . '</td>' .
'<th class="n-new">' . $newLineNum . '</th>' .
($this->options['lineNumbers'] ?
'<th class="n-new">' . $newLineNum . '</th>'
: ''
) .
'<td class="new">' . $newLine . '</td>' .
'</tr>';
}
Expand All @@ -141,9 +151,15 @@ protected function renderTableInsert(array $change): string

$html .=
'<tr>' .
'<th></th>' .
($this->options['lineNumbers'] ?
'<th></th>'
: ''
) .
'<td class="old"></td>' .
'<th class="n-new">' . $newLineNum . '</th>' .
($this->options['lineNumbers'] ?
'<th class="n-new">' . $newLineNum . '</th>'
: ''
) .
'<td class="new">' . $newLine . '</td>' .
'</tr>';
}
Expand All @@ -165,9 +181,15 @@ protected function renderTableDelete(array $change): string

$html .=
'<tr>' .
'<th class="n-old">' . $oldLineNum . '</th>' .
($this->options['lineNumbers'] ?
'<th class="n-old">' . $oldLineNum . '</th>'
: ''
) .
'<td class="old">' . $oldLine . '</td>' .
'<th></th>' .
($this->options['lineNumbers'] ?
'<th></th>'
: ''
) .
'<td class="new"></td>' .
'</tr>';
}
Expand Down Expand Up @@ -198,9 +220,15 @@ protected function renderTableReplace(array $change): string

$html .=
'<tr>' .
'<th class="n-old">' . $oldLineNum . '</th>' .
($this->options['lineNumbers'] ?
'<th class="n-old">' . $oldLineNum . '</th>'
: ''
) .
'<td class="old"><span>' . $oldLine . '</span></td>' .
'<th class="n-new">' . $newLineNum . '</th>' .
($this->options['lineNumbers'] ?
'<th class="n-new">' . $newLineNum . '</th>'
: ''
) .
'<td class="new">' . $newLine . '</td>' .
'</tr>';
}
Expand All @@ -218,9 +246,15 @@ protected function renderTableReplace(array $change): string

$html .=
'<tr>' .
'<th class="n-old">' . $oldLineNum . '</th>' .
($this->options['lineNumbers'] ?
'<th class="n-old">' . $oldLineNum . '</th>'
: ''
) .
'<td class="old"><span>' . $oldLine . '</span></td>' .
'<th class="n-new">' . $newLineNum . '</th>' .
($this->options['lineNumbers'] ?
'<th class="n-new">' . $newLineNum . '</th>'
: ''
) .
'<td class="new">' . $newLine . '</td>' .
'</tr>';
}
Expand Down