PHP-FineDiff icon indicating copy to clipboard operation
PHP-FineDiff copied to clipboard

WISHLIST:Override <del> and <ins> html tags

Open maysara opened this issue 11 years ago • 2 comments

It would be great if the <del> </del> and <ins> </ins> tags can be over ridden; it would also be nice then if the function name would change to something like renderDiffToMarkup.

This is very useful if one wants to create entries that include styling within the tag and not in css , or even use it for non html , such as generating svg or other XML or non XML markup documents.

maysara avatar Dec 20 '13 23:12 maysara

This is already an option. Quoting from README.

It is also possible to provide a custom renderer through a user supplied callback function/method:

FineDiff::renderFromOpcodes($from, $opcodes, $callback);

For example, you could use something like this:

$opcodes = FineDiff::getDiffOpcodes($from_text, $to_text);
$callback = function ($opcode, $from, $from_offset, $from_len) {
    $fragment = substr($from, $from_offset, $from_len);
    if ($opcode == 'd') {
        // do something with removed fragment
    }
    elseif ($opcode == 'i') {
        // do something with inserted fragment
    }
    else {
        // do something with copied fragment
    }
};
FineDiff::renderFromOpcodes($from_text, $opcodes, $callback);

toxalot avatar Apr 02 '14 09:04 toxalot

https://gist.github.com/asleepwalker/fb46883e88a3a44af786 Maybe it will be helpful for someone.

asleepwalker avatar Jul 21 '14 16:07 asleepwalker