author | wenzelm |
Sun, 11 Nov 2001 21:38:54 +0100 | |
changeset 12151 | fb0fb0209c87 |
parent 10954 | a555bfb66c2d |
child 12413 | f879fcc9412d |
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 |
12151 | 37 |
val multi_result: string * (string * thm list) list -> text |
7572 | 38 |
val results: string -> string -> thm list -> text |
6324 | 39 |
val theorem: string -> thm -> text |
7408 | 40 |
val theorems: string -> thm list -> text |
8088 | 41 |
val chapter: string -> text |
6324 | 42 |
val section: string -> text |
7634 | 43 |
val subsection: string -> text |
44 |
val subsubsection: string -> text |
|
6324 | 45 |
val setup: (theory -> theory) list |
46 |
end; |
|
47 |
||
48 |
structure HTML: HTML = |
|
49 |
struct |
|
50 |
||
51 |
||
52 |
(** HTML print modes **) |
|
53 |
||
54 |
(* mode *) |
|
55 |
||
56 |
val htmlN = "HTML"; |
|
10573 | 57 |
fun html_mode f x = setmp print_mode (htmlN :: ! print_mode) f x; |
6324 | 58 |
|
59 |
||
60 |
(* symbol output *) |
|
61 |
||
6338 | 62 |
local |
63 |
val escape = fn "<" => "<" | ">" => ">" | "&" => "&" | c => c; |
|
6324 | 64 |
|
6338 | 65 |
val output_sym = |
9963 | 66 |
fn "\\<spacespace>" => (2.0, " ") |
67 |
| "\\<exclamdown>" => (1.0, "¡") |
|
68 |
| "\\<cent>" => (1.0, "¢") |
|
69 |
| "\\<pounds>" => (1.0, "£") |
|
70 |
| "\\<currency>" => (1.0, "¤") |
|
71 |
| "\\<yen>" => (1.0, "¥") |
|
72 |
| "\\<bar>" => (1.0, "¦") |
|
73 |
| "\\<section>" => (1.0, "§") |
|
10837
7d640de604e4
added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents:
10831
diff
changeset
|
74 |
| "\\<dieresis>" => (1.0, "¨") |
9963 | 75 |
| "\\<copyright>" => (1.0, "©") |
76 |
| "\\<ordfeminine>" => (1.0, "ª") |
|
77 |
| "\\<guillemotleft>" => (1.0, "«") |
|
78 |
| "\\<not>" => (1.0, "¬") |
|
6338 | 79 |
| "\\<hyphen>" => (1.0, "­") |
9963 | 80 |
| "\\<registered>" => (1.0, "®") |
10831 | 81 |
| "\\<inverse>" => (1.0, "¯") |
9963 | 82 |
| "\\<degree>" => (1.0, "°") |
83 |
| "\\<plusminus>" => (1.0, "±") |
|
84 |
| "\\<twosuperior>" => (1.0, "²") |
|
85 |
| "\\<threesuperior>" => (1.0, "³") |
|
10837
7d640de604e4
added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents:
10831
diff
changeset
|
86 |
| "\\<acute>" => (1.0, "´") |
9963 | 87 |
| "\\<mu>" => (1.0, "µ") |
88 |
| "\\<paragraph>" => (1.0, "¶") |
|
6338 | 89 |
| "\\<cdot>" => (1.0, "·") |
10837
7d640de604e4
added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents:
10831
diff
changeset
|
90 |
| "\\<cedilla>" => (1.0, "¸") |
9963 | 91 |
| "\\<onesuperior>" => (1.0, "¹") |
92 |
| "\\<ordmasculine>" => (1.0, "º") |
|
93 |
| "\\<guillemotright>" => (1.0, "»") |
|
94 |
| "\\<onequarter>" => (1.0, "¼") |
|
95 |
| "\\<onehalf>" => (1.0, "½") |
|
96 |
| "\\<threequarters>" => (1.0, "¾") |
|
97 |
| "\\<questiondown>" => (1.0, "¿") |
|
6338 | 98 |
| "\\<times>" => (1.0, "×") |
10837
7d640de604e4
added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents:
10831
diff
changeset
|
99 |
| "\\<emptyset>" => (1.0, "Ø") |
9963 | 100 |
| "\\<div>" => (1.0, "÷") |
6338 | 101 |
| s => (real (size s), implode (map escape (explode s))); |
6324 | 102 |
|
6338 | 103 |
fun add_sym (width, (w: real, s)) = (width + w, s); |
104 |
in |
|
6324 | 105 |
|
6338 | 106 |
fun output_width str = |
107 |
if not (exists_string (equal "<" orf equal ">" orf equal "&") str) then (str, real (size str)) |
|
108 |
else |
|
109 |
let val (width, syms) = foldl_map add_sym (0.0, map output_sym (Symbol.explode str)) |
|
110 |
in (implode syms, width) end; |
|
111 |
||
112 |
val output = #1 o output_width; |
|
113 |
val output_symbols = map (#2 o output_sym); |
|
114 |
||
115 |
end; |
|
116 |
||
6324 | 117 |
|
10954 | 118 |
val _ = Symbol.add_mode htmlN (output_width, Symbol.default_indent); |
6324 | 119 |
|
120 |
||
121 |
(* token translations *) |
|
122 |
||
6347 | 123 |
fun color col = |
124 |
apfst (enclose ("<font color=" ^ quote col ^ ">") "</font>") o output_width; |
|
6324 | 125 |
|
126 |
val html_trans = |
|
127 |
[("class", color "red"), |
|
128 |
("tfree", color "purple"), |
|
129 |
("tvar", color "purple"), |
|
130 |
("free", color "blue"), |
|
131 |
("bound", color "green"), |
|
132 |
("var", color "blue"), |
|
133 |
("xstr", color "brown")]; |
|
134 |
||
135 |
||
136 |
||
137 |
(** HTML markup **) |
|
138 |
||
139 |
type text = string; |
|
140 |
||
141 |
||
142 |
(* atoms *) |
|
143 |
||
144 |
val plain = output; |
|
145 |
fun name s = "<i>" ^ output s ^ "</i>"; |
|
146 |
fun keyword s = "<b>" ^ output s ^ "</b>"; |
|
147 |
fun file_name s = "<tt>" ^ output s ^ "</tt>"; |
|
6649 | 148 |
val file_path = file_name o Url.pack; |
6324 | 149 |
|
150 |
||
151 |
(* misc *) |
|
152 |
||
153 |
fun href_name s txt = "<a href=" ^ quote s ^ ">" ^ txt ^ "</a>"; |
|
6649 | 154 |
fun href_path path txt = href_name (Url.pack path) txt; |
6376 | 155 |
|
156 |
fun href_opt_name None txt = txt |
|
157 |
| href_opt_name (Some s) txt = href_name s txt; |
|
158 |
||
159 |
fun href_opt_path None txt = txt |
|
160 |
| href_opt_path (Some p) txt = href_path p txt; |
|
161 |
||
162 |
fun para txt = "\n<p>\n" ^ txt ^ "\n</p>\n"; |
|
6324 | 163 |
fun preform txt = "<pre>" ^ txt ^ "</pre>"; |
164 |
val verbatim = preform o output; |
|
165 |
||
166 |
||
167 |
(* document *) |
|
168 |
||
169 |
fun begin_document title = |
|
6405 | 170 |
"<html>\n\ |
171 |
\<head>\n\ |
|
172 |
\<title>" ^ plain (title ^ " (" ^ version ^ ")") ^ "</title>\n\ |
|
173 |
\</head>\n\ |
|
174 |
\\n\ |
|
175 |
\<body>\n\ |
|
176 |
\<h1>" ^ plain title ^ "</h1>\n" |
|
6324 | 177 |
|
6405 | 178 |
val end_document = "\n</body>\n</html>\n"; |
6324 | 179 |
|
6754 | 180 |
fun gen_link how (path, name) = para (href_path path how ^ " to index of " ^ plain name); |
181 |
val up_link = gen_link "Up"; |
|
182 |
val back_link = gen_link "Back"; |
|
6338 | 183 |
|
184 |
||
185 |
(* session index *) |
|
186 |
||
7725 | 187 |
fun begin_index up (index_path, session) opt_readme opt_doc graph = |
6754 | 188 |
begin_document ("Index of " ^ session) ^ up_link up ^ |
189 |
para ("View " ^ href_path graph "theory dependencies" ^ |
|
7725 | 190 |
(case opt_readme of None => "" | Some p => "<br>\nView " ^ href_path p "README") ^ |
191 |
(case opt_doc of None => "" | Some p => "<br>\nView " ^ href_path p "document")) ^ |
|
6405 | 192 |
"\n<hr>\n\n<h2>Theories</h2>\n<ul>\n"; |
6338 | 193 |
|
194 |
val end_index = end_document; |
|
195 |
||
6649 | 196 |
fun choice chs s = space_implode " " (map (fn (s', lnk) => |
197 |
enclose "[" "]" (if s = s' then keyword s' else href_name lnk s')) chs); |
|
198 |
||
9415 | 199 |
fun applet_pages session back = |
6649 | 200 |
let |
9415 | 201 |
val sizes = |
202 |
[("small", "small.html", ("500", "400")), |
|
203 |
("medium", "medium.html", ("650", "520")), |
|
204 |
("large", "large.html", ("800", "640"))]; |
|
6649 | 205 |
|
9415 | 206 |
fun applet_page (size, name, (width, height)) = |
6754 | 207 |
let |
208 |
val browser_size = "Set browser size: " ^ |
|
9415 | 209 |
choice (map (fn (y, z, _) => (y, z)) sizes) size; |
6754 | 210 |
in |
211 |
(name, begin_document ("Theory dependencies of " ^ session) ^ |
|
212 |
back_link back ^ |
|
9415 | 213 |
para browser_size ^ |
6754 | 214 |
"\n<hr>\n<applet code=\"GraphBrowser/GraphBrowser.class\" \ |
9045 | 215 |
\width=" ^ width ^ " height=" ^ height ^ ">\n\ |
9415 | 216 |
\<param name=\"graphfile\" value=\"" ^ "session.graph" ^ "\">\n\ |
6754 | 217 |
\</applet>\n<hr>" ^ end_document) |
6649 | 218 |
end; |
9415 | 219 |
in map applet_page sizes end; |
6649 | 220 |
|
221 |
||
6405 | 222 |
fun entry (p, s) = "<li>" ^ href_path p (plain s) ^ "\n"; |
223 |
||
6338 | 224 |
val theory_entry = entry; |
225 |
||
6405 | 226 |
fun session_entries [] = "</ul>" |
227 |
| session_entries es = |
|
228 |
"</ul>\n<hr>\n\n<h2>Sessions</h2>\n<ul>\n" ^ implode (map entry es) ^ "</ul>"; |
|
6324 | 229 |
|
230 |
||
231 |
(* theory *) |
|
232 |
||
7725 | 233 |
fun verbatim_source ss = "\n<hr>\n<pre>" ^ implode (output_symbols ss) ^ "</pre>\n<hr>\n"; |
6324 | 234 |
|
235 |
||
236 |
local |
|
7408 | 237 |
fun encl None = enclose "[" "]" |
238 |
| encl (Some false) = enclose "(" ")" |
|
239 |
| encl (Some true) = I; |
|
6324 | 240 |
|
7408 | 241 |
fun file (opt_ref, path, loadit) = href_opt_path opt_ref (encl loadit (file_path path)); |
7831 | 242 |
val files = space_implode " " o map file; |
6376 | 243 |
val parents = space_implode " + " o map (uncurry href_opt_path o apsnd name); |
6361 | 244 |
|
6376 | 245 |
fun theory up A = |
246 |
begin_document ("Theory " ^ A) ^ "\n" ^ up_link up ^ |
|
6324 | 247 |
keyword "theory" ^ " " ^ name A ^ " = "; |
248 |
in |
|
249 |
||
6376 | 250 |
fun begin_theory up A Bs [] body = theory up A ^ parents Bs ^ ":\n" ^ body |
251 |
| begin_theory up A Bs Ps body = theory up A ^ parents Bs ^ "<br>" ^ keyword "files" ^ |
|
252 |
" " ^ files Ps ^ ":" ^ "\n" ^ body; |
|
6324 | 253 |
end; |
254 |
||
6338 | 255 |
val end_theory = end_document; |
6324 | 256 |
|
257 |
||
258 |
(* ML file *) |
|
259 |
||
260 |
fun ml_file path str = |
|
6649 | 261 |
begin_document ("File " ^ Url.pack path) ^ |
6324 | 262 |
"\n<hr>\n" ^ verbatim str ^ "\n<hr>\n" ^ end_document; |
263 |
||
264 |
||
7408 | 265 |
(* theorems *) |
6324 | 266 |
|
7572 | 267 |
local |
268 |
||
7408 | 269 |
val string_of_thm = |
6324 | 270 |
Pretty.setmp_margin 80 Pretty.string_of o |
271 |
Display.pretty_thm_no_quote o #1 o Drule.freeze_thaw; |
|
272 |
||
273 |
fun thm th = preform (prefix_lines " " (html_mode string_of_thm th)); |
|
7408 | 274 |
|
7572 | 275 |
fun thm_name "" = "" |
276 |
| thm_name a = " " ^ name (a ^ ":"); |
|
277 |
||
278 |
in |
|
279 |
||
280 |
fun results k a ths = para (cat_lines ((keyword k ^ thm_name a) :: map thm ths)); |
|
281 |
||
12151 | 282 |
fun multi_result (_, []) = "" |
283 |
| multi_result (k, ((a, ths) :: res)) = |
|
284 |
cat_lines (results k a ths :: map (uncurry (results "and")) res); |
|
285 |
||
286 |
fun theorem a th = multi_result ("theorem", [(a, [th])]); |
|
7572 | 287 |
val theorems = results "theorems"; |
288 |
||
289 |
end; |
|
6324 | 290 |
|
291 |
||
7634 | 292 |
(* sections *) |
6324 | 293 |
|
8088 | 294 |
fun chapter heading = "\n\n<h1>" ^ plain heading ^ "</h1>\n"; |
6324 | 295 |
fun section heading = "\n\n<h2>" ^ plain heading ^ "</h2>\n"; |
7634 | 296 |
fun subsection heading = "\n\n<h3>" ^ plain heading ^ "</h3>\n"; |
297 |
fun subsubsection heading = "\n\n<h4>" ^ plain heading ^ "</h4>\n"; |
|
6324 | 298 |
|
299 |
||
300 |
||
301 |
(** theory setup **) |
|
302 |
||
303 |
val setup = |
|
304 |
[Theory.add_mode_tokentrfuns htmlN html_trans]; |
|
305 |
||
306 |
||
307 |
end; |