Skip to content

Commit 3f123c6

Browse files
committed
fix: equal seq
1 parent aee5ef2 commit 3f123c6

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

packages/html-diff/src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,15 @@ export default class HtmlDiff {
114114
// no need to diff
115115
if (oldHtml === newHtml) {
116116
this.unifiedContent = oldHtml
117-
this.sideBySideContents = [oldHtml, newHtml]
117+
let equalSequence = 0
118+
const content = oldHtml.replace(
119+
/<([^\s/>]+)[^>]*>/g,
120+
(match: string, name: string) => {
121+
const tagNameLength = name.length + 1
122+
return `${match.slice(0, tagNameLength)} data-seq="${++equalSequence}"${match.slice(tagNameLength)}`
123+
},
124+
)
125+
this.sideBySideContents = [content, content]
118126
return
119127
}
120128

packages/html-diff/tests/__snapshots__/index.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ exports[`HtmlDiff > should work with equal 1`] = `
104104
105105
exports[`HtmlDiff > should work with equal 2`] = `
106106
[
107-
"<h1>hello world</h1>
108-
<p>你若安好,便是晴天</p>",
109-
"<h1>hello world</h1>
110-
<p>你若安好,便是晴天</p>",
107+
"<h1 data-seq="1">hello world</h1>
108+
<p data-seq="2">你若安好,便是晴天</p>",
109+
"<h1 data-seq="1">hello world</h1>
110+
<p data-seq="2">你若安好,便是晴天</p>",
111111
]
112112
`;
113113

0 commit comments

Comments
 (0)