6324
|
1 |
(* Title: Pure/Thy/HTML.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
|
4 |
|
6338
|
5 |
HTML presentation primitives.
|
6324
|
6 |
*)
|
|
7 |
|
|
8 |
signature HTML =
|
|
9 |
sig
|
|
10 |
val output: string -> string
|
|
11 |
val output_width: string -> string * real
|
|
12 |
type text (* = string *)
|
|
13 |
val plain: string -> text
|
|
14 |
val name: string -> text
|
|
15 |
val keyword: string -> text
|
|
16 |
val file_name: string -> text
|
6649
|
17 |
val file_path: Url.T -> text
|
6324
|
18 |
val href_name: string -> text -> text
|
6649
|
19 |
val href_path: Url.T -> text -> text
|
6376
|
20 |
val href_opt_name: string option -> text -> text
|
6649
|
21 |
val href_opt_path: Url.T option -> text -> text
|
6376
|
22 |
val para: text -> text
|
6324
|
23 |
val preform: text -> text
|
|
24 |
val verbatim: string -> text
|
6649
|
25 |
val begin_index: Url.T * string -> Url.T * string -> Url.T option -> Url.T -> text
|
6338
|
26 |
val end_index: text
|
6649
|
27 |
val applet_pages: string -> Url.T -> Url.T * string -> bool -> (string * string) list
|
|
28 |
val theory_entry: Url.T * string -> text
|
|
29 |
val session_entries: (Url.T * string) list -> text
|
6324
|
30 |
val source: (string, 'a) Source.source -> text
|
6649
|
31 |
val begin_theory: Url.T * string -> string -> (Url.T option * string) list ->
|
7408
|
32 |
(Url.T option * Url.T * bool option) list -> text -> text
|
6324
|
33 |
val end_theory: text
|
6649
|
34 |
val ml_file: Url.T -> string -> text
|
7572
|
35 |
val result: string -> string -> thm -> text
|
|
36 |
val results: string -> string -> thm list -> text
|
6324
|
37 |
val theorem: string -> thm -> text
|
7408
|
38 |
val theorems: string -> thm list -> text
|
6324
|
39 |
val section: string -> text
|
7634
|
40 |
val subsection: string -> text
|
|
41 |
val subsubsection: string -> text
|
6324
|
42 |
val setup: (theory -> theory) list
|
|
43 |
end;
|
|
44 |
|
|
45 |
structure HTML: HTML =
|
|
46 |
struct
|
|
47 |
|
|
48 |
|
|
49 |
(** HTML print modes **)
|
|
50 |
|
|
51 |
(* mode *)
|
|
52 |
|
|
53 |
val htmlN = "HTML";
|
|
54 |
fun html_mode f x = setmp print_mode [htmlN] f x;
|
|
55 |
|
|
56 |
|
|
57 |
(* symbol output *)
|
|
58 |
|
6338
|
59 |
local
|
|
60 |
val escape = fn "<" => "<" | ">" => ">" | "&" => "&" | c => c;
|
6324
|
61 |
|
6338
|
62 |
val output_sym =
|
|
63 |
fn "\\<not>" => (1.0, "¬")
|
|
64 |
| "\\<hyphen>" => (1.0, "­")
|
|
65 |
| "\\<cdot>" => (1.0, "·")
|
|
66 |
| "\\<times>" => (1.0, "×")
|
|
67 |
| "\\<copyright>" => (1.0, "©")
|
|
68 |
| "\\<mu>" => (1.0, "µ")
|
|
69 |
| s => (real (size s), implode (map escape (explode s)));
|
6324
|
70 |
|
6338
|
71 |
fun add_sym (width, (w: real, s)) = (width + w, s);
|
|
72 |
in
|
6324
|
73 |
|
6338
|
74 |
fun output_width str =
|
|
75 |
if not (exists_string (equal "<" orf equal ">" orf equal "&") str) then (str, real (size str))
|
|
76 |
else
|
|
77 |
let val (width, syms) = foldl_map add_sym (0.0, map output_sym (Symbol.explode str))
|
|
78 |
in (implode syms, width) end;
|
|
79 |
|
|
80 |
val output = #1 o output_width;
|
|
81 |
val output_symbols = map (#2 o output_sym);
|
|
82 |
|
|
83 |
end;
|
|
84 |
|
6324
|
85 |
|
|
86 |
val _ = Symbol.add_mode htmlN output_width;
|
|
87 |
|
|
88 |
|
|
89 |
(* token translations *)
|
|
90 |
|
6347
|
91 |
fun color col =
|
|
92 |
apfst (enclose ("<font color=" ^ quote col ^ ">") "</font>") o output_width;
|
6324
|
93 |
|
|
94 |
val html_trans =
|
|
95 |
[("class", color "red"),
|
|
96 |
("tfree", color "purple"),
|
|
97 |
("tvar", color "purple"),
|
|
98 |
("free", color "blue"),
|
|
99 |
("bound", color "green"),
|
|
100 |
("var", color "blue"),
|
|
101 |
("xnum", color "yellow"),
|
|
102 |
("xstr", color "brown")];
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
(** HTML markup **)
|
|
107 |
|
|
108 |
type text = string;
|
|
109 |
|
|
110 |
|
|
111 |
(* atoms *)
|
|
112 |
|
|
113 |
val plain = output;
|
|
114 |
fun name s = "<i>" ^ output s ^ "</i>";
|
|
115 |
fun keyword s = "<b>" ^ output s ^ "</b>";
|
|
116 |
fun file_name s = "<tt>" ^ output s ^ "</tt>";
|
6649
|
117 |
val file_path = file_name o Url.pack;
|
6324
|
118 |
|
|
119 |
|
|
120 |
(* misc *)
|
|
121 |
|
|
122 |
fun href_name s txt = "<a href=" ^ quote s ^ ">" ^ txt ^ "</a>";
|
6649
|
123 |
fun href_path path txt = href_name (Url.pack path) txt;
|
6376
|
124 |
|
|
125 |
fun href_opt_name None txt = txt
|
|
126 |
| href_opt_name (Some s) txt = href_name s txt;
|
|
127 |
|
|
128 |
fun href_opt_path None txt = txt
|
|
129 |
| href_opt_path (Some p) txt = href_path p txt;
|
|
130 |
|
|
131 |
fun para txt = "\n<p>\n" ^ txt ^ "\n</p>\n";
|
6324
|
132 |
fun preform txt = "<pre>" ^ txt ^ "</pre>";
|
|
133 |
val verbatim = preform o output;
|
|
134 |
|
|
135 |
|
|
136 |
(* document *)
|
|
137 |
|
|
138 |
fun begin_document title =
|
6405
|
139 |
"<html>\n\
|
|
140 |
\<head>\n\
|
|
141 |
\<title>" ^ plain (title ^ " (" ^ version ^ ")") ^ "</title>\n\
|
|
142 |
\</head>\n\
|
|
143 |
\\n\
|
|
144 |
\<body>\n\
|
|
145 |
\<h1>" ^ plain title ^ "</h1>\n"
|
6324
|
146 |
|
6405
|
147 |
val end_document = "\n</body>\n</html>\n";
|
6324
|
148 |
|
6754
|
149 |
fun gen_link how (path, name) = para (href_path path how ^ " to index of " ^ plain name);
|
|
150 |
val up_link = gen_link "Up";
|
|
151 |
val back_link = gen_link "Back";
|
6338
|
152 |
|
|
153 |
|
|
154 |
(* session index *)
|
|
155 |
|
6649
|
156 |
fun begin_index up (index_path, session) opt_readme graph =
|
6754
|
157 |
begin_document ("Index of " ^ session) ^ up_link up ^
|
|
158 |
para ("View " ^ href_path graph "theory dependencies" ^
|
|
159 |
(case opt_readme of None => "" | Some p => "<br>\nView " ^ href_path p "README")) ^
|
6405
|
160 |
"\n<hr>\n\n<h2>Theories</h2>\n<ul>\n";
|
6338
|
161 |
|
|
162 |
val end_index = end_document;
|
|
163 |
|
6649
|
164 |
fun choice chs s = space_implode " " (map (fn (s', lnk) =>
|
|
165 |
enclose "[" "]" (if s = s' then keyword s' else href_name lnk s')) chs);
|
|
166 |
|
6754
|
167 |
fun applet_pages session codebase back alt_graph =
|
6649
|
168 |
let
|
|
169 |
val choices = [("none", "small", "small.html"),
|
|
170 |
("none", "medium", "medium.html"),
|
|
171 |
("none", "large", "large.html"),
|
|
172 |
("all", "small", "small_all.html"),
|
|
173 |
("all", "medium", "medium_all.html"),
|
|
174 |
("all", "large", "large_all.html")];
|
|
175 |
|
|
176 |
val sizes = [("small", ("500", "400")),
|
|
177 |
("medium", ("650", "520")),
|
|
178 |
("large", ("800", "640"))];
|
|
179 |
|
|
180 |
fun applet_page (gtype, size, name) =
|
6754
|
181 |
let
|
|
182 |
val (width, height) = the (assoc (sizes, size));
|
|
183 |
val subsessions =
|
|
184 |
if alt_graph then
|
|
185 |
"View subsessions: " ^ choice (map (fn (x, _, z) => (x, z))
|
|
186 |
(filter (fn (_, y, _) => y = size) choices)) gtype ^ "<br>\n"
|
|
187 |
else "";
|
|
188 |
val browser_size = "Set browser size: " ^
|
|
189 |
choice (map (fn (_, y, z) => (y, z)) (filter (fn (x, _, _) => x = gtype) choices)) size;
|
|
190 |
in
|
|
191 |
(name, begin_document ("Theory dependencies of " ^ session) ^
|
|
192 |
back_link back ^
|
|
193 |
para (subsessions ^ browser_size) ^
|
|
194 |
"\n<hr>\n<applet code=\"GraphBrowser/GraphBrowser.class\" \
|
|
195 |
\codebase=\"" ^ Url.pack codebase ^ "\" width=" ^ width ^ " height=" ^ height ^ ">\n\
|
|
196 |
\<param name=\"graphfile\" value=\"" ^
|
|
197 |
(if gtype = "all" then "all_sessions.graph" else "session.graph") ^ "\">\n\
|
|
198 |
\</applet>\n<hr>" ^ end_document)
|
6649
|
199 |
end;
|
6754
|
200 |
in map applet_page (take (if alt_graph then 6 else 3, choices)) end;
|
6649
|
201 |
|
|
202 |
|
6405
|
203 |
fun entry (p, s) = "<li>" ^ href_path p (plain s) ^ "\n";
|
|
204 |
|
6338
|
205 |
val theory_entry = entry;
|
|
206 |
|
6405
|
207 |
fun session_entries [] = "</ul>"
|
|
208 |
| session_entries es =
|
|
209 |
"</ul>\n<hr>\n\n<h2>Sessions</h2>\n<ul>\n" ^ implode (map entry es) ^ "</ul>";
|
6324
|
210 |
|
|
211 |
|
|
212 |
(* theory *)
|
|
213 |
|
6338
|
214 |
fun output_source src = implode (output_symbols (Source.exhaust (Symbol.source false src)));
|
|
215 |
fun source src = "\n<hr>\n<pre>" ^ output_source src ^ "</pre>\n<hr>\n";
|
6324
|
216 |
|
|
217 |
|
|
218 |
local
|
7408
|
219 |
fun encl None = enclose "[" "]"
|
|
220 |
| encl (Some false) = enclose "(" ")"
|
|
221 |
| encl (Some true) = I;
|
6324
|
222 |
|
7408
|
223 |
fun file (opt_ref, path, loadit) = href_opt_path opt_ref (encl loadit (file_path path));
|
6376
|
224 |
val files = space_implode " + " o map file;
|
|
225 |
val parents = space_implode " + " o map (uncurry href_opt_path o apsnd name);
|
6361
|
226 |
|
6376
|
227 |
fun theory up A =
|
|
228 |
begin_document ("Theory " ^ A) ^ "\n" ^ up_link up ^
|
6324
|
229 |
keyword "theory" ^ " " ^ name A ^ " = ";
|
|
230 |
in
|
|
231 |
|
6376
|
232 |
fun begin_theory up A Bs [] body = theory up A ^ parents Bs ^ ":\n" ^ body
|
|
233 |
| begin_theory up A Bs Ps body = theory up A ^ parents Bs ^ "<br>" ^ keyword "files" ^
|
|
234 |
" " ^ files Ps ^ ":" ^ "\n" ^ body;
|
6324
|
235 |
end;
|
|
236 |
|
6338
|
237 |
val end_theory = end_document;
|
6324
|
238 |
|
|
239 |
|
|
240 |
(* ML file *)
|
|
241 |
|
|
242 |
fun ml_file path str =
|
6649
|
243 |
begin_document ("File " ^ Url.pack path) ^
|
6324
|
244 |
"\n<hr>\n" ^ verbatim str ^ "\n<hr>\n" ^ end_document;
|
|
245 |
|
|
246 |
|
7408
|
247 |
(* theorems *)
|
6324
|
248 |
|
7572
|
249 |
local
|
|
250 |
|
7408
|
251 |
val string_of_thm =
|
6324
|
252 |
Pretty.setmp_margin 80 Pretty.string_of o
|
|
253 |
Display.pretty_thm_no_quote o #1 o Drule.freeze_thaw;
|
|
254 |
|
|
255 |
fun thm th = preform (prefix_lines " " (html_mode string_of_thm th));
|
7408
|
256 |
|
7572
|
257 |
fun thm_name "" = ""
|
|
258 |
| thm_name a = " " ^ name (a ^ ":");
|
|
259 |
|
|
260 |
in
|
|
261 |
|
|
262 |
fun result k a th = para (keyword k ^ thm_name a ^ "\n" ^ thm th);
|
|
263 |
fun results k a ths = para (cat_lines ((keyword k ^ thm_name a) :: map thm ths));
|
|
264 |
|
|
265 |
val theorem = result "theorem";
|
|
266 |
val theorems = results "theorems";
|
|
267 |
|
|
268 |
end;
|
6324
|
269 |
|
|
270 |
|
7634
|
271 |
(* sections *)
|
6324
|
272 |
|
|
273 |
fun section heading = "\n\n<h2>" ^ plain heading ^ "</h2>\n";
|
7634
|
274 |
fun subsection heading = "\n\n<h3>" ^ plain heading ^ "</h3>\n";
|
|
275 |
fun subsubsection heading = "\n\n<h4>" ^ plain heading ^ "</h4>\n";
|
6324
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
(** theory setup **)
|
|
280 |
|
|
281 |
val setup =
|
|
282 |
[Theory.add_mode_tokentrfuns htmlN html_trans];
|
|
283 |
|
|
284 |
|
|
285 |
end;
|