-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseDiff.bat
62 lines (54 loc) · 1.8 KB
/
parseDiff.bat
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
ECHO start parcing...
SET parent=%~dp0
:: CONSTANTS
SET sOpenFile=^</div^>^<button class="section"^>
SET sCloseFile=^</button^>^<div class="section-content"^>^<div^>
SET sOpenCodeBlock=^</div^>^<div^>
SET sOpenCodeLine=^<pre^>
SET sCloseCodeLine=^</pre^>
SET sOpenAddCodeLine=^<pre class="add"^>
SET sOpenRemoveCodeLine=^<pre class="remove"^>
:: open tag for main cotent
ECHO ^<main^>>>niceDiff-report.html
:: init code block
ECHO ^<div^>>> niceDiff-report.html
:: init file section
ECHO ^<div^>>> niceDiff-report.html
SETLOCAL enabledelayedexpansion
FOR /F "usebackq tokens=*" %%A IN ("%parent%/diff.txt") DO (
SET line1=%%A
SET line2=!line1:^<=^<!
SET line=!line2:^>=^>!
IF "!line:~0,10!"=="diff --git" (
rem close last code block in previous file
ECHO ^</div^>>> niceDiff-report.html
rem new file
ECHO !sOpenFile! >> niceDiff-report.html
) ELSE IF "!line:~0,5!"=="--- a" (
rem get file name
ECHO !line:~5!!sCloseFile! >> niceDiff-report.html
) ELSE IF "!line:~0,5!"=="+++ b" (
rem skip line
) ELSE IF "!line:~0,6!"=="index " (
rem skip line
) ELSE IF "!line:~0,3!"=="@@ " (
rem start diff block
ECHO !sOpenCodeBlock!!sOpenCodeLine!!line!!sCloseCodeLine! >> niceDiff-report.html
) ELSE IF "!line:~0,1!"=="-" (
rem start remove line
ECHO !sOpenRemoveCodeLine!!line:~1!!sCloseCodeLine! >> niceDiff-report.html
) ELSE IF "!line:~0,1!"=="+" (
rem start add line
ECHO !sOpenAddCodeLine!!line:~1!!sCloseCodeLine! >> niceDiff-report.html
) ELSE (
rem default add line
ECHO !sOpenCodeLine!!line!!sCloseCodeLine! >> niceDiff-report.html
)
)
:: close last code block
ECHO ^</div^>>> niceDiff-report.html
:: close file section
ECHO ^</div^>>> niceDiff-report.html
:: add bottom part of template
TYPE %parent%template_bottom_report.html>> niceDiff-report.html
ECHO complited