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