forked from AutoHotkey/AutoHotkeyDocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_chm.ahk
128 lines (110 loc) · 3.32 KB
/
compile_chm.ahk
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#NoEnv
SetBatchLines, -1
SetWorkingDir %A_ScriptDir%
if (A_PtrSize = 8) {
try
RunWait "%A_AhkPath%\..\AutoHotkeyU32.exe" "%A_ScriptFullPath%"
catch
MsgBox 16,, This script must be run with AutoHotkey 32-bit, due to use of the ScriptControl COM component.
ExitApp
}
; Change this path if the loop below doesn't find your hhc.exe,
; or leave it as-is if hhc.exe is somewhere in %PATH%.
hhc := "hhc.exe"
; Try to find hhc.exe, since it's not in %PATH% by default.
for i, env_var in ["ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"]
{
EnvGet Programs, %env_var%
if (Programs && FileExist(checking := Programs "\HTML Help Workshop\hhc.exe"))
{
hhc := checking
break
}
}
FileRead IndexJS, docs\static\source\data_index.js
Overwrite("Index.hhk", INDEX_CreateHHK(IndexJS))
; Use old sidebar:
; FileDelete, docs\static\content.js
; FileRead TocJS, docs\static\source\data_toc.js
; Overwrite("Table of Contents.hhc", TOC_CreateHHC(TocJS))
; IniWrite, Table of Contents.hhc, Project.hhp, OPTIONS, Contents file
; IniWrite, % "AutoHotkey Help,Table of Contents.hhc,Index.hhk,docs\AutoHotkey.htm,docs\AutoHotkey.htm,,,,,0x73520,,0x10200e,[200,0,1080,700],0,,,,0,,0", Project.hhp, WINDOWS, Contents
; Compile AutoHotkey.chm.
RunWait %hhc% "%A_ScriptDir%\Project.hhp"
Overwrite(File, Text)
{
FileOpen(File, "w").Write(Text)
}
TOC_CreateHHC(data)
{
ComObjError(false)
sc := ComObjCreate("ScriptControl")
sc.Language := "JScript"
sc.ExecuteStatement(data)
output =
( LTrim
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<body>
<object type="text/site properties">
<param name="Window Styles" value="0x800025">
<param name="ImageType" value="Folder">
</object>
)
output .= TOC_CreateListCallback("", sc.Eval("tocData"))
output .= "`n</body>`n</html>`n"
return % output
}
TOC_CreateListCallback(byref output, data)
{
output .= "`n<ul>`n"
Loop % data.length
{
i := A_Index - 1
output .= "<li><object type=""text/sitemap"">"
if data[i][0]
{
Transform, param_name, HTML, % data[i][0]
output .= "<param name=""Name"" value=""" param_name """>"
}
if data[i][1]
{
Transform, param_local, HTML, % data[i][1]
output .= "<param name=""Local"" value=""docs/" param_local """>"
}
output .= "</object>"
if data[i][2]
output .= TOC_CreateListCallback(output, data[i][2])
output .= "`n"
}
output .= "</ul>"
return % output
}
INDEX_CreateHHK(data)
{
ComObjError(false)
sc := ComObjCreate("ScriptControl")
sc.Language := "JScript"
sc.ExecuteStatement(data)
data := sc.Eval("indexData")
output =
( LTrim
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<body>
)
output .= "`n<ul>`n"
Loop % data.length
{
i := A_Index - 1
output .= "<li><object type=""text/sitemap"">"
Transform, param_name, HTML, % data[i][0]
output .= "<param name=""Name"" value=""" param_name """>"
Transform, param_local, HTML, % data[i][1]
output .= "<param name=""Local"" value=""docs/" param_local """>"
output .= "</object>`n"
}
output .= "</ul>"
output .= "`n</body>`n</html>`n"
return % output
}