Skip to content

wikimedia/wikimedia-fundraising-FineDiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FineDiff

Originally written by Raymond Hill (https://github.com/gorhill/PHP-FineDiff) FineDiff has been tweaked to bring it up to date with the modern world. That means documented, nicely formatted, tested code that can be easily extended.

Build Status

Installation

Composer

The preferred way of using FineDiff is through Composer.

Add the following to your composer.json file:

{
    "require": {
        "cogpowered/finediff": "0.0.*"
    }
}

Usage

Render HTML

Render as HTML the difference between two strings:

$diff = new cogpowered\FineDiff\Diff;
echo $diff->render('string one', 'string two');

This would then output:

string <ins>tw</ins>o<del>ne</del>

You could change the granularity to cogpowered\FineDiff\Granularity\Word so the output is:

string <del>one</del><ins>two</ins>

You do this by passing it into the Diff constructor:

$granularity = new cogpowered\FineDiff\Granularity\Word;
$diff        = new cogpowered\FineDiff\Diff($granularity);

Grab opcode instructions

Opcode instructions are what tell FineDiff how to change one string into another.

$diff = new cogpowered\FineDiff\Diff;
echo $diff->getOpcodes('string one', 'string two');

This would then output:

c7d3i3:two

Render text using the opcodes:

$render = new cogpowered\FineDiff\Render\Text;
echo $render->process('string one', 'c7d3i3:two');

Would output:

string two

Same with HTML:

$render = new cogpowered\FineDiff\Render\Html;
echo $render->process('string one', 'c7d3i3:two');

License

Copyright (c) 2011 Raymond Hill (http://raymondhill.net/blog/?p=441)
Copyright (c) 2013 Rob Crowe (http://cogpowered.com)

Licensed under The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Github mirror of "wikimedia/fundraising/FineDiff" - our actual code is hosted with Gerrit (please see https://www.mediawiki.org/wiki/Developer_access for contributing

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages