PHP-FineDiff
PHP-FineDiff copied to clipboard
WISHLIST:Override <del> and <ins> html tags
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.
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);
https://gist.github.com/asleepwalker/fb46883e88a3a44af786 Maybe it will be helpful for someone.