-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff.py
More file actions
92 lines (76 loc) · 1.65 KB
/
Copy pathdiff.py
File metadata and controls
92 lines (76 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
import argparse
import subprocess
import tempfile
from pathlib import Path
CSS = """
<style>
body {
font-family: sans-serif;
line-height: 1.5;
}
ins,
ins * {
background: #d4f8d4;
text-decoration: none;
}
del,
del * {
background: #ffd6d6;
text-decoration: line-through;
}
</style>
"""
parser = argparse.ArgumentParser(
description="Erzeugt einen HTML-Diff zweier Markdown-Dateien."
)
parser.add_argument("old", help="Pfad zur alten Markdown-Datei")
parser.add_argument("new", help="Pfad zur neuen Markdown-Datei")
parser.add_argument("-o", "--output", default="diff.html", help="Ausgabedatei")
args = parser.parse_args()
with tempfile.TemporaryDirectory() as tmp:
tmp = Path(tmp)
old_html = tmp / "old.html"
new_html = tmp / "new.html"
subprocess.run(
[
"pandoc",
"-f",
"commonmark",
args.old,
"-o",
str(old_html),
],
check=True,
)
subprocess.run(
[
"pandoc",
"-f",
"commonmark",
args.new,
"-o",
str(new_html),
],
check=True,
)
result = subprocess.run(
[
"wdiff",
"-w",
"<ins>",
"-x",
"</ins>",
"-y",
"<del>",
"-z",
"</del>",
str(new_html),
str(old_html),
],
capture_output=True,
text=True,
)
html = CSS + result.stdout
Path(args.output).write_text(html, encoding="utf-8")
print(f"Diff erfolgreich erstellt: {args.output}")