Skip to content

Commit 65b436b

Browse files
committed
Update diff tool
1 parent ac41417 commit 65b436b

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/html-diff.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,42 @@ export class HtmlDiffClient {
1111

1212
const unifiedDiff = createTwoFilesPatch(lhsPath, rhsPath, lhs, rhs);
1313

14-
this.htmlOutput = Diff2Html.html(unifiedDiff, {
15-
drawFileList: true,
14+
const htmlOutput = Diff2Html.html(unifiedDiff, {
15+
drawFileList: false,
1616
outputFormat: "side-by-side",
1717
matching: "lines",
1818
});
19+
20+
// Step 4: Dynamically read CSS file
21+
const diff2htmlCss = fs.readFileSync(
22+
"./node_modules/diff2html/bundles/css/diff2html.min.css",
23+
"utf8"
24+
);
25+
26+
// Step 5: Embed CSS into the final HTML
27+
this.htmlOutput = `
28+
<!DOCTYPE html>
29+
<html>
30+
<head>
31+
<meta charset="UTF-8">
32+
<title>Diff View</title>
33+
<style>
34+
body {
35+
font-family: Arial, sans-serif;
36+
margin: 0;
37+
padding: 0;
38+
}
39+
.d2h-wrapper {
40+
font-size: 14px;
41+
}
42+
/* Inline CSS for diff2html */
43+
${diff2htmlCss}
44+
</style>
45+
</head>
46+
<body>
47+
${htmlOutput}
48+
</body>
49+
</html>`;
1950
}
2051

2152
writeOutput(outputPath: string) {

0 commit comments

Comments
 (0)