logo svelte /diff v0.4.3

Cleanup Modes

Cleanup options apply only to the default diffMode="character". Word and line modes skip both passes and report zero cleanup time. Granularity chooses comparison units; cleanup reorganizes character edits. See Diff Modes.

The core algorithm finds a valid sequence of edits. Cleanup passes reorganize that sequence without changing the final text.

Semantic cleanup

<SvelteDiff {originalText} {modifiedText} cleanupSemantic />
<SvelteDiff {originalText} {modifiedText} cleanupSemantic />

Semantic cleanup shifts edit boundaries toward natural-looking word and phrase boundaries. Use it for prose, review screens, changelogs, and other output read by people.

It may produce a slightly larger edit than the mathematically smallest diff if that edit is easier to understand.

Efficiency cleanup

<SvelteDiff
    {originalText}
    {modifiedText}
    cleanupEfficiency={4}
/>
<SvelteDiff
    {originalText}
    {modifiedText}
    cleanupEfficiency={4}
/>

Efficiency cleanup removes operationally trivial equalities. The number becomes the algorithm’s edit-cost setting. 4 is the component default.

Higher values make small equal regions more likely to be absorbed into surrounding edits. Lower values preserve more fine-grained equalities.

Raw output

Disable both cleanup paths when exact algorithm output matters:

<SvelteDiff
    {originalText}
    {modifiedText}
    cleanupSemantic={false}
    cleanupEfficiency={0}
/>
<SvelteDiff
    {originalText}
    {modifiedText}
    cleanupSemantic={false}
    cleanupEfficiency={0}
/>

Character-mode precedence

Semantic cleanup wins when enabled. The component does not run semantic and efficiency cleanup in sequence.

ConfigurationCleanup pass
cleanupSemantic={true}semantic
cleanupSemantic={false}, cleanupEfficiency={4}efficiency
cleanupSemantic={false}, cleanupEfficiency={0}none

Choosing character-mode cleanup

  • Use semantic for prose and human review.
  • Use efficiency for compact technical diffs and a balanced default.
  • Use raw when consuming the rendered segmentation as a debugging aid or comparing it with another diff implementation.

Open the cleanup modes example to see all three render the same input side by side.