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