|
1 | | -[](https://scrutinizer-ci.com/g/caxy/php-htmldiff/?branch=master) |
2 | | -[](https://scrutinizer-ci.com/g/caxy/php-htmldiff/build-status/master) |
3 | | -[](https://scrutinizer-ci.com/g/caxy/php-htmldiff/?branch=master) |
4 | | -[](https://packagist.org/packages/caxy/php-htmldiff) |
5 | | -[](http://isitmaintained.com/project/caxy/php-htmldiff "Average time to resolve an issue") |
6 | | -[](http://isitmaintained.com/project/caxy/php-htmldiff "Percentage of issues still open") |
7 | | - |
8 | 1 | php-htmldiff |
9 | | -======= |
10 | | -*A library for comparing two HTML files/snippets and highlighting the differences using simple HTML.* |
11 | | - |
12 | | -This HTML Diff implementation is a PHP port of the ruby implementation found at https://github.com/myobie/htmldiff. |
| 2 | +============ |
13 | 3 |
|
14 | | -This is also available in C# at https://github.com/Rohland/htmldiff.net. |
| 4 | +[][badge_score] |
| 5 | +[][badge_status] |
| 6 | +[][badge_coverage] |
| 7 | +[][badge_packagist] |
| 8 | +[][badge_resolve] |
| 9 | +[][badge_issues] |
15 | 10 |
|
16 | | -License |
17 | | -------- |
18 | | -php-htmldiff is available under [GNU General Public License, version 2] (http://www.gnu.org/licenses/gpl-2.0.html). |
| 11 | +php-htmldiff is a library for comparing two HTML files/snippets and highlighting the differences using simple HTML. |
19 | 12 |
|
20 | | -Differences from rashid2538/php-htmldiff |
21 | | -======================================== |
22 | | -## Code Styling and Clean-up |
23 | | -* Added namespaces, split up classes to their own files, some code styling changes |
| 13 | +This HTML Diff implementation was forked from [rashid2538/php-htmldiff][upstream] and has been modified with new features, |
| 14 | +bug fixes, and enhancements to the original code. |
24 | 15 |
|
25 | | -## Enhancements |
26 | | -* Allow the specialCaseOpeningTags and specialCaseClosingTags properties to be modified by passing an array into the constructor or using set/add/remove functions |
27 | | -* Updated the demo to accept input and diff via AJAX |
28 | | -* Added static properties for the default config variables |
| 16 | +For more information on these modifications, read the [differences from rashid2538/php-htmldiff][differences] or view the [CHANGELOG][changelog]. |
29 | 17 |
|
30 | | -## Bug Fixes |
31 | | -* Fixed an index out of range bug (may have been fixed on the original repo since): https://github.com/caxy/php-htmldiff/commit/c9ba1fab6777cd47427477f8d747293bb01ef1e8 |
32 | | -* Check for empty oldText or newText before processing del or ins in processReplaceOperation function |
| 18 | +## Installation |
33 | 19 |
|
34 | | -## New Features |
35 | | -#### Isolated Diffing of certain HTML elements |
36 | | -This is the one of the largest changes from the original repository. |
| 20 | +The recommended way to install php-htmldiff is through [Composer][composer]. |
| 21 | +Require the [caxy/php-htmldiff][badge_packagist] package by running following command: |
37 | 22 |
|
38 | | -See the release notes for tag 0.0.6 for more information: https://github.com/caxy/php-htmldiff/releases/tag/0.0.6 |
| 23 | +```sh |
| 24 | +composer require caxy/php-htmldiff |
| 25 | +``` |
39 | 26 |
|
40 | | -#### List Diffing |
41 | | -This is the latest new feature (as of last week-ish), and may need some tweaks still. It is similar to the Isolated Diffing feature, but specifically for HTML lists. |
| 27 | +This will resolve the latest stable version. |
42 | 28 |
|
43 | | -More information is to come on this, and there will definitely be some tweaks and configuration options added for this feature. Currently there is no easy way to enable/disable the feature, so if you're having issues with it I suggest using the 0.0.6 or earlier release. |
| 29 | +Otherwise, install the library and setup the autoloader yourself. |
44 | 30 |
|
45 | | -#### New option to group together diffed words by not matching on whitespace-only. Option is enabled by default. |
46 | | -This was a specific requirement for an application we use this library for. The original library would replace single words at a time, but enabling this feature will group replacements instead. See example below. |
| 31 | +### Working with Symfony |
47 | 32 |
|
48 | | -Old Text |
49 | | -> testing some text here and there |
| 33 | +If you are using Symfony, you can use the [caxy/HtmlDiffBundle][htmldiffbundle] to make life easy! |
50 | 34 |
|
51 | | -New Text |
52 | | -> testing other words here and there |
| 35 | +## Usage |
53 | 36 |
|
54 | | -With $groupDiffs = false (original functionality) |
55 | | -> testing <del>some</del><ins>other</ins> <del>text</del><ins>words</ins> here and there |
| 37 | +(WIP) |
56 | 38 |
|
57 | | -With $groupDiffs = true (new feature) |
58 | | -> testing <del>some text</del><ins>other words</ins> here and there |
| 39 | +```php |
| 40 | +use Caxy\HtmlDiff\HtmlDiff; |
59 | 41 |
|
60 | | -#### Change diffing to strike through entire words/numbers if they contain periods or commas within the word |
61 | | -This change introduced a new property `$specialCaseChars`, which defaults to the following characters: `.` `,` `(` `)` `'` |
| 42 | +$htmlDiff = new HtmlDiff($oldHtml, $newHtml); |
| 43 | +$content = $htmlDiff->build(); |
| 44 | +``` |
62 | 45 |
|
63 | | -This feature can be "disabled" by simply setting the $specialCaseChars to an empty array i.e. `$diff->setSpecialCaseChars(array())` |
| 46 | +## Configuration |
64 | 47 |
|
65 | | -In the original library, special characters are treated as their own "words" even if they are in the middle of a word. This causes weird things to happen when diffing numbers that have a comma or a period in the middle of the number. |
| 48 | +WIP |
66 | 49 |
|
67 | | -For example, diffing `10,000.50` against `11,100.75` gives you: |
| 50 | +## Contributing |
68 | 51 |
|
69 | | -Original Functionality: |
70 | | -> <del class="diffmod">10</del><ins class="diffmod">11</ins>,<del class="diffmod">000</del><ins class="diffmod">100</ins>.<del class="diffmod">50</del><ins class="diffmod">75</ins> |
| 52 | +See [CONTRIBUTING][contributing] file. |
71 | 53 |
|
72 | | -This is very difficult to read, so the new feature allows you to add `.` and `,` to the $specialCaseChars array in order to get output that looks like: |
73 | | -> <del class="diffmod">10,000.50</del><ins class="diffmod">11,100.75</ins> |
| 54 | +## Contributor Code of Conduct |
74 | 55 |
|
75 | | -Note: It will *not* treat the specialCaseChars as part of the word if it is at the beginning or end of the word, so normal periods or commas at the end of words will still be diffed like the original. |
| 56 | +Please note that this project is released with a [Contributor Code of |
| 57 | +Conduct][contributor_covenant]. By participating in this project |
| 58 | +you agree to abide by its terms. See [CODE_OF_CONDUCT][code_of_conduct] file. |
76 | 59 |
|
77 | | -#### Added option to insert a space between `<del>` and `<ins>` tags. Disabled by default. |
78 | | -This was a requirement for one our applications that uses this library. |
| 60 | +## Credits |
79 | 61 |
|
80 | | -New property `$insertSpaceInReplace` was added, and setting it to true will simply add a space between the `<del>` and `<ins>` tags in replace operations, which was requested for easier reading. |
| 62 | +* [rashid2538][] for the port to PHP and the base for our project: [rashid2538/php-htmldiff][upstream] |
| 63 | +* [willdurand][] for an excellent post on [open sourcing libraries][]. |
| 64 | +Much of this documentation is based off of the examples in the post. |
81 | 65 |
|
82 | | -Enable it by calling `$diff->setInsertSpaceInReplace(true);` |
| 66 | +Did we miss anyone? If we did, let us know or put in a pull request! |
83 | 67 |
|
84 | | -Original Functionality |
85 | | -> <del>Old</del><ins>New</ins> |
| 68 | +## License |
86 | 69 |
|
87 | | -New Functionality |
88 | | -> <del>Old</del> <ins>New</ins> |
| 70 | +php-htmldiff is available under [GNU General Public License, version 2][gnu]. See the [LICENSE][license] file for details. |
89 | 71 |
|
90 | | -## Upcoming Features (someday) |
91 | | -* Table Diffing (similar to the list diffing updates) - this feature was started a while back, but put on hold. |
| 72 | +[badge_score]: https://scrutinizer-ci.com/g/caxy/php-htmldiff/?branch=master |
| 73 | +[badge_status]: https://scrutinizer-ci.com/g/caxy/php-htmldiff/build-status/master |
| 74 | +[badge_coverage]: https://scrutinizer-ci.com/g/caxy/php-htmldiff/?branch=master |
| 75 | +[badge_packagist]: https://packagist.org/packages/caxy/php-htmldiff |
| 76 | +[badge_resolve]: http://isitmaintained.com/project/caxy/php-htmldiff "Average time to resolve an issue" |
| 77 | +[badge_issues]: http://isitmaintained.com/project/caxy/php-htmldiff "Percentage of issues still open" |
| 78 | +[upstream]: https://github.com/rashid2538/php-htmldiff |
| 79 | +[htmldiffbundle]: https://github.com/caxy/HtmlDiffBundle |
| 80 | +[differences]: https://github.com/caxy/php-htmldiff/blob/master/doc/differences.rst |
| 81 | +[changelog]: https://github.com/caxy/php-htmldiff/blob/master/CHANGELOG.md |
| 82 | +[contributing]: https://github.com/caxy/php-htmldiff/blob/master/CONTRIBUTING.md |
| 83 | +[gnu]: http://www.gnu.org/licenses/gpl-2.0.html |
| 84 | +[license]: https://github.com/caxy/php-htmldiff/blob/master/LICENSE |
| 85 | +[code_of_conduct]: https://github.com/caxy/php-htmldiff/blob/master/CODE_OF_CONDUCT.md |
| 86 | +[composer]: http://getcomposer.org/ |
| 87 | +[contributor_covenant]: http://contributor-covenant.org/ |
| 88 | +[rashid2538]: https://github.com/rashid2538 |
| 89 | +[willdurand]: https://github.com/willdurand |
| 90 | +[open sourcing libraries]: http://williamdurand.fr/2013/07/04/on-open-sourcing-libraries/ |
0 commit comments