author | kleing |
Mon, 12 Apr 2004 23:52:51 +0200 | |
changeset 14541 | 0a7743e2f8dd |
parent 14534 | 7a46bdcd92f2 |
child 14552 | e88f52b775a5 |
permissions | -rw-r--r-- |
6324 | 1 |
(* Title: Pure/Thy/HTML.ML |
2 |
ID: $Id$ |
|
9415 | 3 |
Author: Markus Wenzel and Stefan Berghofer, TU Muenchen |
8808 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
6324 | 5 |
|
9415 | 6 |
HTML presentation elements. |
6324 | 7 |
*) |
8 |
||
9 |
signature HTML = |
|
10 |
sig |
|
11 |
val output: string -> string |
|
12 |
val output_width: string -> string * real |
|
13 |
type text (* = string *) |
|
14 |
val plain: string -> text |
|
15 |
val name: string -> text |
|
16 |
val keyword: string -> text |
|
17 |
val file_name: string -> text |
|
6649 | 18 |
val file_path: Url.T -> text |
6324 | 19 |
val href_name: string -> text -> text |
6649 | 20 |
val href_path: Url.T -> text -> text |
6376 | 21 |
val href_opt_name: string option -> text -> text |
6649 | 22 |
val href_opt_path: Url.T option -> text -> text |
6376 | 23 |
val para: text -> text |
6324 | 24 |
val preform: text -> text |
25 |
val verbatim: string -> text |
|
7725 | 26 |
val begin_index: Url.T * string -> Url.T * string -> Url.T option |
27 |
-> Url.T option -> Url.T -> text |
|
6338 | 28 |
val end_index: text |
9415 | 29 |
val applet_pages: string -> Url.T * string -> (string * string) list |
6649 | 30 |
val theory_entry: Url.T * string -> text |
31 |
val session_entries: (Url.T * string) list -> text |
|
8190 | 32 |
val verbatim_source: Symbol.symbol list -> text |
6649 | 33 |
val begin_theory: Url.T * string -> string -> (Url.T option * string) list -> |
7408 | 34 |
(Url.T option * Url.T * bool option) list -> text -> text |
6324 | 35 |
val end_theory: text |
6649 | 36 |
val ml_file: Url.T -> string -> text |
13531 | 37 |
val results: string -> (string * thm list) list -> text |
8088 | 38 |
val chapter: string -> 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"; |
|
10573 | 54 |
fun html_mode f x = setmp print_mode (htmlN :: ! print_mode) f x; |
6324 | 55 |
|
56 |
||
57 |
(* symbol output *) |
|
58 |
||
6338 | 59 |
local |
60 |
val escape = fn "<" => "<" | ">" => ">" | "&" => "&" | c => c; |
|
6324 | 61 |
|
6338 | 62 |
val output_sym = |
9963 | 63 |
fn "\\<spacespace>" => (2.0, " ") |
64 |
| "\\<exclamdown>" => (1.0, "¡") |
|
65 |
| "\\<cent>" => (1.0, "¢") |
|
66 |
| "\\<pounds>" => (1.0, "£") |
|
67 |
| "\\<currency>" => (1.0, "¤") |
|
68 |
| "\\<yen>" => (1.0, "¥") |
|
69 |
| "\\<bar>" => (1.0, "¦") |
|
70 |
| "\\<section>" => (1.0, "§") |
|
10837
7d640de604e4
added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents:
10831
diff
changeset
|
71 |
| "\\<dieresis>" => (1.0, "¨") |
9963 | 72 |
| "\\<copyright>" => (1.0, "©") |
73 |
| "\\<ordfeminine>" => (1.0, "ª") |
|
74 |
| "\\<guillemotleft>" => (1.0, "«") |
|
75 |
| "\\<not>" => (1.0, "¬") |
|
6338 | 76 |
| "\\<hyphen>" => (1.0, "­") |
9963 | 77 |
| "\\<registered>" => (1.0, "®") |
10831 | 78 |
| "\\<inverse>" => (1.0, "¯") |
9963 | 79 |
| "\\<degree>" => (1.0, "°") |
80 |
| "\\<plusminus>" => (1.0, "±") |
|
81 |
| "\\<twosuperior>" => (1.0, "²") |
|
82 |
| "\\<threesuperior>" => (1.0, "³") |
|
10837
7d640de604e4
added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents:
10831
diff
changeset
|
83 |
| "\\<acute>" => (1.0, "´") |
9963 | 84 |
| "\\<mu>" => (1.0, "µ") |
85 |
| "\\<paragraph>" => (1.0, "¶") |
|
6338 | 86 |
| "\\<cdot>" => (1.0, "·") |
10837
7d640de604e4
added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents:
10831
diff
changeset
|
87 |
| "\\<cedilla>" => (1.0, "¸") |
9963 | 88 |
| "\\<onesuperior>" => (1.0, "¹") |
89 |
| "\\<ordmasculine>" => (1.0, "º") |
|
90 |
| "\\<guillemotright>" => (1.0, "»") |
|
91 |
| "\\<onequarter>" => (1.0, "¼") |
|
92 |
| "\\<onehalf>" => (1.0, "½") |
|
93 |
| "\\<threequarters>" => (1.0, "¾") |
|
94 |
| "\\<questiondown>" => (1.0, "¿") |
|
6338 | 95 |
| "\\<times>" => (1.0, "×") |
10837
7d640de604e4
added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents:
10831
diff
changeset
|
96 |
| "\\<emptyset>" => (1.0, "Ø") |
9963 | 97 |
| "\\<div>" => (1.0, "÷") |
14534 | 98 |
| "\\<^bsub>" => (0.0, "<sub>") |
99 |
| "\\<^esub>" => (0.0, "</sub>") |
|
100 |
| "\\<^bsup>" => (0.0, "<sup>") |
|
101 |
| "\\<^esup>" => (0.0, "</sup>") |
|
102 |
(* keep \<^sub> etc, so it does not get destroyed by default case *) |
|
103 |
| "\\<^sup>" => (0.0, "\\<^sup>") |
|
104 |
| "\\<^sub>" => (0.0, "\\<^sub>") |
|
105 |
| "\\<^isup>" => (0.0, "\\<^isup>") |
|
106 |
| "\\<^isub>" => (0.0, "\\<^isub>") |
|
6338 | 107 |
| s => (real (size s), implode (map escape (explode s))); |
6324 | 108 |
|
6338 | 109 |
fun add_sym (width, (w: real, s)) = (width + w, s); |
14534 | 110 |
|
111 |
fun script (0, "\\<^sub>") = (1,"<sub>") |
|
112 |
| script (0, "\\<^isub>") = (1,"<sub>") |
|
113 |
| script (1, x) = (0, x ^ "</sub>") |
|
114 |
| script (0, "\\<^sup>") = (2,"<sup>") |
|
115 |
| script (0, "\\<^isup>") = (2,"<sup>") |
|
116 |
| script (2, x) = (0, x ^ "</sup>") |
|
117 |
| script (s, x) = (s,x); |
|
118 |
||
119 |
fun scrs (s, []) = (s,[]) |
|
120 |
| scrs (s, x::xs) = let val (s', x') = script (s, x) |
|
121 |
val (s'', xs') = scrs (s', xs) |
|
122 |
in (s'', x'::xs') end; |
|
123 |
||
124 |
fun scripts ss = #2 (scrs (0,ss)); |
|
6338 | 125 |
in |
6324 | 126 |
|
6338 | 127 |
fun output_width str = |
128 |
if not (exists_string (equal "<" orf equal ">" orf equal "&") str) then (str, real (size str)) |
|
129 |
else |
|
130 |
let val (width, syms) = foldl_map add_sym (0.0, map output_sym (Symbol.explode str)) |
|
14534 | 131 |
in (implode (scripts syms), width) end; |
6338 | 132 |
|
133 |
val output = #1 o output_width; |
|
14534 | 134 |
val output_symbols = scripts o (map (#2 o output_sym)) |
6338 | 135 |
|
136 |
end; |
|
137 |
||
6324 | 138 |
|
10954 | 139 |
val _ = Symbol.add_mode htmlN (output_width, Symbol.default_indent); |
6324 | 140 |
|
141 |
||
142 |
(* token translations *) |
|
143 |
||
14541 | 144 |
fun style stl = |
145 |
apfst (enclose ("<span class=" ^ quote stl ^ ">") "</span>") o output_width; |
|
6324 | 146 |
|
147 |
val html_trans = |
|
14541 | 148 |
[("class", style "tclass"), |
149 |
("tfree", style "tfree"), |
|
150 |
("tvar", style "tvar"), |
|
151 |
("free", style "free"), |
|
152 |
("bound", style "bound"), |
|
153 |
("var", style "var"), |
|
154 |
("xstr", style "xstr")]; |
|
6324 | 155 |
|
156 |
||
157 |
||
158 |
(** HTML markup **) |
|
159 |
||
160 |
type text = string; |
|
161 |
||
162 |
||
163 |
(* atoms *) |
|
164 |
||
165 |
val plain = output; |
|
14541 | 166 |
fun name s = "<span class=\"name\">" ^ output s ^ "</span>"; |
167 |
fun keyword s = "<span class=\"keyword\">" ^ output s ^ "</span>"; |
|
168 |
fun file_name s = "<span class=\"filename\">" ^ output s ^ "</span>"; |
|
6649 | 169 |
val file_path = file_name o Url.pack; |
6324 | 170 |
|
171 |
||
172 |
(* misc *) |
|
173 |
||
174 |
fun href_name s txt = "<a href=" ^ quote s ^ ">" ^ txt ^ "</a>"; |
|
6649 | 175 |
fun href_path path txt = href_name (Url.pack path) txt; |
6376 | 176 |
|
177 |
fun href_opt_name None txt = txt |
|
178 |
| href_opt_name (Some s) txt = href_name s txt; |
|
179 |
||
180 |
fun href_opt_path None txt = txt |
|
181 |
| href_opt_path (Some p) txt = href_path p txt; |
|
182 |
||
12413 | 183 |
fun para txt = "\n<p>" ^ txt ^ "</p>\n"; |
6324 | 184 |
fun preform txt = "<pre>" ^ txt ^ "</pre>"; |
185 |
val verbatim = preform o output; |
|
186 |
||
187 |
||
188 |
(* document *) |
|
189 |
||
190 |
fun begin_document title = |
|
14083
aed5d25c4a0c
Added DOCTYPE and Content-type to HTML documents.
webertj
parents:
13531
diff
changeset
|
191 |
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n\ |
aed5d25c4a0c
Added DOCTYPE and Content-type to HTML documents.
webertj
parents:
13531
diff
changeset
|
192 |
\\n\ |
aed5d25c4a0c
Added DOCTYPE and Content-type to HTML documents.
webertj
parents:
13531
diff
changeset
|
193 |
\<html>\n\ |
6405 | 194 |
\<head>\n\ |
14083
aed5d25c4a0c
Added DOCTYPE and Content-type to HTML documents.
webertj
parents:
13531
diff
changeset
|
195 |
\<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n\ |
6405 | 196 |
\<title>" ^ plain (title ^ " (" ^ version ^ ")") ^ "</title>\n\ |
14541 | 197 |
\<link rel=\"stylesheet\" type=\"text/css\" href=\"isabelle.css\">\n\ |
6405 | 198 |
\</head>\n\ |
199 |
\\n\ |
|
200 |
\<body>\n\ |
|
14541 | 201 |
\<div class=\"head\">\ |
6405 | 202 |
\<h1>" ^ plain title ^ "</h1>\n" |
6324 | 203 |
|
14541 | 204 |
val end_document = "\n</div>\n</body>\n</html>\n"; |
6324 | 205 |
|
6754 | 206 |
fun gen_link how (path, name) = para (href_path path how ^ " to index of " ^ plain name); |
207 |
val up_link = gen_link "Up"; |
|
208 |
val back_link = gen_link "Back"; |
|
6338 | 209 |
|
210 |
||
211 |
(* session index *) |
|
212 |
||
7725 | 213 |
fun begin_index up (index_path, session) opt_readme opt_doc graph = |
6754 | 214 |
begin_document ("Index of " ^ session) ^ up_link up ^ |
215 |
para ("View " ^ href_path graph "theory dependencies" ^ |
|
7725 | 216 |
(case opt_readme of None => "" | Some p => "<br>\nView " ^ href_path p "README") ^ |
217 |
(case opt_doc of None => "" | Some p => "<br>\nView " ^ href_path p "document")) ^ |
|
14541 | 218 |
"\n</div>\n<hr>\n<div class=\"theories\">\n<h2>Theories</h2>\n<ul>\n"; |
6338 | 219 |
|
220 |
val end_index = end_document; |
|
221 |
||
6649 | 222 |
fun choice chs s = space_implode " " (map (fn (s', lnk) => |
223 |
enclose "[" "]" (if s = s' then keyword s' else href_name lnk s')) chs); |
|
224 |
||
9415 | 225 |
fun applet_pages session back = |
6649 | 226 |
let |
9415 | 227 |
val sizes = |
228 |
[("small", "small.html", ("500", "400")), |
|
229 |
("medium", "medium.html", ("650", "520")), |
|
230 |
("large", "large.html", ("800", "640"))]; |
|
6649 | 231 |
|
9415 | 232 |
fun applet_page (size, name, (width, height)) = |
6754 | 233 |
let |
234 |
val browser_size = "Set browser size: " ^ |
|
9415 | 235 |
choice (map (fn (y, z, _) => (y, z)) sizes) size; |
6754 | 236 |
in |
237 |
(name, begin_document ("Theory dependencies of " ^ session) ^ |
|
238 |
back_link back ^ |
|
9415 | 239 |
para browser_size ^ |
14541 | 240 |
"\n</div>\n<hr>\n<div class=\"graphbrowser\">\n<applet code=\"GraphBrowser/GraphBrowser.class\" \ |
241 |
\archive=\"GraphBrowser.jar\" \ |
|
9045 | 242 |
\width=" ^ width ^ " height=" ^ height ^ ">\n\ |
9415 | 243 |
\<param name=\"graphfile\" value=\"" ^ "session.graph" ^ "\">\n\ |
6754 | 244 |
\</applet>\n<hr>" ^ end_document) |
6649 | 245 |
end; |
9415 | 246 |
in map applet_page sizes end; |
6649 | 247 |
|
248 |
||
6405 | 249 |
fun entry (p, s) = "<li>" ^ href_path p (plain s) ^ "\n"; |
250 |
||
6338 | 251 |
val theory_entry = entry; |
252 |
||
6405 | 253 |
fun session_entries [] = "</ul>" |
254 |
| session_entries es = |
|
14541 | 255 |
"</ul>\n</div>\n<hr>\n<div class=\"sessions\">\n<h2>Sessions</h2>\n<ul>\n" ^ implode (map entry es) ^ "</ul>"; |
6324 | 256 |
|
257 |
||
258 |
(* theory *) |
|
259 |
||
14541 | 260 |
fun verbatim_source ss = "\n</div>\n<hr>\n<div class=\"source\">\n<pre>" ^ |
261 |
implode (output_symbols ss) ^ |
|
262 |
"</pre>\n</div>\n<hr>\n<div class=\"theorems\">\n"; |
|
6324 | 263 |
|
264 |
||
265 |
local |
|
7408 | 266 |
fun encl None = enclose "[" "]" |
267 |
| encl (Some false) = enclose "(" ")" |
|
268 |
| encl (Some true) = I; |
|
6324 | 269 |
|
7408 | 270 |
fun file (opt_ref, path, loadit) = href_opt_path opt_ref (encl loadit (file_path path)); |
7831 | 271 |
val files = space_implode " " o map file; |
6376 | 272 |
val parents = space_implode " + " o map (uncurry href_opt_path o apsnd name); |
6361 | 273 |
|
6376 | 274 |
fun theory up A = |
275 |
begin_document ("Theory " ^ A) ^ "\n" ^ up_link up ^ |
|
6324 | 276 |
keyword "theory" ^ " " ^ name A ^ " = "; |
277 |
in |
|
278 |
||
6376 | 279 |
fun begin_theory up A Bs [] body = theory up A ^ parents Bs ^ ":\n" ^ body |
12413 | 280 |
| begin_theory up A Bs Ps body = theory up A ^ parents Bs ^ "<br>\n" ^ keyword "files" ^ |
6376 | 281 |
" " ^ files Ps ^ ":" ^ "\n" ^ body; |
6324 | 282 |
end; |
283 |
||
6338 | 284 |
val end_theory = end_document; |
6324 | 285 |
|
286 |
||
287 |
(* ML file *) |
|
288 |
||
289 |
fun ml_file path str = |
|
6649 | 290 |
begin_document ("File " ^ Url.pack path) ^ |
14541 | 291 |
"\n</div>\n<hr><div class=\"mlsource\">\n" ^ |
292 |
verbatim str ^ |
|
293 |
"\n</div>\n<hr>\n<div class=\"mlfooter\">\n" ^ |
|
294 |
end_document; |
|
6324 | 295 |
|
296 |
||
7408 | 297 |
(* theorems *) |
6324 | 298 |
|
7572 | 299 |
local |
300 |
||
7408 | 301 |
val string_of_thm = |
6324 | 302 |
Pretty.setmp_margin 80 Pretty.string_of o |
303 |
Display.pretty_thm_no_quote o #1 o Drule.freeze_thaw; |
|
304 |
||
305 |
fun thm th = preform (prefix_lines " " (html_mode string_of_thm th)); |
|
7408 | 306 |
|
7572 | 307 |
fun thm_name "" = "" |
308 |
| thm_name a = " " ^ name (a ^ ":"); |
|
309 |
||
310 |
in |
|
311 |
||
13531 | 312 |
fun result k (a, ths) = para (cat_lines ((keyword k ^ thm_name a) :: map thm ths)); |
7572 | 313 |
|
13531 | 314 |
fun results _ [] = "" |
315 |
| results k (res :: ress) = cat_lines (result k res :: map (result "and") ress); |
|
7572 | 316 |
|
317 |
end; |
|
6324 | 318 |
|
319 |
||
7634 | 320 |
(* sections *) |
6324 | 321 |
|
8088 | 322 |
fun chapter heading = "\n\n<h1>" ^ plain heading ^ "</h1>\n"; |
6324 | 323 |
fun section heading = "\n\n<h2>" ^ plain heading ^ "</h2>\n"; |
7634 | 324 |
fun subsection heading = "\n\n<h3>" ^ plain heading ^ "</h3>\n"; |
325 |
fun subsubsection heading = "\n\n<h4>" ^ plain heading ^ "</h4>\n"; |
|
6324 | 326 |
|
327 |
||
328 |
(** theory setup **) |
|
329 |
||
330 |
val setup = |
|
331 |
[Theory.add_mode_tokentrfuns htmlN html_trans]; |
|
332 |
||
333 |
||
334 |
end; |