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