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