@@ -128,6 +128,70 @@ import type {
128
128
| onProcessing | ` function ` | - | Callback for timing and diff information |
129
129
| rendererClasses | ` object ` | - | CSS classes for diff highlighting |
130
130
131
+ ## Custom Rendering with Snippets
132
+
133
+ You can customize how the diff is rendered using Svelte snippets. This gives you full control over the HTML structure and styling of each diff part.
134
+
135
+ ``` svelte
136
+ <script lang="ts">
137
+ import SvelteDiffMatchPatch from '@humanspeak/svelte-diff-match-patch'
138
+
139
+ let originalText = $state(`I am the very model of a modern Major-General,
140
+ I've information vegetable, animal, and mineral,
141
+ I know the kings of England, and I quote the fights historical,
142
+ From Marathon to Waterloo, in order categorical.`)
143
+
144
+ let modifiedText = $state(`I am the very model of a cartoon individual,
145
+ My animation's comical, unusual, and whimsical,
146
+ I'm quite adept at funny gags, comedic theory I have read,
147
+ From wicked puns and stupid jokes to anvils that drop on your head.`)
148
+ </script>
149
+
150
+ <SvelteDiffMatchPatch {originalText} {modifiedText}>
151
+ {#snippet remove(text: string)}
152
+ <span class="diff-snippet-remove">{text}</span>
153
+ {/snippet}
154
+ {#snippet insert(text: string)}
155
+ <span class="diff-snippet-insert">{text}</span>
156
+ {/snippet}
157
+ {#snippet equal(text: string)}
158
+ <span class="diff-snippet-equal">{text}</span>
159
+ {/snippet}
160
+ {#snippet lineBreak()}
161
+ <br /><br />
162
+ {/snippet}
163
+ </SvelteDiffMatchPatch>
164
+
165
+ <style>
166
+ :global(.diff-snippet-remove) {
167
+ background-color: #ffd7d5;
168
+ text-decoration: line-through;
169
+ }
170
+ :global(.diff-snippet-insert) {
171
+ background-color: #d4ffd4;
172
+ }
173
+ </style>
174
+ ```
175
+
176
+ ### Available Snippets
177
+
178
+ | Snippet | Parameters | Description |
179
+ | --------- | ---------- | -------------------------------------------- |
180
+ | remove | ` text ` | Renders removed text (in originalText only) |
181
+ | insert | ` text ` | Renders inserted text (in modifiedText only) |
182
+ | equal | ` text ` | Renders unchanged text (in both texts) |
183
+ | lineBreak | - | Renders line breaks between diff sections |
184
+
185
+ You can use these snippets to:
186
+
187
+ - Customize the HTML structure of each diff part
188
+ - Apply custom styling to different types of changes
189
+ - Add additional elements or attributes
190
+ - Implement custom animations or transitions
191
+ - Add tooltips or other interactive elements
192
+
193
+ If you don't provide snippets, the component will use the default rendering with the ` rendererClasses ` prop.
194
+
131
195
## Events
132
196
133
197
The component emits a ` processing ` event with timing and diff information:
0 commit comments