| author | wenzelm |
| Tue, 31 Jul 2007 00:56:31 +0200 | |
| changeset 24077 | e7ba448bc571 |
| parent 23935 | 2a4e42ec9a54 |
| child 24101 | bdcefe679ced |
| permissions | -rw-r--r-- |
| 6324 | 1 |
(* Title: Pure/Thy/HTML.ML |
2 |
ID: $Id$ |
|
| 9415 | 3 |
Author: Markus Wenzel and Stefan Berghofer, TU Muenchen |
| 6324 | 4 |
|
| 9415 | 5 |
HTML presentation elements. |
| 6324 | 6 |
*) |
7 |
||
8 |
signature HTML = |
|
9 |
sig |
|
| 23724 | 10 |
val html_mode: ('a -> 'b) -> 'a -> 'b
|
| 23622 | 11 |
type text = string |
| 6324 | 12 |
val plain: string -> text |
13 |
val name: string -> text |
|
14 |
val keyword: string -> text |
|
| 23622 | 15 |
val command: string -> text |
| 6324 | 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 |
|
|
17470
6e9d910c3837
added with_charset: string -> ('a -> 'b) -> 'a -> 'b;
wenzelm
parents:
17412
diff
changeset
|
25 |
val with_charset: string -> ('a -> 'b) -> 'a -> 'b
|
| 23724 | 26 |
val begin_document: string -> text |
27 |
val end_document: text |
|
| 17080 | 28 |
val begin_index: Url.T * string -> Url.T * string -> (Url.T * string) list -> Url.T -> text |
| 6338 | 29 |
val end_index: text |
| 9415 | 30 |
val applet_pages: string -> Url.T * string -> (string * string) list |
| 6649 | 31 |
val theory_entry: Url.T * string -> text |
32 |
val session_entries: (Url.T * string) list -> text |
|
| 8190 | 33 |
val verbatim_source: Symbol.symbol list -> text |
| 6649 | 34 |
val begin_theory: Url.T * string -> string -> (Url.T option * string) list -> |
| 7408 | 35 |
(Url.T option * Url.T * bool option) list -> text -> text |
| 6324 | 36 |
val end_theory: text |
| 6649 | 37 |
val ml_file: Url.T -> string -> text |
| 22122 | 38 |
val results: Proof.context -> string -> (string * thm list) list -> text |
| 8088 | 39 |
val chapter: string -> text |
| 6324 | 40 |
val section: string -> text |
| 7634 | 41 |
val subsection: string -> text |
42 |
val subsubsection: string -> text |
|
| 6324 | 43 |
end; |
44 |
||
45 |
structure HTML: HTML = |
|
46 |
struct |
|
47 |
||
48 |
||
49 |
(** HTML print modes **) |
|
50 |
||
51 |
(* mode *) |
|
52 |
||
53 |
val htmlN = "HTML"; |
|
| 23935 | 54 |
fun html_mode f x = PrintMode.with_modes [htmlN] f x; |
| 6324 | 55 |
|
56 |
||
57 |
(* symbol output *) |
|
58 |
||
| 6338 | 59 |
local |
| 16196 | 60 |
val html_syms = Symtab.make |
| 23622 | 61 |
[("\\<spacespace>", (2, " ")),
|
62 |
("\\<exclamdown>", (1, "¡")),
|
|
63 |
("\\<cent>", (1, "¢")),
|
|
64 |
("\\<pounds>", (1, "£")),
|
|
65 |
("\\<currency>", (1, "¤")),
|
|
66 |
("\\<yen>", (1, "¥")),
|
|
67 |
("\\<bar>", (1, "¦")),
|
|
68 |
("\\<section>", (1, "§")),
|
|
69 |
("\\<dieresis>", (1, "¨")),
|
|
70 |
("\\<copyright>", (1, "©")),
|
|
71 |
("\\<ordfeminine>", (1, "ª")),
|
|
72 |
("\\<guillemotleft>", (1, "«")),
|
|
73 |
("\\<not>", (1, "¬")),
|
|
74 |
("\\<hyphen>", (1, "­")),
|
|
75 |
("\\<registered>", (1, "®")),
|
|
76 |
("\\<inverse>", (1, "¯")),
|
|
77 |
("\\<degree>", (1, "°")),
|
|
78 |
("\\<plusminus>", (1, "±")),
|
|
79 |
("\\<twosuperior>", (1, "²")),
|
|
80 |
("\\<threesuperior>", (1, "³")),
|
|
81 |
("\\<acute>", (1, "´")),
|
|
82 |
("\\<paragraph>", (1, "¶")),
|
|
83 |
("\\<cdot>", (1, "·")),
|
|
84 |
("\\<cedilla>", (1, "¸")),
|
|
85 |
("\\<onesuperior>", (1, "¹")),
|
|
86 |
("\\<ordmasculine>", (1, "º")),
|
|
87 |
("\\<guillemotright>", (1, "»")),
|
|
88 |
("\\<onequarter>", (1, "¼")),
|
|
89 |
("\\<onehalf>", (1, "½")),
|
|
90 |
("\\<threequarters>", (1, "¾")),
|
|
91 |
("\\<questiondown>", (1, "¿")),
|
|
92 |
("\\<times>", (1, "×")),
|
|
93 |
("\\<div>", (1, "÷")),
|
|
94 |
("\\<circ>", (1, "o")),
|
|
95 |
("\\<Alpha>", (1, "Α")),
|
|
96 |
("\\<Beta>", (1, "Β")),
|
|
97 |
("\\<Gamma>", (1, "Γ")),
|
|
98 |
("\\<Delta>", (1, "Δ")),
|
|
99 |
("\\<Epsilon>", (1, "Ε")),
|
|
100 |
("\\<Zeta>", (1, "Ζ")),
|
|
101 |
("\\<Eta>", (1, "Η")),
|
|
102 |
("\\<Theta>", (1, "Θ")),
|
|
103 |
("\\<Iota>", (1, "Ι")),
|
|
104 |
("\\<Kappa>", (1, "Κ")),
|
|
105 |
("\\<Lambda>", (1, "Λ")),
|
|
106 |
("\\<Mu>", (1, "Μ")),
|
|
107 |
("\\<Nu>", (1, "Ν")),
|
|
108 |
("\\<Xi>", (1, "Ξ")),
|
|
109 |
("\\<Omicron>", (1, "Ο")),
|
|
110 |
("\\<Pi>", (1, "Π")),
|
|
111 |
("\\<Rho>", (1, "Ρ")),
|
|
112 |
("\\<Sigma>", (1, "Σ")),
|
|
113 |
("\\<Tau>", (1, "Τ")),
|
|
114 |
("\\<Upsilon>", (1, "Υ")),
|
|
115 |
("\\<Phi>", (1, "Φ")),
|
|
116 |
("\\<Chi>", (1, "Χ")),
|
|
117 |
("\\<Psi>", (1, "Ψ")),
|
|
118 |
("\\<Omega>", (1, "Ω")),
|
|
119 |
("\\<alpha>", (1, "α")),
|
|
120 |
("\\<beta>", (1, "β")),
|
|
121 |
("\\<gamma>", (1, "γ")),
|
|
122 |
("\\<delta>", (1, "δ")),
|
|
123 |
("\\<epsilon>", (1, "ε")),
|
|
124 |
("\\<zeta>", (1, "ζ")),
|
|
125 |
("\\<eta>", (1, "η")),
|
|
126 |
("\\<theta>", (1, "ϑ")),
|
|
127 |
("\\<iota>", (1, "ι")),
|
|
128 |
("\\<kappa>", (1, "κ")),
|
|
129 |
("\\<lambda>", (1, "λ")),
|
|
130 |
("\\<mu>", (1, "μ")),
|
|
131 |
("\\<nu>", (1, "ν")),
|
|
132 |
("\\<xi>", (1, "ξ")),
|
|
133 |
("\\<omicron>", (1, "ο")),
|
|
134 |
("\\<pi>", (1, "π")),
|
|
135 |
("\\<rho>", (1, "ρ")),
|
|
136 |
("\\<sigma>", (1, "σ")),
|
|
137 |
("\\<tau>", (1, "τ")),
|
|
138 |
("\\<upsilon>", (1, "υ")),
|
|
139 |
("\\<phi>", (1, "φ")),
|
|
140 |
("\\<chi>", (1, "χ")),
|
|
141 |
("\\<psi>", (1, "ψ")),
|
|
142 |
("\\<omega>", (1, "ω")),
|
|
143 |
("\\<bullet>", (1, "•")),
|
|
144 |
("\\<dots>", (1, "…")),
|
|
145 |
("\\<Re>", (1, "ℜ")),
|
|
146 |
("\\<Im>", (1, "ℑ")),
|
|
147 |
("\\<wp>", (1, "℘")),
|
|
148 |
("\\<forall>", (1, "∀")),
|
|
149 |
("\\<partial>", (1, "∂")),
|
|
150 |
("\\<exists>", (1, "∃")),
|
|
151 |
("\\<emptyset>", (1, "∅")),
|
|
152 |
("\\<nabla>", (1, "∇")),
|
|
153 |
("\\<in>", (1, "∈")),
|
|
154 |
("\\<notin>", (1, "∉")),
|
|
155 |
("\\<Prod>", (1, "∏")),
|
|
156 |
("\\<Sum>", (1, "∑")),
|
|
157 |
("\\<star>", (1, "∗")),
|
|
158 |
("\\<propto>", (1, "∝")),
|
|
159 |
("\\<infinity>", (1, "∞")),
|
|
160 |
("\\<angle>", (1, "∠")),
|
|
161 |
("\\<and>", (1, "∧")),
|
|
162 |
("\\<or>", (1, "∨")),
|
|
163 |
("\\<inter>", (1, "∩")),
|
|
164 |
("\\<union>", (1, "∪")),
|
|
165 |
("\\<sim>", (1, "∼")),
|
|
166 |
("\\<cong>", (1, "≅")),
|
|
167 |
("\\<approx>", (1, "≈")),
|
|
168 |
("\\<noteq>", (1, "≠")),
|
|
169 |
("\\<equiv>", (1, "≡")),
|
|
170 |
("\\<le>", (1, "≤")),
|
|
171 |
("\\<ge>", (1, "≥")),
|
|
172 |
("\\<subset>", (1, "⊂")),
|
|
173 |
("\\<supset>", (1, "⊃")),
|
|
174 |
("\\<subseteq>", (1, "⊆")),
|
|
175 |
("\\<supseteq>", (1, "⊇")),
|
|
176 |
("\\<oplus>", (1, "⊕")),
|
|
177 |
("\\<otimes>", (1, "⊗")),
|
|
178 |
("\\<bottom>", (1, "⊥")),
|
|
179 |
("\\<lceil>", (1, "⌈")),
|
|
180 |
("\\<rceil>", (1, "⌉")),
|
|
181 |
("\\<lfloor>", (1, "⌊")),
|
|
182 |
("\\<rfloor>", (1, "⌋")),
|
|
183 |
("\\<langle>", (1, "⟨")),
|
|
184 |
("\\<rangle>", (1, "⟩")),
|
|
185 |
("\\<lozenge>", (1, "◊")),
|
|
186 |
("\\<spadesuit>", (1, "♠")),
|
|
187 |
("\\<clubsuit>", (1, "♣")),
|
|
188 |
("\\<heartsuit>", (1, "♥")),
|
|
189 |
("\\<diamondsuit>", (1, "♦")),
|
|
190 |
("\\<lbrakk>", (2, "[|")),
|
|
191 |
("\\<rbrakk>", (2, "|]")),
|
|
192 |
("\\<Longrightarrow>", (3, "==>")),
|
|
193 |
("\\<Rightarrow>", (2, "=>")),
|
|
194 |
("\\<And>", (2, "!!")),
|
|
195 |
("\\<Colon>", (2, "::")),
|
|
196 |
("\\<lparr>", (2, "(|")),
|
|
197 |
("\\<rparr>", (2, "|)),")),
|
|
198 |
("\\<longleftrightarrow>", (3, "<->")),
|
|
199 |
("\\<longrightarrow>", (3, "-->")),
|
|
200 |
("\\<rightarrow>", (2, "->")),
|
|
201 |
("\\<^bsub>", (0, "<sub>")),
|
|
202 |
("\\<^esub>", (0, "</sub>")),
|
|
203 |
("\\<^bsup>", (0, "<sup>")),
|
|
204 |
("\\<^esup>", (0, "</sup>"))];
|
|
| 17178 | 205 |
|
206 |
val escape = fn "<" => "<" | ">" => ">" | "&" => "&" | c => c; |
|
| 16196 | 207 |
|
208 |
fun output_sym s = |
|
| 23622 | 209 |
if Symbol.is_raw s then (1, Symbol.decode_raw s) |
| 20742 | 210 |
else |
211 |
(case Symtab.lookup html_syms s of SOME x => x |
|
| 23622 | 212 |
| NONE => (size s, translate_string escape s)); |
| 6324 | 213 |
|
| 17178 | 214 |
fun output_sub s = apsnd (enclose "<sub>" "</sub>") (output_sym s); |
215 |
fun output_sup s = apsnd (enclose "<sup>" "</sup>") (output_sym s); |
|
216 |
fun output_loc s = apsnd (enclose "<span class=\"loc\">" "</span>") (output_sym s); |
|
| 14534 | 217 |
|
| 17178 | 218 |
fun output_syms ("\\<^sub>" :: s :: ss) = output_sub s :: output_syms ss
|
219 |
| output_syms ("\\<^isub>" :: s :: ss) = output_sub s :: output_syms ss
|
|
220 |
| output_syms ("\\<^sup>" :: s :: ss) = output_sup s :: output_syms ss
|
|
221 |
| output_syms ("\\<^isup>" :: s :: ss) = output_sup s :: output_syms ss
|
|
222 |
| output_syms ("\\<^loc>" :: s :: ss) = output_loc s :: output_syms ss
|
|
223 |
| output_syms (s :: ss) = output_sym s :: output_syms ss |
|
224 |
| output_syms [] = []; |
|
| 6338 | 225 |
in |
| 6324 | 226 |
|
| 6338 | 227 |
fun output_width str = |
| 19305 | 228 |
if not (exists_string (fn s => s = "\\" orelse s = "<" orelse s = ">" orelse s = "&") str) |
| 23622 | 229 |
then Output.default_output str |
| 6338 | 230 |
else |
| 17178 | 231 |
let val (syms, width) = fold_map (fn (w, s) => fn width => (s, w + width)) |
| 23622 | 232 |
(output_syms (Symbol.explode str)) 0 |
| 17178 | 233 |
in (implode syms, width) end; |
| 6338 | 234 |
|
235 |
val output = #1 o output_width; |
|
| 17178 | 236 |
val output_symbols = map #2 o output_syms; |
| 6338 | 237 |
|
238 |
end; |
|
239 |
||
| 6324 | 240 |
|
| 23622 | 241 |
(* markup and token translations *) |
242 |
||
243 |
fun span s = ("<span class=" ^ Library.quote s ^ ">", "</span>");
|
|
244 |
||
245 |
fun style s = apfst (span s |-> enclose) o output_width; |
|
| 6324 | 246 |
|
| 23622 | 247 |
fun free_or_skolem x = |
248 |
(case try Name.dest_skolem x of |
|
249 |
NONE => style "free" x |
|
250 |
| SOME x' => style "skolem" x'); |
|
251 |
||
252 |
fun var_or_skolem s = |
|
253 |
(case Syntax.read_variable s of |
|
254 |
SOME (x, i) => |
|
255 |
(case try Name.dest_skolem x of |
|
256 |
NONE => style "var" s |
|
257 |
| SOME x' => style "skolem" |
|
258 |
(setmp show_question_marks true Term.string_of_vname (x', i))) |
|
259 |
| NONE => style "var" s); |
|
| 6324 | 260 |
|
261 |
val html_trans = |
|
| 14541 | 262 |
[("class", style "tclass"),
|
263 |
("tfree", style "tfree"),
|
|
264 |
("tvar", style "tvar"),
|
|
| 23622 | 265 |
("free", free_or_skolem),
|
| 14541 | 266 |
("bound", style "bound"),
|
| 23622 | 267 |
("var", var_or_skolem),
|
| 14541 | 268 |
("xstr", style "xstr")];
|
| 6324 | 269 |
|
| 22796 | 270 |
val _ = Context.add_setup (Sign.add_mode_tokentrfuns htmlN html_trans); |
| 15801 | 271 |
|
| 6324 | 272 |
|
273 |
||
274 |
(** HTML markup **) |
|
275 |
||
276 |
type text = string; |
|
277 |
||
278 |
||
279 |
(* atoms *) |
|
280 |
||
281 |
val plain = output; |
|
| 19265 | 282 |
val name = enclose "<span class=\"name\">" "</span>" o output; |
283 |
val keyword = enclose "<span class=\"keyword\">" "</span>" o output; |
|
| 23622 | 284 |
val command = enclose "<span class=\"command\">" "</span>" o output; |
| 19265 | 285 |
val file_name = enclose "<span class=\"filename\">" "</span>" o output; |
|
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
20742
diff
changeset
|
286 |
val file_path = file_name o Url.implode; |
| 6324 | 287 |
|
288 |
||
289 |
(* misc *) |
|
290 |
||
|
14598
7009f59711e3
Replaced quote by Library.quote, since quote now refers to Symbol.quote
berghofe
parents:
14571
diff
changeset
|
291 |
fun href_name s txt = "<a href=" ^ Library.quote s ^ ">" ^ txt ^ "</a>"; |
|
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
20742
diff
changeset
|
292 |
fun href_path path txt = href_name (Url.implode path) txt; |
| 6376 | 293 |
|
| 15531 | 294 |
fun href_opt_name NONE txt = txt |
295 |
| href_opt_name (SOME s) txt = href_name s txt; |
|
| 6376 | 296 |
|
| 15531 | 297 |
fun href_opt_path NONE txt = txt |
298 |
| href_opt_path (SOME p) txt = href_path p txt; |
|
| 6376 | 299 |
|
| 12413 | 300 |
fun para txt = "\n<p>" ^ txt ^ "</p>\n"; |
| 6324 | 301 |
fun preform txt = "<pre>" ^ txt ^ "</pre>"; |
302 |
val verbatim = preform o output; |
|
303 |
||
304 |
||
305 |
(* document *) |
|
306 |
||
|
17470
6e9d910c3837
added with_charset: string -> ('a -> 'b) -> 'a -> 'b;
wenzelm
parents:
17412
diff
changeset
|
307 |
val charset = ref "iso-8859-1"; |
|
6e9d910c3837
added with_charset: string -> ('a -> 'b) -> 'a -> 'b;
wenzelm
parents:
17412
diff
changeset
|
308 |
fun with_charset s = setmp charset s; |
|
6e9d910c3837
added with_charset: string -> ('a -> 'b) -> 'a -> 'b;
wenzelm
parents:
17412
diff
changeset
|
309 |
|
| 6324 | 310 |
fun begin_document title = |
| 17080 | 311 |
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \ |
312 |
\\"http://www.w3.org/TR/html4/loose.dtd\">\n\ |
|
|
14083
aed5d25c4a0c
Added DOCTYPE and Content-type to HTML documents.
webertj
parents:
13531
diff
changeset
|
313 |
\\n\ |
|
aed5d25c4a0c
Added DOCTYPE and Content-type to HTML documents.
webertj
parents:
13531
diff
changeset
|
314 |
\<html>\n\ |
| 6405 | 315 |
\<head>\n\ |
|
17470
6e9d910c3837
added with_charset: string -> ('a -> 'b) -> 'a -> 'b;
wenzelm
parents:
17412
diff
changeset
|
316 |
\<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" ^ ! charset ^ "\">\n\ |
| 6405 | 317 |
\<title>" ^ plain (title ^ " (" ^ version ^ ")") ^ "</title>\n\
|
| 14541 | 318 |
\<link rel=\"stylesheet\" type=\"text/css\" href=\"isabelle.css\">\n\ |
| 6405 | 319 |
\</head>\n\ |
320 |
\\n\ |
|
321 |
\<body>\n\ |
|
| 14541 | 322 |
\<div class=\"head\">\ |
| 6405 | 323 |
\<h1>" ^ plain title ^ "</h1>\n" |
| 6324 | 324 |
|
| 14541 | 325 |
val end_document = "\n</div>\n</body>\n</html>\n"; |
| 6324 | 326 |
|
| 6754 | 327 |
fun gen_link how (path, name) = para (href_path path how ^ " to index of " ^ plain name); |
328 |
val up_link = gen_link "Up"; |
|
329 |
val back_link = gen_link "Back"; |
|
| 6338 | 330 |
|
331 |
||
332 |
(* session index *) |
|
333 |
||
| 17080 | 334 |
fun begin_index up (index_path, session) docs graph = |
| 6754 | 335 |
begin_document ("Index of " ^ session) ^ up_link up ^
|
336 |
para ("View " ^ href_path graph "theory dependencies" ^
|
|
| 17080 | 337 |
implode (map (fn (p, name) => "<br>\nView " ^ href_path p name) docs)) ^ |
| 14541 | 338 |
"\n</div>\n<hr>\n<div class=\"theories\">\n<h2>Theories</h2>\n<ul>\n"; |
| 6338 | 339 |
|
340 |
val end_index = end_document; |
|
341 |
||
| 6649 | 342 |
fun choice chs s = space_implode " " (map (fn (s', lnk) => |
343 |
enclose "[" "]" (if s = s' then keyword s' else href_name lnk s')) chs); |
|
344 |
||
| 9415 | 345 |
fun applet_pages session back = |
| 6649 | 346 |
let |
| 9415 | 347 |
val sizes = |
348 |
[("small", "small.html", ("500", "400")),
|
|
349 |
("medium", "medium.html", ("650", "520")),
|
|
350 |
("large", "large.html", ("800", "640"))];
|
|
| 6649 | 351 |
|
| 9415 | 352 |
fun applet_page (size, name, (width, height)) = |
| 6754 | 353 |
let |
354 |
val browser_size = "Set browser size: " ^ |
|
| 9415 | 355 |
choice (map (fn (y, z, _) => (y, z)) sizes) size; |
| 6754 | 356 |
in |
357 |
(name, begin_document ("Theory dependencies of " ^ session) ^
|
|
358 |
back_link back ^ |
|
| 9415 | 359 |
para browser_size ^ |
| 17080 | 360 |
"\n</div>\n<hr>\n<div class=\"graphbrowser\">\n\ |
361 |
\<applet code=\"GraphBrowser/GraphBrowser.class\" \ |
|
| 14541 | 362 |
\archive=\"GraphBrowser.jar\" \ |
| 9045 | 363 |
\width=" ^ width ^ " height=" ^ height ^ ">\n\ |
| 9415 | 364 |
\<param name=\"graphfile\" value=\"" ^ "session.graph" ^ "\">\n\ |
| 6754 | 365 |
\</applet>\n<hr>" ^ end_document) |
| 6649 | 366 |
end; |
| 9415 | 367 |
in map applet_page sizes end; |
| 6649 | 368 |
|
369 |
||
| 6405 | 370 |
fun entry (p, s) = "<li>" ^ href_path p (plain s) ^ "\n"; |
371 |
||
| 6338 | 372 |
val theory_entry = entry; |
373 |
||
| 6405 | 374 |
fun session_entries [] = "</ul>" |
375 |
| session_entries es = |
|
| 17080 | 376 |
"</ul>\n</div>\n<hr>\n<div class=\"sessions\">\n\ |
377 |
\<h2>Sessions</h2>\n<ul>\n" ^ implode (map entry es) ^ "</ul>"; |
|
| 6324 | 378 |
|
379 |
||
380 |
(* theory *) |
|
381 |
||
| 14571 | 382 |
fun verbatim_source ss = |
383 |
"\n</div>\n<hr>\n<div class=\"source\">\n<pre>" ^ |
|
| 17178 | 384 |
implode (output_symbols ss) ^ |
| 14571 | 385 |
"</pre>\n</div>\n<hr>\n<div class=\"theorems\">\n"; |
| 6324 | 386 |
|
387 |
||
388 |
local |
|
| 15531 | 389 |
fun encl NONE = enclose "[" "]" |
390 |
| encl (SOME false) = enclose "(" ")"
|
|
391 |
| encl (SOME true) = I; |
|
| 6324 | 392 |
|
| 7408 | 393 |
fun file (opt_ref, path, loadit) = href_opt_path opt_ref (encl loadit (file_path path)); |
| 6361 | 394 |
|
| 6376 | 395 |
fun theory up A = |
396 |
begin_document ("Theory " ^ A) ^ "\n" ^ up_link up ^
|
|
| 23622 | 397 |
command "theory" ^ " " ^ name A; |
|
16267
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
398 |
|
|
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
399 |
fun imports Bs = |
|
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
400 |
keyword "imports" ^ " " ^ space_implode " " (map (uncurry href_opt_path o apsnd name) Bs); |
|
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
401 |
|
| 17209 | 402 |
fun uses Ps = keyword "uses" ^ " " ^ space_implode " " (map file Ps) ^ "<br>\n"; |
| 6324 | 403 |
in |
404 |
||
|
16267
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
405 |
fun begin_theory up A Bs Ps body = |
|
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
406 |
theory up A ^ "<br>\n" ^ |
|
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
407 |
imports Bs ^ "<br>\n" ^ |
|
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
408 |
(if null Ps then "" else uses Ps) ^ |
|
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
409 |
keyword "begin" ^ "<br>\n" ^ |
|
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
410 |
body; |
|
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
411 |
|
| 6324 | 412 |
end; |
413 |
||
| 6338 | 414 |
val end_theory = end_document; |
| 6324 | 415 |
|
416 |
||
417 |
(* ML file *) |
|
418 |
||
419 |
fun ml_file path str = |
|
|
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
20742
diff
changeset
|
420 |
begin_document ("File " ^ Url.implode path) ^
|
| 14571 | 421 |
"\n</div>\n<hr><div class=\"mlsource\">\n" ^ |
422 |
verbatim str ^ |
|
423 |
"\n</div>\n<hr>\n<div class=\"mlfooter\">\n" ^ |
|
| 14541 | 424 |
end_document; |
| 6324 | 425 |
|
426 |
||
| 7408 | 427 |
(* theorems *) |
| 6324 | 428 |
|
| 7572 | 429 |
local |
430 |
||
| 22122 | 431 |
fun string_of_thm ctxt = |
|
14839
c994f1c57fc7
handle raw symbols; Output.add_mode; more robust handling of sub/superscript;
wenzelm
parents:
14775
diff
changeset
|
432 |
Output.output o Pretty.setmp_margin 80 Pretty.string_of o |
| 22122 | 433 |
setmp show_question_marks false (ProofContext.pretty_thm ctxt); |
| 6324 | 434 |
|
| 22122 | 435 |
fun thm ctxt th = preform (prefix_lines " " (html_mode (string_of_thm ctxt) th)); |
| 7408 | 436 |
|
| 7572 | 437 |
fun thm_name "" = "" |
438 |
| thm_name a = " " ^ name (a ^ ":"); |
|
439 |
||
440 |
in |
|
441 |
||
| 23622 | 442 |
fun result ctxt k (a, ths) = para (cat_lines ((command k ^ thm_name a) :: map (thm ctxt) ths)); |
| 7572 | 443 |
|
| 22122 | 444 |
fun results _ _ [] = "" |
445 |
| results ctxt k (res :: ress) = cat_lines (result ctxt k res :: map (result ctxt "and") ress); |
|
| 7572 | 446 |
|
447 |
end; |
|
| 6324 | 448 |
|
449 |
||
| 7634 | 450 |
(* sections *) |
| 6324 | 451 |
|
| 8088 | 452 |
fun chapter heading = "\n\n<h1>" ^ plain heading ^ "</h1>\n"; |
| 6324 | 453 |
fun section heading = "\n\n<h2>" ^ plain heading ^ "</h2>\n"; |
| 7634 | 454 |
fun subsection heading = "\n\n<h3>" ^ plain heading ^ "</h3>\n"; |
455 |
fun subsubsection heading = "\n\n<h4>" ^ plain heading ^ "</h4>\n"; |
|
| 6324 | 456 |
|
457 |
||
| 19265 | 458 |
(* mode output *) |
459 |
||
| 23622 | 460 |
val _ = Output.add_mode htmlN output_width Symbol.encode_raw; |
| 23703 | 461 |
val _ = Markup.add_mode htmlN (span o #1); |
| 19265 | 462 |
|
| 6324 | 463 |
end; |