diff --git a/README.md b/README.md index 9fd6125e..d97ce02f 100644 --- a/README.md +++ b/README.md @@ -98,10 +98,6 @@ directory. Included is a light and a dark theme. ![HTML Inline Example](assets/htmlInline.png "HTML Inline Example") -#### HTML Unified Example - -![HTML Unified Example](assets/htmlUnified.png "HTML Unified Example") - #### Text Unified Example ![Text Unified Example](assets/textUnified.png "Text Unified Example") diff --git a/assets/htmlUnified.png b/assets/htmlUnified.png deleted file mode 100644 index bc63c8cd..00000000 Binary files a/assets/htmlUnified.png and /dev/null differ diff --git a/example/dark-theme.css b/example/dark-theme.css index 8bd57baf..3cf32779 100644 --- a/example/dark-theme.css +++ b/example/dark-theme.css @@ -153,65 +153,3 @@ a, a:visited { .DifferencesMerged th.ChangeDelete { background-image: linear-gradient(-45deg, #AAAAAA 0%, #EE9999 100%); } - -/* - * HTML Unified Diff - */ - -/* Line removed in new */ -.DifferencesUnified .ChangeDelete .Left::before { - content: "- \00a0"; -} - -.DifferencesUnified .ChangeDelete .Left { - background: #EE9999; - color: #272822; -} - -/* Line modified in old and new */ -.DifferencesUnified .ChangeReplace { - background: #FFEE99; - color: #272822; - display: table; -} - -/* Line in old replaced by line in new */ -.DifferencesUnified .ChangeReplace .Left:first-child:before { - content: "\250C \00a0"; -} - -.DifferencesUnified .ChangeReplace .Left:before { - content: "\251C \00a0"; -} - -.DifferencesUnified .ChangeReplace .Left { - background: #FFEE99; -} - -/* Line in new replaced line in old */ -.DifferencesUnified .ChangeReplace .Right:last-of-type:before { - content: "\2514 \00a0"; -} - -.DifferencesUnified .ChangeReplace .Right:before { - content: "\251C \00a0"; -} - -.DifferencesUnified .ChangeReplace .Right { - background: #FFEE99; -} - -/* Line inserted in new */ -.DifferencesUnified .ChangeInsert .Right:before { - content: "+ \00A0"; -} - -/* Character inserted in line of new */ -.DifferencesUnified .ChangeReplace ins { - background: #99EE99; -} - -/* Character removed from line in old */ -.DifferencesUnified .ChangeReplace del { - background: #EE9999; -} diff --git a/example/example.php b/example/example.php index fd8861e5..c231a32d 100644 --- a/example/example.php +++ b/example/example.php @@ -4,7 +4,6 @@ use jblond\Diff\Renderer\Html\Inline; use jblond\Diff\Renderer\Html\Merged; use jblond\Diff\Renderer\Html\SideBySide; -use jblond\Diff\Renderer\Html\Unified as HtmlUnified; use jblond\Diff\Renderer\Text\Context; use jblond\Diff\Renderer\Text\Unified; @@ -99,13 +98,6 @@ function changeCSS(cssFile, cssLinkIndex) { echo $diff->isIdentical() ? 'No differences found.' : $diff->Render($renderer); ?> -

HTML Unified Diff

-isIdentical() ? 'No differences found.' : '
' . $diff->Render($renderer) . '
'; -?> -

Text Unified Diff

- * @author Mario Brandt - * @author Ferry Cools - * @copyright (c) 2009 Chris Boulton - * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 2.3.0 - * @link https://github.com/JBlond/php-diff - */ -class Unified extends MainRenderer implements SubRendererInterface -{ - /** - * @var array Associative array containing the default options available for this renderer and their default - * value. - * - format Format of the texts. - * - insertMarkers Markers for inserted text. - * - deleteMarkers Markers for removed text. - * - title1 Title of the "old" version of text. - * - title2 Title of the "new" version of text. - */ - private $subOptions = [ - 'format' => 'html', - 'insertMarkers' => ['', ''], - 'deleteMarkers' => ['', ''], - 'title1' => 'Version1', - 'title2' => 'Version2', - ]; - - /** - * Unified constructor. - * - * @param array $options Custom defined options for the inline diff renderer. - * - * @see Inline::$subOptions - */ - public function __construct(array $options = []) - { - parent::__construct($this->subOptions); - $this->setOptions($options); - } - - /** - * @inheritDoc - * - * @return string|false The generated diff-view or false when there's no difference. - */ - public function render() - { - $changes = parent::renderSequences(); - - return parent::renderOutput($changes, $this); - } - - /** - * @inheritDoc - * - * @return string HTML code representation of the diff-view header. - */ - public function generateDiffHeader(): string - { - return ''; - } - - /** - * @inheritDoc - * - * @return string HTML code representation of a table's header. - */ - public function generateSkippedLines(): string - { - return ''; - } - - - /** - * @inheritDoc - * - * @return string HTML code representing the blocks of text with no difference. - */ - public function generateLinesEqual(array $changes): string - { - $html = ''; - - foreach ($changes['base']['lines'] as $line) { - $html .= '' . $line . '
'; - } - - return $html; - } - - /** - * @inheritDoc - * - * @return string HTML code representing a block of added text. - */ - public function generateLinesInsert(array $changes): string - { - $html = ''; - - foreach ($changes['changed']['lines'] as $line) { - $html .= '' . $line . '
'; - } - - return $html; - } - - /** - * @inheritDoc - * - * @return string HTML code representing a block of removed text. - */ - public function generateLinesDelete(array $changes): string - { - $html = ''; - foreach ($changes['base']['lines'] as $line) { - $html .= '' . $line . '
'; - } - - return $html; - } - - /** - * @inheritDoc - * - * @return string HTML code representing a block of modified text. - */ - public function generateLinesReplace(array $changes): string - { - $html = ''; - - // Lines with characters removed. - foreach ($changes['base']['lines'] as $line) { - $line = str_replace(["\0", "\1"], $this->options['deleteMarkers'], $line); - $html .= '' . $line . '
'; - } - - // Lines with characters added. - foreach ($changes['changed']['lines'] as $line) { - $line = str_replace(["\0", "\1"], $this->options['insertMarkers'], $line); - $html .= '' . $line . '
'; - } - - return $html; - } - - /** - * @inheritDoc - * - * @return string Start of the block. - */ - public function generateBlockHeader(array $changes): string - { - return ''; - } - - /** - * @inheritDoc - * - * @return string End of the block. - */ - public function generateBlockFooter(array $changes): string - { - return ''; - } - - /** - * @inheritDoc - * - * @return string End of the diff view. - */ - public function generateDiffFooter(): string - { - return '
'; - } -} diff --git a/tests/Diff/Renderer/Html/HtmlRenderersTest.php b/tests/Diff/Renderer/Html/HtmlRenderersTest.php index 5106d9ce..cb8bf303 100644 --- a/tests/Diff/Renderer/Html/HtmlRenderersTest.php +++ b/tests/Diff/Renderer/Html/HtmlRenderersTest.php @@ -8,7 +8,6 @@ use jblond\Diff\Renderer\Html\Inline; use jblond\Diff\Renderer\Html\Merged; use jblond\Diff\Renderer\Html\SideBySide; -use jblond\Diff\Renderer\Html\Unified; use PHPUnit\Framework\TestCase; /** @@ -112,25 +111,4 @@ public function testMerged() $this->assertStringEqualsFile('tests/resources/htmlMerged.txt', $result); } - - /** - * Test the output of the HTML Unified renderer. - * - * @covers \jblond\Diff\Renderer\Html\Unified - */ - public function testUnified() - { - $diff = new Diff( - file_get_contents('tests/resources/a.txt'), - file_get_contents('tests/resources/b.txt') - ); - - $renderer = new Unified(); - $result = $diff->render($renderer); - if ($this->genOutputFiles) { - file_put_contents('htmlUnified.txt', $result); - } - - $this->assertStringEqualsFile('tests/resources/htmlUnified.txt', $result); - } } diff --git a/tests/resources/htmlUnified.txt b/tests/resources/htmlUnified.txt deleted file mode 100644 index 8827106e..00000000 --- a/tests/resources/htmlUnified.txt +++ /dev/null @@ -1 +0,0 @@ -<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
        <title>Hello World!</title>
        <title>Hello You!</title>
    </head>
    <body>
        <h1>This is demo content to show features of the php-diff package.</h1>
        <h2>This line is removed from version2.</h2>
        <h2>This line is the same for both versions.</h2>
        <h2>this line has inline differences between both versions.</h2>
        <h2>This line has differences between both versions.</h2>
        <h2>This line is the same for both versions.</h2>
        <h2>This line also has inline differences between both versions.</h2>
        <h2>This line also has InLine differences between both versions.</h2>
        <h2>This line is the same for both versions.</h2>
        <h2>This line is added to version2.</h2>

        <p>
            It's also compatible with multibyte characters (like Chinese and emoji) as shown below:
            另外我覺得那個評的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
            Do you know what "金槍魚罐頭" means in Chinese?
            🍏🍎🙂
            另外我覺得那個評的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
            Do you know what "魚の缶詰" means in Chinese?
            🍎🍏🙂
        </p>

        <p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
        <p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
        <p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
        <p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
        <h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
        <h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
        <h2>This line is the same for both versions.</h2>
        <h2>This line also has inline differences between both versions.</h2>
        <h2>This line also has inline differences between both versions!</h2>
    </body>
</html>

\ No newline at end of file