src/Pure/Thy/html.ML
author kleing
Wed Apr 14 14:13:05 2004 +0200 (2004-04-14)
changeset 14565 c6dc17aab88a
parent 14558 726f6761c562
child 14571 b88d5f9e02e1
permissions -rw-r--r--
use more symbols in HTML output
wenzelm@6324
     1
(*  Title:      Pure/Thy/HTML.ML
wenzelm@6324
     2
    ID:         $Id$
wenzelm@9415
     3
    Author:     Markus Wenzel and Stefan Berghofer, TU Muenchen
wenzelm@8808
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
wenzelm@6324
     5
wenzelm@9415
     6
HTML presentation elements.
wenzelm@6324
     7
*)
wenzelm@6324
     8
wenzelm@6324
     9
signature HTML =
wenzelm@6324
    10
sig
wenzelm@6324
    11
  val output: string -> string
wenzelm@6324
    12
  val output_width: string -> string * real
wenzelm@6324
    13
  type text (* = string *)
wenzelm@6324
    14
  val plain: string -> text
wenzelm@6324
    15
  val name: string -> text
wenzelm@6324
    16
  val keyword: string -> text
wenzelm@6324
    17
  val file_name: string -> text
berghofe@6649
    18
  val file_path: Url.T -> text
wenzelm@6324
    19
  val href_name: string -> text -> text
berghofe@6649
    20
  val href_path: Url.T -> text -> text
wenzelm@6376
    21
  val href_opt_name: string option -> text -> text
berghofe@6649
    22
  val href_opt_path: Url.T option -> text -> text
wenzelm@6376
    23
  val para: text -> text
wenzelm@6324
    24
  val preform: text -> text
wenzelm@6324
    25
  val verbatim: string -> text
wenzelm@7725
    26
  val begin_index: Url.T * string -> Url.T * string -> Url.T option
wenzelm@7725
    27
    -> Url.T option -> Url.T -> text
wenzelm@6338
    28
  val end_index: text
wenzelm@9415
    29
  val applet_pages: string -> Url.T * string -> (string * string) list
berghofe@6649
    30
  val theory_entry: Url.T * string -> text
berghofe@6649
    31
  val session_entries: (Url.T * string) list -> text
wenzelm@8190
    32
  val verbatim_source: Symbol.symbol list -> text
berghofe@6649
    33
  val begin_theory: Url.T * string -> string -> (Url.T option * string) list ->
wenzelm@7408
    34
    (Url.T option * Url.T * bool option) list -> text -> text
wenzelm@6324
    35
  val end_theory: text
berghofe@6649
    36
  val ml_file: Url.T -> string -> text
wenzelm@13531
    37
  val results: string -> (string * thm list) list -> text
wenzelm@8088
    38
  val chapter: string -> text
wenzelm@6324
    39
  val section: string -> text
wenzelm@7634
    40
  val subsection: string -> text
wenzelm@7634
    41
  val subsubsection: string -> text
wenzelm@6324
    42
  val setup: (theory -> theory) list
wenzelm@6324
    43
end;
wenzelm@6324
    44
wenzelm@6324
    45
structure HTML: HTML =
wenzelm@6324
    46
struct
wenzelm@6324
    47
wenzelm@6324
    48
wenzelm@6324
    49
(** HTML print modes **)
wenzelm@6324
    50
wenzelm@6324
    51
(* mode *)
wenzelm@6324
    52
wenzelm@6324
    53
val htmlN = "HTML";
wenzelm@10573
    54
fun html_mode f x = setmp print_mode (htmlN :: ! print_mode) f x;
wenzelm@6324
    55
wenzelm@6324
    56
wenzelm@6324
    57
(* symbol output *)
wenzelm@6324
    58
wenzelm@6338
    59
local
wenzelm@6338
    60
  val escape = fn "<" => "&lt;" | ">" => "&gt;" | "&" => "&amp;" | c => c;
wenzelm@6324
    61
wenzelm@6338
    62
  val output_sym =
wenzelm@9963
    63
    fn "\\<spacespace>" => (2.0, "&nbsp;&nbsp;")
wenzelm@9963
    64
     | "\\<exclamdown>" => (1.0, "&iexcl;")
wenzelm@9963
    65
     | "\\<cent>" => (1.0, "&cent;")
wenzelm@9963
    66
     | "\\<pounds>" => (1.0, "&pound;")
wenzelm@9963
    67
     | "\\<currency>" => (1.0, "&curren;")
wenzelm@9963
    68
     | "\\<yen>" => (1.0, "&yen;")
wenzelm@9963
    69
     | "\\<bar>" => (1.0, "&brvbar;")
wenzelm@9963
    70
     | "\\<section>" => (1.0, "&sect;")
wenzelm@10837
    71
     | "\\<dieresis>" => (1.0, "&uml;")
wenzelm@9963
    72
     | "\\<copyright>" => (1.0, "&copy;")
wenzelm@9963
    73
     | "\\<ordfeminine>" => (1.0, "&ordf;")
wenzelm@9963
    74
     | "\\<guillemotleft>" => (1.0, "&laquo;")
wenzelm@9963
    75
     | "\\<not>" => (1.0, "&not;")
wenzelm@6338
    76
     | "\\<hyphen>" => (1.0, "&shy;")
wenzelm@9963
    77
     | "\\<registered>" => (1.0, "&reg;")
wenzelm@10831
    78
     | "\\<inverse>" => (1.0, "&macr;")
wenzelm@9963
    79
     | "\\<degree>" => (1.0, "&deg;")
wenzelm@9963
    80
     | "\\<plusminus>" => (1.0, "&plusmn;")
wenzelm@9963
    81
     | "\\<twosuperior>" => (1.0, "&sup2;")
wenzelm@9963
    82
     | "\\<threesuperior>" => (1.0, "&sup3;")
wenzelm@10837
    83
     | "\\<acute>" => (1.0, "&acute;")
wenzelm@9963
    84
     | "\\<mu>" => (1.0, "&micro;")
wenzelm@9963
    85
     | "\\<paragraph>" => (1.0, "&para;")
wenzelm@6338
    86
     | "\\<cdot>" => (1.0, "&middot;")
wenzelm@10837
    87
     | "\\<cedilla>" => (1.0, "&cedil;")
wenzelm@9963
    88
     | "\\<onesuperior>" => (1.0, "&sup1;")
wenzelm@9963
    89
     | "\\<ordmasculine>" => (1.0, "&ordm;")
wenzelm@9963
    90
     | "\\<guillemotright>" => (1.0, "&raquo;")
wenzelm@9963
    91
     | "\\<onequarter>" => (1.0, "&frac14;")
wenzelm@9963
    92
     | "\\<onehalf>" => (1.0, "&frac12;")
wenzelm@9963
    93
     | "\\<threequarters>" => (1.0, "&frac34;")
wenzelm@9963
    94
     | "\\<questiondown>" => (1.0, "&iquest;")
wenzelm@6338
    95
     | "\\<times>" => (1.0, "&times;")
wenzelm@10837
    96
     | "\\<emptyset>" => (1.0, "&Oslash;")
wenzelm@9963
    97
     | "\\<div>" => (1.0, "&divide;")
kleing@14552
    98
     | "\\<circ>" => (1.0, "&circ;")    
kleing@14552
    99
     | "\\<Alpha>" => (1.0, "&Alpha;")
kleing@14552
   100
     | "\\<Beta>" => (1.0, "&Beta;")
kleing@14552
   101
     | "\\<Gamma>" => (1.0, "&Gamma;")
kleing@14552
   102
     | "\\<Delta>" => (1.0, "&Delta;")
kleing@14552
   103
     | "\\<Epsilon>" => (1.0, "&Epsilon;")
kleing@14552
   104
     | "\\<Zeta>" => (1.0, "&Zeta;")
kleing@14552
   105
     | "\\<Eta>" => (1.0, "&Eta;")
kleing@14552
   106
     | "\\<Theta>" => (1.0, "&Theta;")
kleing@14552
   107
     | "\\<Iota>" => (1.0, "&Iota;")
kleing@14552
   108
     | "\\<Kappa>" => (1.0, "&Kappa;")
kleing@14552
   109
     | "\\<Lambda>" => (1.0, "&Lambda;")
kleing@14552
   110
     | "\\<Mu>" => (1.0, "&Mu;")
kleing@14552
   111
     | "\\<Nu>" => (1.0, "&Nu;")
kleing@14552
   112
     | "\\<Xi>" => (1.0, "&Xi;")
kleing@14552
   113
     | "\\<Omicron>" => (1.0, "&Omicron;")
kleing@14552
   114
     | "\\<Pi>" => (1.0, "&Pi;")
kleing@14552
   115
     | "\\<Rho>" => (1.0, "&Rho;")
kleing@14552
   116
     | "\\<Sigma>" => (1.0, "&Sigma;")
kleing@14552
   117
     | "\\<Tau>" => (1.0, "&Tau;")
kleing@14552
   118
     | "\\<Upsilon>" => (1.0, "&Upsilon;")
kleing@14552
   119
     | "\\<Phi>" => (1.0, "&Phi;")
kleing@14552
   120
     | "\\<Chi>" => (1.0, "&Chi;")
kleing@14552
   121
     | "\\<Psi>" => (1.0, "&Psi;")
kleing@14552
   122
     | "\\<Omega>" => (1.0, "&Omega;")
kleing@14552
   123
     | "\\<alpha>" => (1.0, "&alpha;")
kleing@14552
   124
     | "\\<beta>" => (1.0, "&beta;")
kleing@14552
   125
     | "\\<gamma>" => (1.0, "&gamma;")
kleing@14552
   126
     | "\\<delta>" => (1.0, "&delta;")
kleing@14552
   127
     | "\\<epsilon>" => (1.0, "&epsilon;")
kleing@14552
   128
     | "\\<zeta>" => (1.0, "&zeta;")
kleing@14552
   129
     | "\\<eta>" => (1.0, "&eta;")
kleing@14552
   130
     | "\\<theta>" => (1.0, "&thetasym;")
kleing@14552
   131
     | "\\<iota>" => (1.0, "&iota;")
kleing@14552
   132
     | "\\<kappa>" => (1.0, "&kappa;")
kleing@14552
   133
     | "\\<lambda>" => (1.0, "&lambda;")
kleing@14552
   134
     | "\\<mu>" => (1.0, "&mu;")
kleing@14552
   135
     | "\\<nu>" => (1.0, "&nu;")
kleing@14552
   136
     | "\\<xi>" => (1.0, "&xi;")
kleing@14552
   137
     | "\\<omicron>" => (1.0, "&omicron;")
kleing@14552
   138
     | "\\<pi>" => (1.0, "&pi;")
kleing@14552
   139
     | "\\<rho>" => (1.0, "&rho;")
kleing@14552
   140
     | "\\<sigma>" => (1.0, "&sigma;")
kleing@14552
   141
     | "\\<tau>" => (1.0, "&tau;")
kleing@14552
   142
     | "\\<upsilon>" => (1.0, "&upsilon;")
kleing@14552
   143
     | "\\<phi>" => (1.0, "&phi;")
kleing@14552
   144
     | "\\<chi>" => (1.0, "&chi;")
kleing@14552
   145
     | "\\<psi>" => (1.0, "&psi;")
kleing@14552
   146
     | "\\<omega>" => (1.0, "&omega;")
kleing@14552
   147
     | "\\<buller>" => (1.0, "&bull;")
kleing@14552
   148
     | "\\<dots>" => (1.0, "&hellip;")
kleing@14552
   149
     | "\\<Re>" => (1.0, "&real;")
kleing@14552
   150
     | "\\<Im>" => (1.0, "&image;")
kleing@14552
   151
     | "\\<wp>" => (1.0, "&weierp;")
kleing@14552
   152
     | "\\<forall>" => (1.0, "&forall;")
kleing@14552
   153
     | "\\<partial>" => (1.0, "&part;")
kleing@14552
   154
     | "\\<exists>" => (1.0, "&exist;")
kleing@14552
   155
     | "\\<emptyset>" => (1.0, "&empty;")
kleing@14552
   156
     | "\\<nabla>" => (1.0, "&nabla;")
kleing@14552
   157
     | "\\<in>" => (1.0, "&isin;")
kleing@14552
   158
     | "\\<notin>" => (1.0, "&notin;")
kleing@14565
   159
     | "\\<Prod>" => (1.0, "&prod;")
kleing@14565
   160
     | "\\<Sum>" => (1.0, "&sum;")
kleing@14552
   161
     | "\\<star>" => (1.0, "&lowast;")
kleing@14552
   162
     | "\\<propto>" => (1.0, "&prop;")
kleing@14552
   163
     | "\\<infinity>" => (1.0, "&infin;")
kleing@14552
   164
     | "\\<angle>" => (1.0, "&ang;")
kleing@14552
   165
     | "\\<and>" => (1.0, "&and;")     
kleing@14552
   166
     | "\\<or>" => (1.0, "&or;")
kleing@14552
   167
     | "\\<inter>" => (1.0, "&cap;")
kleing@14552
   168
     | "\\<union>" => (1.0, "&cup;")
kleing@14552
   169
     | "\\<sim>" => (1.0, "&sim;")
kleing@14552
   170
     | "\\<cong>" => (1.0, "&cong;")
kleing@14552
   171
     | "\\<approx>" => (1.0, "&asymp;")
kleing@14552
   172
     | "\\<noteq>" => (1.0, "&ne;")
kleing@14552
   173
     | "\\<equiv>" => (1.0, "&equiv;")
kleing@14552
   174
     | "\\<le>" => (1.0, "&le;")
kleing@14552
   175
     | "\\<ge>" => (1.0, "&ge;")
kleing@14552
   176
     | "\\<subset>" => (1.0, "&sub;")
kleing@14552
   177
     | "\\<supset>" => (1.0, "&sup;")
kleing@14552
   178
     | "\\<subseteq>" => (1.0, "&sube;")
kleing@14552
   179
     | "\\<supseteq>" => (1.0, "&supe;")
kleing@14552
   180
     | "\\<oplus>" => (1.0, "&oplus;")
kleing@14552
   181
     | "\\<otimes>" => (1.0, "&otimes;")
kleing@14552
   182
     | "\\<bottom>" => (1.0, "&perp;")
kleing@14552
   183
     | "\\<lceil>" => (1.0, "&lceil;")
kleing@14552
   184
     | "\\<rceil>" => (1.0, "&rceil;")
kleing@14552
   185
     | "\\<lfloor>" => (1.0, "&lfloor;")
kleing@14552
   186
     | "\\<rfloor>" => (1.0, "&rfloor;")
kleing@14552
   187
     | "\\<langle>" => (1.0, "&lang;")
kleing@14552
   188
     | "\\<rangle>" => (1.0, "&rang;")
kleing@14552
   189
     | "\\<lozenge>" => (1.0, "&loz;")
kleing@14552
   190
     | "\\<spadesuit>" => (1.0, "&spades;")
kleing@14552
   191
     | "\\<clubsuit>" => (1.0, "&clubs;")
kleing@14552
   192
     | "\\<heartsuit>" => (1.0, "&hearts;")
kleing@14552
   193
     | "\\<diamondsuit>" => (1.0, "&diams;")
kleing@14552
   194
kleing@14552
   195
     | "\\<lbrakk>" => (2.0, "[|")
kleing@14552
   196
     | "\\<rbrakk>" => (2.0, "|]")
kleing@14552
   197
     | "\\<Longrightarrow>" => (3.0, "==&gt;")
kleing@14552
   198
     | "\\<Rightarrow>" => (3.0, "=&gt;")
kleing@14552
   199
     | "\\<And>" => (2.0, "!!")
kleing@14552
   200
     | "\\<Colon>" => (2.0, "::")
kleing@14552
   201
     | "\\<lparr>" => (2.0, "(|")
kleing@14552
   202
     | "\\<rparr>" => (2.0, "|)")
kleing@14552
   203
     | "\\<longleftrightarrow>" => (3.0, "&lt;-&gt;")
kleing@14552
   204
     | "\\<longrightarrow>" => (3.0, "--&gt;")
kleing@14552
   205
     | "\\<rightarrow>" => (2.0, "-&gt;")
kleing@14552
   206
     | "\\<rightleftharpoons>" => (2.0, "==")
kleing@14552
   207
     | "\\<rightharpoonup>" => (2.0, "=&gt;")
kleing@14552
   208
     | "\\<leftharpoondown>" => (2.0, "&lt;=")
kleing@14552
   209
kleing@14534
   210
     | "\\<^bsub>" => (0.0, "<sub>")
kleing@14534
   211
     | "\\<^esub>" => (0.0, "</sub>")
kleing@14534
   212
     | "\\<^bsup>" => (0.0, "<sup>")
kleing@14534
   213
     | "\\<^esup>" => (0.0, "</sup>")
kleing@14552
   214
(* keep \<^sub> etc, so they are not destroyed by default case *)
kleing@14534
   215
     | "\\<^sup>" => (0.0, "\\<^sup>")
kleing@14534
   216
     | "\\<^sub>" => (0.0, "\\<^sub>")
kleing@14534
   217
     | "\\<^isup>" => (0.0, "\\<^isup>")
kleing@14534
   218
     | "\\<^isub>" => (0.0, "\\<^isub>")
wenzelm@6338
   219
     | s => (real (size s), implode (map escape (explode s)));
wenzelm@6324
   220
wenzelm@6338
   221
  fun add_sym (width, (w: real, s)) = (width + w, s);
kleing@14534
   222
kleing@14534
   223
  fun script (0, "\\<^sub>") = (1,"<sub>")
kleing@14534
   224
    | script (0, "\\<^isub>") = (1,"<sub>")
kleing@14534
   225
    | script (1, x) = (0, x ^ "</sub>")
kleing@14534
   226
    | script (0, "\\<^sup>") = (2,"<sup>")
kleing@14534
   227
    | script (0, "\\<^isup>") = (2,"<sup>")
kleing@14534
   228
    | script (2, x) = (0, x ^ "</sup>")
kleing@14534
   229
    | script (s, x) = (s,x);
kleing@14534
   230
kleing@14534
   231
  fun scrs (s, []) = (s,[])
kleing@14534
   232
    | scrs (s, x::xs) = let val (s', x') = script (s, x)
kleing@14534
   233
                            val (s'', xs') = scrs (s', xs)
kleing@14534
   234
                        in (s'', x'::xs') end;
kleing@14534
   235
                           
kleing@14534
   236
  fun scripts ss = #2 (scrs (0,ss));
wenzelm@6338
   237
in
wenzelm@6324
   238
wenzelm@6338
   239
fun output_width str =
wenzelm@6338
   240
  if not (exists_string (equal "<" orf equal ">" orf equal "&") str) then (str, real (size str))
wenzelm@6338
   241
  else
wenzelm@6338
   242
    let val (width, syms) = foldl_map add_sym (0.0, map output_sym (Symbol.explode str))
kleing@14534
   243
    in (implode (scripts syms), width) end;
wenzelm@6338
   244
wenzelm@6338
   245
val output = #1 o output_width;
kleing@14534
   246
val output_symbols = scripts o (map (#2 o output_sym))
wenzelm@6338
   247
wenzelm@6338
   248
end;
wenzelm@6338
   249
wenzelm@6324
   250
wenzelm@10954
   251
val _ = Symbol.add_mode htmlN (output_width, Symbol.default_indent);
wenzelm@6324
   252
wenzelm@6324
   253
wenzelm@6324
   254
(* token translations *)
wenzelm@6324
   255
kleing@14541
   256
fun style stl =
kleing@14541
   257
  apfst (enclose ("<span class=" ^ quote stl ^ ">") "</span>") o output_width;
wenzelm@6324
   258
wenzelm@6324
   259
val html_trans =
kleing@14541
   260
 [("class", style "tclass"),
kleing@14541
   261
  ("tfree", style "tfree"),
kleing@14541
   262
  ("tvar",  style "tvar"),
kleing@14541
   263
  ("free",  style "free"),
kleing@14541
   264
  ("bound", style "bound"),
kleing@14541
   265
  ("var",   style "var"),
kleing@14541
   266
  ("xstr",  style "xstr")];
wenzelm@6324
   267
wenzelm@6324
   268
wenzelm@6324
   269
wenzelm@6324
   270
(** HTML markup **)
wenzelm@6324
   271
wenzelm@6324
   272
type text = string;
wenzelm@6324
   273
wenzelm@6324
   274
wenzelm@6324
   275
(* atoms *)
wenzelm@6324
   276
wenzelm@6324
   277
val plain = output;
kleing@14541
   278
fun name s = "<span class=\"name\">" ^ output s ^ "</span>";
kleing@14541
   279
fun keyword s = "<span class=\"keyword\">" ^ output s ^ "</span>";
kleing@14541
   280
fun file_name s = "<span class=\"filename\">" ^ output s ^ "</span>";
berghofe@6649
   281
val file_path = file_name o Url.pack;
wenzelm@6324
   282
wenzelm@6324
   283
wenzelm@6324
   284
(* misc *)
wenzelm@6324
   285
wenzelm@6324
   286
fun href_name s txt = "<a href=" ^ quote s ^ ">" ^ txt ^ "</a>";
berghofe@6649
   287
fun href_path path txt = href_name (Url.pack path) txt;
wenzelm@6376
   288
wenzelm@6376
   289
fun href_opt_name None txt = txt
wenzelm@6376
   290
  | href_opt_name (Some s) txt = href_name s txt;
wenzelm@6376
   291
wenzelm@6376
   292
fun href_opt_path None txt = txt
wenzelm@6376
   293
  | href_opt_path (Some p) txt = href_path p txt;
wenzelm@6376
   294
wenzelm@12413
   295
fun para txt = "\n<p>" ^ txt ^ "</p>\n";
wenzelm@6324
   296
fun preform txt = "<pre>" ^ txt ^ "</pre>";
wenzelm@6324
   297
val verbatim = preform o output;
wenzelm@6324
   298
wenzelm@6324
   299
wenzelm@6324
   300
(* document *)
wenzelm@6324
   301
wenzelm@6324
   302
fun begin_document title =
webertj@14083
   303
  "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n\
webertj@14083
   304
  \\n\
webertj@14083
   305
  \<html>\n\
wenzelm@6405
   306
  \<head>\n\
webertj@14083
   307
  \<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n\
wenzelm@6405
   308
  \<title>" ^ plain (title ^ " (" ^ version ^ ")") ^ "</title>\n\
kleing@14541
   309
  \<link rel=\"stylesheet\" type=\"text/css\" href=\"isabelle.css\">\n\
wenzelm@6405
   310
  \</head>\n\
wenzelm@6405
   311
  \\n\
wenzelm@6405
   312
  \<body>\n\
kleing@14541
   313
  \<div class=\"head\">\
wenzelm@6405
   314
  \<h1>" ^ plain title ^ "</h1>\n"
wenzelm@6324
   315
kleing@14541
   316
val end_document = "\n</div>\n</body>\n</html>\n";
wenzelm@6324
   317
wenzelm@6754
   318
fun gen_link how (path, name) = para (href_path path how ^ " to index of " ^ plain name);
wenzelm@6754
   319
val up_link = gen_link "Up";
wenzelm@6754
   320
val back_link = gen_link "Back";
wenzelm@6338
   321
wenzelm@6338
   322
wenzelm@6338
   323
(* session index *)
wenzelm@6338
   324
wenzelm@7725
   325
fun begin_index up (index_path, session) opt_readme opt_doc graph =
wenzelm@6754
   326
  begin_document ("Index of " ^ session) ^ up_link up ^
wenzelm@6754
   327
  para ("View " ^ href_path graph "theory dependencies" ^
wenzelm@7725
   328
    (case opt_readme of None => "" | Some p => "<br>\nView " ^ href_path p "README") ^
wenzelm@7725
   329
    (case opt_doc of None => "" | Some p => "<br>\nView " ^ href_path p "document")) ^
kleing@14541
   330
  "\n</div>\n<hr>\n<div class=\"theories\">\n<h2>Theories</h2>\n<ul>\n";
wenzelm@6338
   331
wenzelm@6338
   332
val end_index = end_document;
wenzelm@6338
   333
berghofe@6649
   334
fun choice chs s = space_implode " " (map (fn (s', lnk) =>
berghofe@6649
   335
  enclose "[" "]" (if s = s' then keyword s' else href_name lnk s')) chs);
berghofe@6649
   336
wenzelm@9415
   337
fun applet_pages session back =
berghofe@6649
   338
  let
wenzelm@9415
   339
    val sizes =
wenzelm@9415
   340
     [("small", "small.html", ("500", "400")),
wenzelm@9415
   341
      ("medium", "medium.html", ("650", "520")),
wenzelm@9415
   342
      ("large", "large.html", ("800", "640"))];
berghofe@6649
   343
wenzelm@9415
   344
    fun applet_page (size, name, (width, height)) =
wenzelm@6754
   345
      let
wenzelm@6754
   346
        val browser_size = "Set browser size: " ^
wenzelm@9415
   347
          choice (map (fn (y, z, _) => (y, z)) sizes) size;
wenzelm@6754
   348
      in
wenzelm@6754
   349
        (name, begin_document ("Theory dependencies of " ^ session) ^
wenzelm@6754
   350
          back_link back ^
wenzelm@9415
   351
          para browser_size ^
kleing@14541
   352
          "\n</div>\n<hr>\n<div class=\"graphbrowser\">\n<applet code=\"GraphBrowser/GraphBrowser.class\" \
kleing@14541
   353
          \archive=\"GraphBrowser.jar\" \
berghofe@9045
   354
          \width=" ^ width ^ " height=" ^ height ^ ">\n\
wenzelm@9415
   355
          \<param name=\"graphfile\" value=\"" ^ "session.graph" ^ "\">\n\
wenzelm@6754
   356
          \</applet>\n<hr>" ^ end_document)
berghofe@6649
   357
      end;
wenzelm@9415
   358
  in map applet_page sizes end;
berghofe@6649
   359
berghofe@6649
   360
wenzelm@6405
   361
fun entry (p, s) = "<li>" ^ href_path p (plain s) ^ "\n";
wenzelm@6405
   362
wenzelm@6338
   363
val theory_entry = entry;
wenzelm@6338
   364
wenzelm@6405
   365
fun session_entries [] = "</ul>"
wenzelm@6405
   366
  | session_entries es =
kleing@14541
   367
      "</ul>\n</div>\n<hr>\n<div class=\"sessions\">\n<h2>Sessions</h2>\n<ul>\n" ^ implode (map entry es) ^ "</ul>";
wenzelm@6324
   368
wenzelm@6324
   369
wenzelm@6324
   370
(* theory *)
wenzelm@6324
   371
kleing@14541
   372
fun verbatim_source ss = "\n</div>\n<hr>\n<div class=\"source\">\n<pre>" ^ 
kleing@14541
   373
                         implode (output_symbols ss)  ^ 
kleing@14541
   374
                         "</pre>\n</div>\n<hr>\n<div class=\"theorems\">\n";
wenzelm@6324
   375
wenzelm@6324
   376
wenzelm@6324
   377
local
wenzelm@7408
   378
  fun encl None = enclose "[" "]"
wenzelm@7408
   379
    | encl (Some false) = enclose "(" ")"
wenzelm@7408
   380
    | encl (Some true) = I;
wenzelm@6324
   381
wenzelm@7408
   382
  fun file (opt_ref, path, loadit) = href_opt_path opt_ref (encl loadit (file_path path));
wenzelm@7831
   383
  val files = space_implode " " o map file;
wenzelm@6376
   384
  val parents = space_implode " + " o map (uncurry href_opt_path o apsnd name);
wenzelm@6361
   385
wenzelm@6376
   386
  fun theory up A =
wenzelm@6376
   387
    begin_document ("Theory " ^ A) ^ "\n" ^ up_link up ^
wenzelm@6324
   388
    keyword "theory" ^ " " ^ name A ^ " = ";
wenzelm@6324
   389
in
wenzelm@6324
   390
wenzelm@6376
   391
fun begin_theory up A Bs [] body = theory up A ^ parents Bs ^ ":\n" ^ body
wenzelm@12413
   392
  | begin_theory up A Bs Ps body = theory up A ^ parents Bs ^ "<br>\n" ^ keyword "files" ^
wenzelm@6376
   393
      " " ^ files Ps ^ ":" ^ "\n" ^ body;
wenzelm@6324
   394
end;
wenzelm@6324
   395
wenzelm@6338
   396
val end_theory = end_document;
wenzelm@6324
   397
wenzelm@6324
   398
wenzelm@6324
   399
(* ML file *)
wenzelm@6324
   400
wenzelm@6324
   401
fun ml_file path str =
berghofe@6649
   402
  begin_document ("File " ^ Url.pack path) ^
kleing@14541
   403
  "\n</div>\n<hr><div class=\"mlsource\">\n" ^ 
kleing@14541
   404
  verbatim str ^ 
kleing@14541
   405
  "\n</div>\n<hr>\n<div class=\"mlfooter\">\n" ^ 
kleing@14541
   406
  end_document;
wenzelm@6324
   407
wenzelm@6324
   408
wenzelm@7408
   409
(* theorems *)
wenzelm@6324
   410
wenzelm@7572
   411
local
wenzelm@7572
   412
wenzelm@7408
   413
val string_of_thm =
wenzelm@6324
   414
  Pretty.setmp_margin 80 Pretty.string_of o
wenzelm@6324
   415
    Display.pretty_thm_no_quote o #1 o Drule.freeze_thaw;
wenzelm@6324
   416
wenzelm@6324
   417
fun thm th = preform (prefix_lines "  " (html_mode string_of_thm th));
wenzelm@7408
   418
wenzelm@7572
   419
fun thm_name "" = ""
wenzelm@7572
   420
  | thm_name a = " " ^ name (a ^ ":");
wenzelm@7572
   421
wenzelm@7572
   422
in
wenzelm@7572
   423
wenzelm@13531
   424
fun result k (a, ths) = para (cat_lines ((keyword k ^ thm_name a) :: map thm ths));
wenzelm@7572
   425
wenzelm@13531
   426
fun results _ [] = ""
wenzelm@13531
   427
  | results k (res :: ress) = cat_lines (result k res :: map (result "and") ress);
wenzelm@7572
   428
wenzelm@7572
   429
end;
wenzelm@6324
   430
wenzelm@6324
   431
wenzelm@7634
   432
(* sections *)
wenzelm@6324
   433
wenzelm@8088
   434
fun chapter heading = "\n\n<h1>" ^ plain heading ^ "</h1>\n";
wenzelm@6324
   435
fun section heading = "\n\n<h2>" ^ plain heading ^ "</h2>\n";
wenzelm@7634
   436
fun subsection heading = "\n\n<h3>" ^ plain heading ^ "</h3>\n";
wenzelm@7634
   437
fun subsubsection heading = "\n\n<h4>" ^ plain heading ^ "</h4>\n";
wenzelm@6324
   438
wenzelm@6324
   439
wenzelm@6324
   440
(** theory setup **)
wenzelm@6324
   441
wenzelm@6324
   442
val setup =
wenzelm@6324
   443
 [Theory.add_mode_tokentrfuns htmlN html_trans];
wenzelm@6324
   444
wenzelm@6324
   445
wenzelm@6324
   446
end;