@createiq/htmldiff 1.0.5-beta.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/HtmlDiff.cjs +5 -973
- package/dist/HtmlDiff.cjs.map +1 -1
- package/dist/HtmlDiff.d.cts +2 -16
- package/dist/HtmlDiff.d.mts +2 -16
- package/dist/HtmlDiff.mjs +5 -973
- package/dist/HtmlDiff.mjs.map +1 -1
- package/package.json +3 -3
- package/src/HtmlDiff.ts +5 -51
- package/test/HtmlDiff.spec.ts +1 -1
- package/.claude/settings.local.json +0 -15
- package/src/TableDiff.ts +0 -1428
- package/test/HtmlDiff.tables.matrix.spec.ts +0 -327
- package/test/HtmlDiff.tables.spec.ts +0 -1458
- package/test/TableDiff.bench.ts +0 -244
package/src/HtmlDiff.ts
CHANGED
|
@@ -2,7 +2,6 @@ import Action from './Action'
|
|
|
2
2
|
import Match from './Match'
|
|
3
3
|
import MatchFinder from './MatchFinder'
|
|
4
4
|
import Operation from './Operation'
|
|
5
|
-
import { preprocessTables, restoreTablePlaceholders } from './TableDiff'
|
|
6
5
|
import Utils from './Utils'
|
|
7
6
|
import WordSplitter from './WordSplitter'
|
|
8
7
|
|
|
@@ -65,21 +64,9 @@ export default class HtmlDiff {
|
|
|
65
64
|
'span',
|
|
66
65
|
])
|
|
67
66
|
|
|
68
|
-
/**
|
|
69
|
-
* Hard cap on nested `HtmlDiff.execute` calls (table preprocessing
|
|
70
|
-
* recurses through `diffCell` for cell content). Each level allocates
|
|
71
|
-
* fresh DP matrices and word arrays; without a guard a maliciously
|
|
72
|
-
* nested table-in-cell-in-table-in-cell input could blow stack and
|
|
73
|
-
* memory. Set high enough to comfortably handle real legal documents
|
|
74
|
-
* (tables nested 2-3 deep at most), low enough to short-circuit
|
|
75
|
-
* pathological input.
|
|
76
|
-
*/
|
|
77
|
-
private static MaxTablePreprocessDepth = 8
|
|
78
|
-
|
|
79
67
|
private content: string[] = []
|
|
80
68
|
private newText: string
|
|
81
69
|
private oldText: string
|
|
82
|
-
private readonly tablePreprocessDepth: number
|
|
83
70
|
|
|
84
71
|
private specialTagDiffStack: string[] = []
|
|
85
72
|
private newWords: string[] = []
|
|
@@ -147,18 +134,14 @@ export default class HtmlDiff {
|
|
|
147
134
|
* Initializes a new instance of the class.
|
|
148
135
|
* @param oldText The old text.
|
|
149
136
|
* @param newText The new text.
|
|
150
|
-
* @param tablePreprocessDepth Internal: nested-call depth for table
|
|
151
|
-
* preprocessing. Callers should leave at default (0); the recursive
|
|
152
|
-
* `diffCell` callback in TableDiff bumps it.
|
|
153
137
|
*/
|
|
154
|
-
constructor(oldText: string, newText: string
|
|
138
|
+
constructor(oldText: string, newText: string) {
|
|
155
139
|
this.oldText = oldText
|
|
156
140
|
this.newText = newText
|
|
157
|
-
this.tablePreprocessDepth = tablePreprocessDepth
|
|
158
141
|
}
|
|
159
142
|
|
|
160
|
-
static execute(oldText: string, newText: string
|
|
161
|
-
return new HtmlDiff(oldText, newText
|
|
143
|
+
static execute(oldText: string, newText: string) {
|
|
144
|
+
return new HtmlDiff(oldText, newText).build()
|
|
162
145
|
}
|
|
163
146
|
|
|
164
147
|
/**
|
|
@@ -171,34 +154,6 @@ export default class HtmlDiff {
|
|
|
171
154
|
return this.newText
|
|
172
155
|
}
|
|
173
156
|
|
|
174
|
-
// Table preprocessing: when both sides have matching `<table>` structures,
|
|
175
|
-
// diff cells positionally so cross-cell content shifts produce one
|
|
176
|
-
// independent del/ins per cell rather than cell-misaligned output.
|
|
177
|
-
// Recursion guarded by MaxTablePreprocessDepth to bound work on
|
|
178
|
-
// deeply-nested table-in-cell-in-table inputs. Caller-configured
|
|
179
|
-
// settings (block expressions, accuracy thresholds) are propagated to
|
|
180
|
-
// the recursive cell diff so cell-level output is consistent with the
|
|
181
|
-
// top-level configuration.
|
|
182
|
-
const blockExpressions = this.blockExpressions
|
|
183
|
-
const repeatingWordsAccuracy = this.repeatingWordsAccuracy
|
|
184
|
-
const orphanMatchThreshold = this.orphanMatchThreshold
|
|
185
|
-
const ignoreWhitespaceDifferences = this.ignoreWhitespaceDifferences
|
|
186
|
-
const tablePreprocess =
|
|
187
|
-
this.tablePreprocessDepth >= HtmlDiff.MaxTablePreprocessDepth
|
|
188
|
-
? null
|
|
189
|
-
: preprocessTables(this.oldText, this.newText, (oldCell, newCell) => {
|
|
190
|
-
const inner = new HtmlDiff(oldCell, newCell, this.tablePreprocessDepth + 1)
|
|
191
|
-
for (const expr of blockExpressions) inner.addBlockExpression(expr)
|
|
192
|
-
inner.repeatingWordsAccuracy = repeatingWordsAccuracy
|
|
193
|
-
inner.orphanMatchThreshold = orphanMatchThreshold
|
|
194
|
-
inner.ignoreWhitespaceDifferences = ignoreWhitespaceDifferences
|
|
195
|
-
return inner.build()
|
|
196
|
-
})
|
|
197
|
-
if (tablePreprocess) {
|
|
198
|
-
this.oldText = tablePreprocess.modifiedOld
|
|
199
|
-
this.newText = tablePreprocess.modifiedNew
|
|
200
|
-
}
|
|
201
|
-
|
|
202
157
|
this.splitInputsToWords()
|
|
203
158
|
this.buildContentProjections()
|
|
204
159
|
|
|
@@ -215,8 +170,7 @@ export default class HtmlDiff {
|
|
|
215
170
|
this.performOperation(op)
|
|
216
171
|
}
|
|
217
172
|
|
|
218
|
-
|
|
219
|
-
return tablePreprocess ? restoreTablePlaceholders(result, tablePreprocess.placeholderToDiff) : result
|
|
173
|
+
return this.content.join('')
|
|
220
174
|
}
|
|
221
175
|
|
|
222
176
|
/**
|
|
@@ -563,7 +517,7 @@ export default class HtmlDiff {
|
|
|
563
517
|
const openingAndClosingTagsMatch =
|
|
564
518
|
!!openingTag && Utils.getTagName(openingTag) === Utils.getTagName(words[tagIndexToCompare])
|
|
565
519
|
|
|
566
|
-
if (openingTag && openingAndClosingTagsMatch) {
|
|
520
|
+
if (!!openingTag && openingAndClosingTagsMatch) {
|
|
567
521
|
specialCaseTagInjection = '</ins>'
|
|
568
522
|
specialCaseTagInjectionIsBefore = true
|
|
569
523
|
}
|
package/test/HtmlDiff.spec.ts
CHANGED
|
@@ -51,7 +51,7 @@ describe('HtmlDiff', () => {
|
|
|
51
51
|
[
|
|
52
52
|
'<table><tr><td>col1</td><td>col2</td></tr><tr><td>Data 1</td><td>Data 2</td></tr></table>',
|
|
53
53
|
'<table><tr><td>col1</td><td>col2</td></tr></table>',
|
|
54
|
-
"<table><tr><td>col1</td><td>col2</td></tr><tr
|
|
54
|
+
"<table><tr><td>col1</td><td>col2</td></tr><tr><td><del class='diffdel'>Data 1</del></td><td><del class='diffdel'>Data 2</del></td></tr></table>",
|
|
55
55
|
],
|
|
56
56
|
[
|
|
57
57
|
'text',
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"Bash(diff -u test/input1.html test/input2.html)",
|
|
5
|
-
"Bash(npm test -- test/Bug.spec.tsx)",
|
|
6
|
-
"Bash(timeout 30s npm run test:ci -- test/Bug.spec.tsx)",
|
|
7
|
-
"Bash(npm run build)",
|
|
8
|
-
"Bash(timeout 10s npm run test:ci -- test/Bug.spec.tsx)",
|
|
9
|
-
"Bash(npm run lint)",
|
|
10
|
-
"Bash(npm run test:ci)",
|
|
11
|
-
"Bash(npm run bench:ci)"
|
|
12
|
-
],
|
|
13
|
-
"deny": []
|
|
14
|
-
}
|
|
15
|
-
}
|