| author | wenzelm | 
| Thu, 21 Sep 2006 19:05:01 +0200 | |
| changeset 20670 | 115262dd18e2 | 
| parent 20576 | 8b1591393b8d | 
| child 20742 | 2233f6afc491 | 
| 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 = | |
| 20576 
8b1591393b8d
output: uninterpreted raw symbols -- these are usually LaTeX macros;
 wenzelm parents: 
20253diff
changeset | 207 | (case Symtab.lookup html_syms s of | 
| 
8b1591393b8d
output: uninterpreted raw symbols -- these are usually LaTeX macros;
 wenzelm parents: 
20253diff
changeset | 208 | SOME x => x | 
| 
8b1591393b8d
output: uninterpreted raw symbols -- these are usually LaTeX macros;
 wenzelm parents: 
20253diff
changeset | 209 | | NONE => (real (size s), translate_string escape s)); | 
| 6324 | 210 | |
| 17178 | 211 | fun output_sub s = apsnd (enclose "<sub>" "</sub>") (output_sym s); | 
| 212 | fun output_sup s = apsnd (enclose "<sup>" "</sup>") (output_sym s); | |
| 213 | fun output_loc s = apsnd (enclose "<span class=\"loc\">" "</span>") (output_sym s); | |
| 14534 | 214 | |
| 17178 | 215 |   fun output_syms ("\\<^sub>" :: s :: ss) = output_sub s :: output_syms ss
 | 
| 216 |     | output_syms ("\\<^isub>" :: s :: ss) = output_sub s :: output_syms ss
 | |
| 217 |     | output_syms ("\\<^sup>" :: s :: ss) = output_sup s :: output_syms ss
 | |
| 218 |     | output_syms ("\\<^isup>" :: s :: ss) = output_sup s :: output_syms ss
 | |
| 219 |     | output_syms ("\\<^loc>" :: s :: ss) = output_loc s :: output_syms ss
 | |
| 220 | | output_syms (s :: ss) = output_sym s :: output_syms ss | |
| 221 | | output_syms [] = []; | |
| 6338 | 222 | in | 
| 6324 | 223 | |
| 6338 | 224 | fun output_width str = | 
| 19305 | 225 | if not (exists_string (fn s => s = "\\" orelse s = "<" orelse s = ">" orelse s = "&") str) | 
| 14992 | 226 | then Symbol.default_output str | 
| 6338 | 227 | else | 
| 17178 | 228 | let val (syms, width) = fold_map (fn (w, s) => fn width => (s, w + width)) | 
| 229 | (output_syms (Symbol.explode str)) 0.0 | |
| 230 | in (implode syms, width) end; | |
| 6338 | 231 | |
| 232 | val output = #1 o output_width; | |
| 17178 | 233 | val output_symbols = map #2 o output_syms; | 
| 6338 | 234 | |
| 235 | end; | |
| 236 | ||
| 6324 | 237 | |
| 238 | (* token translations *) | |
| 239 | ||
| 16196 | 240 | fun style s = | 
| 241 |   apfst (enclose ("<span class=" ^ Library.quote s ^ ">") "</span>") o output_width;
 | |
| 6324 | 242 | |
| 243 | val html_trans = | |
| 14541 | 244 |  [("class", style "tclass"),
 | 
| 245 |   ("tfree", style "tfree"),
 | |
| 246 |   ("tvar",  style "tvar"),
 | |
| 247 |   ("free",  style "free"),
 | |
| 248 |   ("bound", style "bound"),
 | |
| 249 |   ("var",   style "var"),
 | |
| 250 |   ("xstr",  style "xstr")];
 | |
| 6324 | 251 | |
| 18708 | 252 | val _ = Context.add_setup (Theory.add_mode_tokentrfuns htmlN html_trans); | 
| 15801 | 253 | |
| 6324 | 254 | |
| 255 | ||
| 256 | (** HTML markup **) | |
| 257 | ||
| 258 | type text = string; | |
| 259 | ||
| 260 | ||
| 261 | (* atoms *) | |
| 262 | ||
| 263 | val plain = output; | |
| 19265 | 264 | val name = enclose "<span class=\"name\">" "</span>" o output; | 
| 265 | val keyword = enclose "<span class=\"keyword\">" "</span>" o output; | |
| 266 | val keyword_width = apfst (enclose "<span class=\"keyword\">" "</span>") o output_width; | |
| 267 | val file_name = enclose "<span class=\"filename\">" "</span>" o output; | |
| 6649 | 268 | val file_path = file_name o Url.pack; | 
| 6324 | 269 | |
| 270 | ||
| 271 | (* misc *) | |
| 272 | ||
| 14598 
7009f59711e3
Replaced quote by Library.quote, since quote now refers to Symbol.quote
 berghofe parents: 
14571diff
changeset | 273 | fun href_name s txt = "<a href=" ^ Library.quote s ^ ">" ^ txt ^ "</a>"; | 
| 6649 | 274 | fun href_path path txt = href_name (Url.pack path) txt; | 
| 6376 | 275 | |
| 15531 | 276 | fun href_opt_name NONE txt = txt | 
| 277 | | href_opt_name (SOME s) txt = href_name s txt; | |
| 6376 | 278 | |
| 15531 | 279 | fun href_opt_path NONE txt = txt | 
| 280 | | href_opt_path (SOME p) txt = href_path p txt; | |
| 6376 | 281 | |
| 12413 | 282 | fun para txt = "\n<p>" ^ txt ^ "</p>\n"; | 
| 6324 | 283 | fun preform txt = "<pre>" ^ txt ^ "</pre>"; | 
| 284 | val verbatim = preform o output; | |
| 285 | ||
| 286 | ||
| 287 | (* document *) | |
| 288 | ||
| 17470 
6e9d910c3837
added with_charset: string -> ('a -> 'b) -> 'a -> 'b;
 wenzelm parents: 
17412diff
changeset | 289 | val charset = ref "iso-8859-1"; | 
| 
6e9d910c3837
added with_charset: string -> ('a -> 'b) -> 'a -> 'b;
 wenzelm parents: 
17412diff
changeset | 290 | fun with_charset s = setmp charset s; | 
| 
6e9d910c3837
added with_charset: string -> ('a -> 'b) -> 'a -> 'b;
 wenzelm parents: 
17412diff
changeset | 291 | |
| 6324 | 292 | fun begin_document title = | 
| 17080 | 293 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \ | 
| 294 | \\"http://www.w3.org/TR/html4/loose.dtd\">\n\ | |
| 14083 
aed5d25c4a0c
Added DOCTYPE and Content-type to HTML documents.
 webertj parents: 
13531diff
changeset | 295 | \\n\ | 
| 
aed5d25c4a0c
Added DOCTYPE and Content-type to HTML documents.
 webertj parents: 
13531diff
changeset | 296 | \<html>\n\ | 
| 6405 | 297 | \<head>\n\ | 
| 17470 
6e9d910c3837
added with_charset: string -> ('a -> 'b) -> 'a -> 'b;
 wenzelm parents: 
17412diff
changeset | 298 | \<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" ^ ! charset ^ "\">\n\ | 
| 6405 | 299 |   \<title>" ^ plain (title ^ " (" ^ version ^ ")") ^ "</title>\n\
 | 
| 14541 | 300 | \<link rel=\"stylesheet\" type=\"text/css\" href=\"isabelle.css\">\n\ | 
| 6405 | 301 | \</head>\n\ | 
| 302 | \\n\ | |
| 303 | \<body>\n\ | |
| 14541 | 304 | \<div class=\"head\">\ | 
| 6405 | 305 | \<h1>" ^ plain title ^ "</h1>\n" | 
| 6324 | 306 | |
| 14541 | 307 | val end_document = "\n</div>\n</body>\n</html>\n"; | 
| 6324 | 308 | |
| 6754 | 309 | fun gen_link how (path, name) = para (href_path path how ^ " to index of " ^ plain name); | 
| 310 | val up_link = gen_link "Up"; | |
| 311 | val back_link = gen_link "Back"; | |
| 6338 | 312 | |
| 313 | ||
| 314 | (* session index *) | |
| 315 | ||
| 17080 | 316 | fun begin_index up (index_path, session) docs graph = | 
| 6754 | 317 |   begin_document ("Index of " ^ session) ^ up_link up ^
 | 
| 318 |   para ("View " ^ href_path graph "theory dependencies" ^
 | |
| 17080 | 319 | implode (map (fn (p, name) => "<br>\nView " ^ href_path p name) docs)) ^ | 
| 14541 | 320 | "\n</div>\n<hr>\n<div class=\"theories\">\n<h2>Theories</h2>\n<ul>\n"; | 
| 6338 | 321 | |
| 322 | val end_index = end_document; | |
| 323 | ||
| 6649 | 324 | fun choice chs s = space_implode " " (map (fn (s', lnk) => | 
| 325 | enclose "[" "]" (if s = s' then keyword s' else href_name lnk s')) chs); | |
| 326 | ||
| 9415 | 327 | fun applet_pages session back = | 
| 6649 | 328 | let | 
| 9415 | 329 | val sizes = | 
| 330 |      [("small", "small.html", ("500", "400")),
 | |
| 331 |       ("medium", "medium.html", ("650", "520")),
 | |
| 332 |       ("large", "large.html", ("800", "640"))];
 | |
| 6649 | 333 | |
| 9415 | 334 | fun applet_page (size, name, (width, height)) = | 
| 6754 | 335 | let | 
| 336 | val browser_size = "Set browser size: " ^ | |
| 9415 | 337 | choice (map (fn (y, z, _) => (y, z)) sizes) size; | 
| 6754 | 338 | in | 
| 339 |         (name, begin_document ("Theory dependencies of " ^ session) ^
 | |
| 340 | back_link back ^ | |
| 9415 | 341 | para browser_size ^ | 
| 17080 | 342 | "\n</div>\n<hr>\n<div class=\"graphbrowser\">\n\ | 
| 343 | \<applet code=\"GraphBrowser/GraphBrowser.class\" \ | |
| 14541 | 344 | \archive=\"GraphBrowser.jar\" \ | 
| 9045 | 345 | \width=" ^ width ^ " height=" ^ height ^ ">\n\ | 
| 9415 | 346 | \<param name=\"graphfile\" value=\"" ^ "session.graph" ^ "\">\n\ | 
| 6754 | 347 | \</applet>\n<hr>" ^ end_document) | 
| 6649 | 348 | end; | 
| 9415 | 349 | in map applet_page sizes end; | 
| 6649 | 350 | |
| 351 | ||
| 6405 | 352 | fun entry (p, s) = "<li>" ^ href_path p (plain s) ^ "\n"; | 
| 353 | ||
| 6338 | 354 | val theory_entry = entry; | 
| 355 | ||
| 6405 | 356 | fun session_entries [] = "</ul>" | 
| 357 | | session_entries es = | |
| 17080 | 358 | "</ul>\n</div>\n<hr>\n<div class=\"sessions\">\n\ | 
| 359 | \<h2>Sessions</h2>\n<ul>\n" ^ implode (map entry es) ^ "</ul>"; | |
| 6324 | 360 | |
| 361 | ||
| 362 | (* theory *) | |
| 363 | ||
| 14571 | 364 | fun verbatim_source ss = | 
| 365 | "\n</div>\n<hr>\n<div class=\"source\">\n<pre>" ^ | |
| 17178 | 366 | implode (output_symbols ss) ^ | 
| 14571 | 367 | "</pre>\n</div>\n<hr>\n<div class=\"theorems\">\n"; | 
| 6324 | 368 | |
| 369 | ||
| 370 | local | |
| 15531 | 371 | fun encl NONE = enclose "[" "]" | 
| 372 |     | encl (SOME false) = enclose "(" ")"
 | |
| 373 | | encl (SOME true) = I; | |
| 6324 | 374 | |
| 7408 | 375 | fun file (opt_ref, path, loadit) = href_opt_path opt_ref (encl loadit (file_path path)); | 
| 6361 | 376 | |
| 6376 | 377 | fun theory up A = | 
| 378 |     begin_document ("Theory " ^ A) ^ "\n" ^ up_link up ^
 | |
| 16267 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 379 | keyword "theory" ^ " " ^ name A; | 
| 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 380 | |
| 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 381 | fun imports Bs = | 
| 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 382 | 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 | 383 | |
| 17209 | 384 | fun uses Ps = keyword "uses" ^ " " ^ space_implode " " (map file Ps) ^ "<br>\n"; | 
| 6324 | 385 | in | 
| 386 | ||
| 16267 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 387 | fun begin_theory up A Bs Ps body = | 
| 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 388 | theory up A ^ "<br>\n" ^ | 
| 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 389 | imports Bs ^ "<br>\n" ^ | 
| 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 390 | (if null Ps then "" else uses Ps) ^ | 
| 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 391 | keyword "begin" ^ "<br>\n" ^ | 
| 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 392 | body; | 
| 
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
 wenzelm parents: 
16196diff
changeset | 393 | |
| 6324 | 394 | end; | 
| 395 | ||
| 6338 | 396 | val end_theory = end_document; | 
| 6324 | 397 | |
| 398 | ||
| 399 | (* ML file *) | |
| 400 | ||
| 401 | fun ml_file path str = | |
| 6649 | 402 |   begin_document ("File " ^ Url.pack path) ^
 | 
| 14571 | 403 | "\n</div>\n<hr><div class=\"mlsource\">\n" ^ | 
| 404 | verbatim str ^ | |
| 405 | "\n</div>\n<hr>\n<div class=\"mlfooter\">\n" ^ | |
| 14541 | 406 | end_document; | 
| 6324 | 407 | |
| 408 | ||
| 7408 | 409 | (* theorems *) | 
| 6324 | 410 | |
| 7572 | 411 | local | 
| 412 | ||
| 7408 | 413 | val string_of_thm = | 
| 14839 
c994f1c57fc7
handle raw symbols; Output.add_mode; more robust handling of sub/superscript;
 wenzelm parents: 
14775diff
changeset | 414 | Output.output o Pretty.setmp_margin 80 Pretty.string_of o | 
| 20253 | 415 | setmp show_question_marks false (ProofContext.pretty_thm_legacy false); | 
| 6324 | 416 | |
| 417 | fun thm th = preform (prefix_lines " " (html_mode string_of_thm th)); | |
| 7408 | 418 | |
| 7572 | 419 | fun thm_name "" = "" | 
| 420 | | thm_name a = " " ^ name (a ^ ":"); | |
| 421 | ||
| 422 | in | |
| 423 | ||
| 13531 | 424 | fun result k (a, ths) = para (cat_lines ((keyword k ^ thm_name a) :: map thm ths)); | 
| 7572 | 425 | |
| 13531 | 426 | fun results _ [] = "" | 
| 427 | | results k (res :: ress) = cat_lines (result k res :: map (result "and") ress); | |
| 7572 | 428 | |
| 429 | end; | |
| 6324 | 430 | |
| 431 | ||
| 7634 | 432 | (* sections *) | 
| 6324 | 433 | |
| 8088 | 434 | fun chapter heading = "\n\n<h1>" ^ plain heading ^ "</h1>\n"; | 
| 6324 | 435 | fun section heading = "\n\n<h2>" ^ plain heading ^ "</h2>\n"; | 
| 7634 | 436 | fun subsection heading = "\n\n<h3>" ^ plain heading ^ "</h3>\n"; | 
| 437 | fun subsubsection heading = "\n\n<h4>" ^ plain heading ^ "</h4>\n"; | |
| 6324 | 438 | |
| 439 | ||
| 19265 | 440 | (* mode output *) | 
| 441 | ||
| 442 | val _ = Output.add_mode htmlN | |
| 443 | (output_width, K keyword_width, Symbol.default_indent, Symbol.encode_raw); | |
| 444 | ||
| 6324 | 445 | end; |