jfcherng / php-diff

A comprehensive library for generating differences between two strings in multiple formats (unified, side by side HTML etc).
https://packagist.org/packages/jfcherng/php-diff
BSD 3-Clause "New" or "Revised" License
407 stars 50 forks source link

Long text diff #86

Open kouroshfar opened 1 month ago

kouroshfar commented 1 month ago

Hi and thanks for your great library. I have a problem with long texts comparisons. I have these configs:

// the Diff class options
$differOptions = [
    'context' => Differ::CONTEXT_ALL,
    'ignoreCase' => false,
    'ignoreLineEnding' => false,
    'ignoreWhitespace' => false,
    'lengthLimit' => 200000,
    'fullContextIfIdentical' => false,
];
// the renderer class options
$rendererOptions = [
    'detailLevel' => 'word',
    'language' => 'eng',
    'lineNumbers' => false,
    'separateBlock' => false,
    'showHeader' => false,
    'spacesToNbsp' => false,
    'tabSize' => 4,
    'mergeThreshold' => 0.8,
    'cliColorization' => RendererConstant::CLI_COLOR_AUTO,
    'outputTagAsString' => false,
    'jsonEncodeFlags' => \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE,
    'wordGlues' => [' ', '-'],
    'resultForIdenticals' => null,
    'wrapperClasses' => ['diff-wrapper '],
];
$rendererName = 'Combined';
$result = DiffHelper::calculate($old, $new, $rendererName, $differOptions, $rendererOptions);

And I wanted to compare these 2 texts:

New.txt Old.txt

When the context set to Differ::CONTEXT_ALL it will not show the full text on the result. I need to see the removed sentences and added sentences and also modified sentences too.

I need to have a result like this. Can you help me? I've attached my result at the end of the issue too.

screenshot screenshot

jfcherng commented 1 month ago

When the context set to Differ::CONTEXT_ALL it will not show the full text on the result.

I don't notice anything unexpected with your options and sources.

Snipaste_2024-07-19_22-18-43

kouroshfar commented 1 month ago

Thanks for your reply. If you see my latest uploaded image, i have the result same as you. But on the left column as you can see i have many sentences that they should show on the right column as a removed text (as we don't have them more), but we can't see.

screen

jfcherng commented 1 month ago

But on the left column as you can see i have many sentences that they should show on the right column as a removed text (as we don't have them more), but we can't see.

That's not what you provided in old.txt / new.txt.

To save our time, use the demo example to provide results and point out what the issue is. I won't try anything other than the demo example.