src/Pure/Thy/html.ML
author wenzelm
Wed Jun 29 15:23:36 2011 +0200 (2011-06-29)
changeset 43592 e67d104c0c50
parent 43548 f231a7594e54
child 45666 d83797ef0d2d
permissions -rw-r--r--
HTML: render control symbols more like Isabelle/Scala/jEdit;
haftmann@24584
     1
(*  Title:      Pure/Thy/html.ML
wenzelm@9415
     2
    Author:     Markus Wenzel and Stefan Berghofer, TU Muenchen
wenzelm@6324
     3
wenzelm@9415
     4
HTML presentation elements.
wenzelm@6324
     5
*)
wenzelm@6324
     6
wenzelm@6324
     7
signature HTML =
wenzelm@6324
     8
sig
wenzelm@23724
     9
  val html_mode: ('a -> 'b) -> 'a -> 'b
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
berghofe@6649
    19
  val href_opt_path: Url.T option -> text -> text
wenzelm@6376
    20
  val para: text -> text
wenzelm@6324
    21
  val preform: text -> text
wenzelm@6324
    22
  val verbatim: string -> text
wenzelm@23724
    23
  val begin_document: string -> text
wenzelm@23724
    24
  val end_document: text
wenzelm@17080
    25
  val begin_index: Url.T * string -> Url.T * string -> (Url.T * string) list -> Url.T -> text
wenzelm@9415
    26
  val applet_pages: string -> Url.T * string -> (string * string) list
berghofe@6649
    27
  val theory_entry: Url.T * string -> text
berghofe@6649
    28
  val session_entries: (Url.T * string) list -> text
wenzelm@27861
    29
  val theory_source: text -> text
berghofe@6649
    30
  val begin_theory: Url.T * string -> string -> (Url.T option * string) list ->
wenzelm@27490
    31
    (Url.T * Url.T * bool) list -> text -> text
wenzelm@37940
    32
  val external_file: Url.T -> string -> text
wenzelm@6324
    33
end;
wenzelm@6324
    34
wenzelm@6324
    35
structure HTML: HTML =
wenzelm@6324
    36
struct
wenzelm@6324
    37
wenzelm@6324
    38
wenzelm@6324
    39
(** HTML print modes **)
wenzelm@6324
    40
wenzelm@6324
    41
(* mode *)
wenzelm@6324
    42
wenzelm@6324
    43
val htmlN = "HTML";
wenzelm@37146
    44
fun html_mode f x = Print_Mode.with_modes [htmlN] f x;
wenzelm@6324
    45
wenzelm@6324
    46
wenzelm@33985
    47
(* common markup *)
wenzelm@33985
    48
wenzelm@33985
    49
fun span class = ("<span class=" ^ quote (XML.text class) ^ ">", "</span>");
wenzelm@33985
    50
wenzelm@43548
    51
fun span_class (name, props) =
wenzelm@43548
    52
  (case Markup.get_entity_kind (name, props) of
wenzelm@43548
    53
    SOME kind => Markup.entityN ^ "_" ^ name
wenzelm@43548
    54
  | NONE => name);
wenzelm@43548
    55
wenzelm@43548
    56
val _ = Markup.add_mode htmlN (span o span_class);
wenzelm@33985
    57
wenzelm@33985
    58
wenzelm@6324
    59
(* symbol output *)
wenzelm@6324
    60
wenzelm@6338
    61
local
wenzelm@43592
    62
  val hidden = span Markup.hiddenN |-> enclose;
wenzelm@33985
    63
wenzelm@43592
    64
  (* FIXME proper unicode -- produced on Scala side *)
wenzelm@16196
    65
  val html_syms = Symtab.make
wenzelm@34003
    66
   [("", (0, "")),
wenzelm@34003
    67
    ("\n", (0, "<br/>")),
wenzelm@33986
    68
    ("'", (1, "&#39;")),
wenzelm@33983
    69
    ("\\<spacespace>", (2, "&nbsp;&nbsp;")),
wenzelm@23622
    70
    ("\\<exclamdown>", (1, "&iexcl;")),
wenzelm@23622
    71
    ("\\<cent>", (1, "&cent;")),
wenzelm@23622
    72
    ("\\<pounds>", (1, "&pound;")),
wenzelm@23622
    73
    ("\\<currency>", (1, "&curren;")),
wenzelm@23622
    74
    ("\\<yen>", (1, "&yen;")),
wenzelm@23622
    75
    ("\\<bar>", (1, "&brvbar;")),
wenzelm@23622
    76
    ("\\<section>", (1, "&sect;")),
wenzelm@23622
    77
    ("\\<dieresis>", (1, "&uml;")),
wenzelm@23622
    78
    ("\\<copyright>", (1, "&copy;")),
wenzelm@23622
    79
    ("\\<ordfeminine>", (1, "&ordf;")),
wenzelm@23622
    80
    ("\\<guillemotleft>", (1, "&laquo;")),
wenzelm@23622
    81
    ("\\<not>", (1, "&not;")),
wenzelm@23622
    82
    ("\\<hyphen>", (1, "&shy;")),
wenzelm@23622
    83
    ("\\<registered>", (1, "&reg;")),
wenzelm@23622
    84
    ("\\<inverse>", (1, "&macr;")),
wenzelm@23622
    85
    ("\\<degree>", (1, "&deg;")),
wenzelm@23622
    86
    ("\\<plusminus>", (1, "&plusmn;")),
wenzelm@23622
    87
    ("\\<twosuperior>", (1, "&sup2;")),
wenzelm@23622
    88
    ("\\<threesuperior>", (1, "&sup3;")),
wenzelm@23622
    89
    ("\\<acute>", (1, "&acute;")),
wenzelm@23622
    90
    ("\\<paragraph>", (1, "&para;")),
wenzelm@23622
    91
    ("\\<cdot>", (1, "&middot;")),
wenzelm@23622
    92
    ("\\<cedilla>", (1, "&cedil;")),
wenzelm@23622
    93
    ("\\<onesuperior>", (1, "&sup1;")),
wenzelm@23622
    94
    ("\\<ordmasculine>", (1, "&ordm;")),
wenzelm@23622
    95
    ("\\<guillemotright>", (1, "&raquo;")),
wenzelm@23622
    96
    ("\\<onequarter>", (1, "&frac14;")),
wenzelm@23622
    97
    ("\\<onehalf>", (1, "&frac12;")),
wenzelm@23622
    98
    ("\\<threequarters>", (1, "&frac34;")),
wenzelm@23622
    99
    ("\\<questiondown>", (1, "&iquest;")),
wenzelm@23622
   100
    ("\\<times>", (1, "&times;")),
wenzelm@23622
   101
    ("\\<div>", (1, "&divide;")),
wenzelm@23622
   102
    ("\\<circ>", (1, "o")),
wenzelm@23622
   103
    ("\\<Alpha>", (1, "&Alpha;")),
wenzelm@23622
   104
    ("\\<Beta>", (1, "&Beta;")),
wenzelm@23622
   105
    ("\\<Gamma>", (1, "&Gamma;")),
wenzelm@23622
   106
    ("\\<Delta>", (1, "&Delta;")),
wenzelm@23622
   107
    ("\\<Epsilon>", (1, "&Epsilon;")),
wenzelm@23622
   108
    ("\\<Zeta>", (1, "&Zeta;")),
wenzelm@23622
   109
    ("\\<Eta>", (1, "&Eta;")),
wenzelm@23622
   110
    ("\\<Theta>", (1, "&Theta;")),
wenzelm@23622
   111
    ("\\<Iota>", (1, "&Iota;")),
wenzelm@23622
   112
    ("\\<Kappa>", (1, "&Kappa;")),
wenzelm@23622
   113
    ("\\<Lambda>", (1, "&Lambda;")),
wenzelm@23622
   114
    ("\\<Mu>", (1, "&Mu;")),
wenzelm@23622
   115
    ("\\<Nu>", (1, "&Nu;")),
wenzelm@23622
   116
    ("\\<Xi>", (1, "&Xi;")),
wenzelm@23622
   117
    ("\\<Omicron>", (1, "&Omicron;")),
wenzelm@23622
   118
    ("\\<Pi>", (1, "&Pi;")),
wenzelm@23622
   119
    ("\\<Rho>", (1, "&Rho;")),
wenzelm@23622
   120
    ("\\<Sigma>", (1, "&Sigma;")),
wenzelm@23622
   121
    ("\\<Tau>", (1, "&Tau;")),
wenzelm@23622
   122
    ("\\<Upsilon>", (1, "&Upsilon;")),
wenzelm@23622
   123
    ("\\<Phi>", (1, "&Phi;")),
wenzelm@23622
   124
    ("\\<Chi>", (1, "&Chi;")),
wenzelm@23622
   125
    ("\\<Psi>", (1, "&Psi;")),
wenzelm@23622
   126
    ("\\<Omega>", (1, "&Omega;")),
wenzelm@23622
   127
    ("\\<alpha>", (1, "&alpha;")),
wenzelm@23622
   128
    ("\\<beta>", (1, "&beta;")),
wenzelm@23622
   129
    ("\\<gamma>", (1, "&gamma;")),
wenzelm@23622
   130
    ("\\<delta>", (1, "&delta;")),
wenzelm@23622
   131
    ("\\<epsilon>", (1, "&epsilon;")),
wenzelm@23622
   132
    ("\\<zeta>", (1, "&zeta;")),
wenzelm@23622
   133
    ("\\<eta>", (1, "&eta;")),
wenzelm@23622
   134
    ("\\<theta>", (1, "&thetasym;")),
wenzelm@23622
   135
    ("\\<iota>", (1, "&iota;")),
wenzelm@23622
   136
    ("\\<kappa>", (1, "&kappa;")),
wenzelm@23622
   137
    ("\\<lambda>", (1, "&lambda;")),
wenzelm@23622
   138
    ("\\<mu>", (1, "&mu;")),
wenzelm@23622
   139
    ("\\<nu>", (1, "&nu;")),
wenzelm@23622
   140
    ("\\<xi>", (1, "&xi;")),
wenzelm@23622
   141
    ("\\<omicron>", (1, "&omicron;")),
wenzelm@23622
   142
    ("\\<pi>", (1, "&pi;")),
wenzelm@23622
   143
    ("\\<rho>", (1, "&rho;")),
wenzelm@23622
   144
    ("\\<sigma>", (1, "&sigma;")),
wenzelm@23622
   145
    ("\\<tau>", (1, "&tau;")),
wenzelm@23622
   146
    ("\\<upsilon>", (1, "&upsilon;")),
wenzelm@23622
   147
    ("\\<phi>", (1, "&phi;")),
wenzelm@23622
   148
    ("\\<chi>", (1, "&chi;")),
wenzelm@23622
   149
    ("\\<psi>", (1, "&psi;")),
wenzelm@23622
   150
    ("\\<omega>", (1, "&omega;")),
wenzelm@23622
   151
    ("\\<bullet>", (1, "&bull;")),
wenzelm@23622
   152
    ("\\<dots>", (1, "&hellip;")),
wenzelm@23622
   153
    ("\\<Re>", (1, "&real;")),
wenzelm@23622
   154
    ("\\<Im>", (1, "&image;")),
wenzelm@23622
   155
    ("\\<wp>", (1, "&weierp;")),
wenzelm@23622
   156
    ("\\<forall>", (1, "&forall;")),
wenzelm@23622
   157
    ("\\<partial>", (1, "&part;")),
wenzelm@23622
   158
    ("\\<exists>", (1, "&exist;")),
wenzelm@23622
   159
    ("\\<emptyset>", (1, "&empty;")),
wenzelm@23622
   160
    ("\\<nabla>", (1, "&nabla;")),
wenzelm@23622
   161
    ("\\<in>", (1, "&isin;")),
wenzelm@23622
   162
    ("\\<notin>", (1, "&notin;")),
wenzelm@23622
   163
    ("\\<Prod>", (1, "&prod;")),
wenzelm@23622
   164
    ("\\<Sum>", (1, "&sum;")),
wenzelm@23622
   165
    ("\\<star>", (1, "&lowast;")),
wenzelm@23622
   166
    ("\\<propto>", (1, "&prop;")),
wenzelm@23622
   167
    ("\\<infinity>", (1, "&infin;")),
wenzelm@23622
   168
    ("\\<angle>", (1, "&ang;")),
wenzelm@23622
   169
    ("\\<and>", (1, "&and;")),
wenzelm@23622
   170
    ("\\<or>", (1, "&or;")),
wenzelm@23622
   171
    ("\\<inter>", (1, "&cap;")),
wenzelm@23622
   172
    ("\\<union>", (1, "&cup;")),
wenzelm@23622
   173
    ("\\<sim>", (1, "&sim;")),
wenzelm@23622
   174
    ("\\<cong>", (1, "&cong;")),
wenzelm@23622
   175
    ("\\<approx>", (1, "&asymp;")),
wenzelm@23622
   176
    ("\\<noteq>", (1, "&ne;")),
wenzelm@23622
   177
    ("\\<equiv>", (1, "&equiv;")),
wenzelm@23622
   178
    ("\\<le>", (1, "&le;")),
wenzelm@23622
   179
    ("\\<ge>", (1, "&ge;")),
wenzelm@23622
   180
    ("\\<subset>", (1, "&sub;")),
wenzelm@23622
   181
    ("\\<supset>", (1, "&sup;")),
wenzelm@23622
   182
    ("\\<subseteq>", (1, "&sube;")),
wenzelm@23622
   183
    ("\\<supseteq>", (1, "&supe;")),
wenzelm@23622
   184
    ("\\<oplus>", (1, "&oplus;")),
wenzelm@23622
   185
    ("\\<otimes>", (1, "&otimes;")),
wenzelm@23622
   186
    ("\\<bottom>", (1, "&perp;")),
wenzelm@23622
   187
    ("\\<lceil>", (1, "&lceil;")),
wenzelm@23622
   188
    ("\\<rceil>", (1, "&rceil;")),
wenzelm@23622
   189
    ("\\<lfloor>", (1, "&lfloor;")),
wenzelm@23622
   190
    ("\\<rfloor>", (1, "&rfloor;")),
wenzelm@23622
   191
    ("\\<langle>", (1, "&lang;")),
wenzelm@23622
   192
    ("\\<rangle>", (1, "&rang;")),
wenzelm@23622
   193
    ("\\<lozenge>", (1, "&loz;")),
wenzelm@23622
   194
    ("\\<spadesuit>", (1, "&spades;")),
wenzelm@23622
   195
    ("\\<clubsuit>", (1, "&clubs;")),
wenzelm@23622
   196
    ("\\<heartsuit>", (1, "&hearts;")),
wenzelm@23622
   197
    ("\\<diamondsuit>", (1, "&diams;")),
wenzelm@23622
   198
    ("\\<lbrakk>", (2, "[|")),
wenzelm@23622
   199
    ("\\<rbrakk>", (2, "|]")),
wenzelm@23622
   200
    ("\\<Longrightarrow>", (3, "==&gt;")),
wenzelm@23622
   201
    ("\\<Rightarrow>", (2, "=&gt;")),
wenzelm@23622
   202
    ("\\<And>", (2, "!!")),
wenzelm@23622
   203
    ("\\<Colon>", (2, "::")),
wenzelm@23622
   204
    ("\\<lparr>", (2, "(|")),
wenzelm@23622
   205
    ("\\<rparr>", (2, "|)),")),
wenzelm@23622
   206
    ("\\<longleftrightarrow>", (3, "&lt;-&gt;")),
wenzelm@23622
   207
    ("\\<longrightarrow>", (3, "--&gt;")),
wenzelm@23622
   208
    ("\\<rightarrow>", (2, "-&gt;")),
wenzelm@43592
   209
    ("\\<^bsub>", (0, hidden "&#8664;" ^ "<sub>")),
wenzelm@43592
   210
    ("\\<^esub>", (0, hidden "&#8665;" ^ "</sub>")),
wenzelm@43592
   211
    ("\\<^bsup>", (0, hidden "&#8663;" ^ "<sup>")),
wenzelm@43592
   212
    ("\\<^esup>", (0, hidden "&#8662;" ^ "</sup>"))];
wenzelm@17178
   213
wenzelm@16196
   214
  fun output_sym s =
wenzelm@23622
   215
    if Symbol.is_raw s then (1, Symbol.decode_raw s)
wenzelm@20742
   216
    else
wenzelm@33983
   217
      (case Symtab.lookup html_syms s of
wenzelm@33983
   218
        SOME x => x
wenzelm@26709
   219
      | NONE => (size s, XML.text s));
wenzelm@6324
   220
wenzelm@33985
   221
  fun output_markup (bg, en) s1 s2 =
wenzelm@33985
   222
    let val (n, txt) = output_sym s2
wenzelm@33985
   223
    in (n, hidden s1 ^ enclose bg en txt) end;
kleing@14534
   224
wenzelm@33985
   225
  val output_sub = output_markup ("<sub>", "</sub>");
wenzelm@33985
   226
  val output_sup = output_markup ("<sup>", "</sup>");
wenzelm@33985
   227
  val output_bold = output_markup (span "bold");
wenzelm@33985
   228
wenzelm@41482
   229
  fun output_syms [] (result, width) = (implode (rev result), width)
wenzelm@41482
   230
    | output_syms (s1 :: rest) (result, width) =
wenzelm@41482
   231
        let
wenzelm@41482
   232
          val (s2, ss) = (case rest of [] => ("", []) | s2 :: ss => (s2, ss));
wenzelm@41482
   233
          val ((w, s), r) =
wenzelm@43592
   234
            if s1 = "\\<^sub>" then (output_sub "&#8681;" s2, ss)
wenzelm@43592
   235
            else if s1 = "\\<^isub>" then (output_sub "&#8675;" s2, ss)
wenzelm@43592
   236
            else if s1 = "\\<^sup>" then (output_sup "&#8679;" s2, ss)
wenzelm@43592
   237
            else if s1 = "\\<^isup>" then (output_sup "&#8673;" s2, ss)
wenzelm@43592
   238
            else if s1 = "\\<^bold>" then (output_bold "&#10073;" s2, ss)
wenzelm@41482
   239
            else (output_sym s1, rest);
wenzelm@41482
   240
        in output_syms r (s :: result, width + w) end;
wenzelm@6338
   241
in
wenzelm@6324
   242
wenzelm@41482
   243
fun output_width str = output_syms (Symbol.explode str) ([], 0);
wenzelm@6338
   244
val output = #1 o output_width;
wenzelm@6338
   245
wenzelm@26709
   246
val _ = Output.add_mode htmlN output_width Symbol.encode_raw;
wenzelm@26709
   247
wenzelm@6338
   248
end;
wenzelm@6338
   249
wenzelm@6324
   250
wenzelm@6324
   251
wenzelm@6324
   252
(** HTML markup **)
wenzelm@6324
   253
wenzelm@6324
   254
type text = string;
wenzelm@6324
   255
wenzelm@6324
   256
wenzelm@6324
   257
(* atoms *)
wenzelm@6324
   258
wenzelm@6324
   259
val plain = output;
wenzelm@19265
   260
val name = enclose "<span class=\"name\">" "</span>" o output;
wenzelm@19265
   261
val keyword = enclose "<span class=\"keyword\">" "</span>" o output;
wenzelm@23622
   262
val command = enclose "<span class=\"command\">" "</span>" o output;
wenzelm@19265
   263
val file_name = enclose "<span class=\"filename\">" "</span>" o output;
wenzelm@21858
   264
val file_path = file_name o Url.implode;
wenzelm@6324
   265
wenzelm@6324
   266
wenzelm@6324
   267
(* misc *)
wenzelm@6324
   268
wenzelm@28840
   269
fun href_name s txt = "<a href=" ^ quote s ^ ">" ^ txt ^ "</a>";
wenzelm@21858
   270
fun href_path path txt = href_name (Url.implode path) txt;
wenzelm@6376
   271
skalberg@15531
   272
fun href_opt_path NONE txt = txt
skalberg@15531
   273
  | href_opt_path (SOME p) txt = href_path p txt;
wenzelm@6376
   274
wenzelm@12413
   275
fun para txt = "\n<p>" ^ txt ^ "</p>\n";
wenzelm@27830
   276
fun preform txt = "<pre>" ^ txt ^ "</pre>";
wenzelm@6324
   277
val verbatim = preform o output;
wenzelm@6324
   278
wenzelm@6324
   279
wenzelm@6324
   280
(* document *)
wenzelm@6324
   281
wenzelm@6324
   282
fun begin_document title =
wenzelm@40946
   283
  "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n\
wenzelm@40946
   284
  \<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \
wenzelm@40946
   285
  \\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\
wenzelm@40946
   286
  \<html xmlns=\"http://www.w3.org/1999/xhtml\">\n\
wenzelm@40946
   287
  \<head>\n\
wenzelm@40946
   288
  \<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n\
wenzelm@40946
   289
  \<title>" ^ plain (title ^ " (" ^ Distribution.version ^ ")") ^ "</title>\n\
wenzelm@40946
   290
  \<link media=\"all\" rel=\"stylesheet\" type=\"text/css\" href=\"isabelle.css\"/>\n\
wenzelm@40946
   291
  \</head>\n\
wenzelm@40946
   292
  \\n\
wenzelm@40946
   293
  \<body>\n\
wenzelm@40946
   294
  \<div class=\"head\">\
wenzelm@40946
   295
  \<h1>" ^ plain title ^ "</h1>\n";
wenzelm@6324
   296
kleing@14541
   297
val end_document = "\n</div>\n</body>\n</html>\n";
wenzelm@6324
   298
wenzelm@6754
   299
fun gen_link how (path, name) = para (href_path path how ^ " to index of " ^ plain name);
wenzelm@6754
   300
val up_link = gen_link "Up";
wenzelm@6754
   301
val back_link = gen_link "Back";
wenzelm@6338
   302
wenzelm@6338
   303
wenzelm@6338
   304
(* session index *)
wenzelm@6338
   305
wenzelm@17080
   306
fun begin_index up (index_path, session) docs graph =
wenzelm@6754
   307
  begin_document ("Index of " ^ session) ^ up_link up ^
wenzelm@6754
   308
  para ("View " ^ href_path graph "theory dependencies" ^
wenzelm@27829
   309
    implode (map (fn (p, name) => "<br/>\nView " ^ href_path p name) docs)) ^
wenzelm@37941
   310
  "\n</div>\n<div class=\"theories\">\n<h2>Theories</h2>\n<ul>\n";
wenzelm@6338
   311
berghofe@6649
   312
fun choice chs s = space_implode " " (map (fn (s', lnk) =>
berghofe@6649
   313
  enclose "[" "]" (if s = s' then keyword s' else href_name lnk s')) chs);
berghofe@6649
   314
wenzelm@9415
   315
fun applet_pages session back =
berghofe@6649
   316
  let
wenzelm@9415
   317
    val sizes =
wenzelm@9415
   318
     [("small", "small.html", ("500", "400")),
wenzelm@9415
   319
      ("medium", "medium.html", ("650", "520")),
wenzelm@9415
   320
      ("large", "large.html", ("800", "640"))];
berghofe@6649
   321
wenzelm@9415
   322
    fun applet_page (size, name, (width, height)) =
wenzelm@6754
   323
      let
wenzelm@6754
   324
        val browser_size = "Set browser size: " ^
wenzelm@9415
   325
          choice (map (fn (y, z, _) => (y, z)) sizes) size;
wenzelm@6754
   326
      in
wenzelm@6754
   327
        (name, begin_document ("Theory dependencies of " ^ session) ^
wenzelm@6754
   328
          back_link back ^
wenzelm@9415
   329
          para browser_size ^
wenzelm@37941
   330
          "\n</div>\n<div class=\"graphbrowser\">\n\
wenzelm@17080
   331
          \<applet code=\"GraphBrowser/GraphBrowser.class\" \
kleing@14541
   332
          \archive=\"GraphBrowser.jar\" \
wenzelm@27832
   333
          \width=" ^ quote width ^ " height=" ^ quote height ^ ">\n\
wenzelm@27832
   334
          \<param name=\"graphfile\" value=\"" ^ "session.graph" ^ "\"/>\n\
wenzelm@37941
   335
          \</applet>" ^ end_document)
berghofe@6649
   336
      end;
wenzelm@9415
   337
  in map applet_page sizes end;
berghofe@6649
   338
berghofe@6649
   339
wenzelm@27829
   340
fun entry (p, s) = "<li>" ^ href_path p (plain s) ^ "</li>\n";
wenzelm@6405
   341
wenzelm@6338
   342
val theory_entry = entry;
wenzelm@6338
   343
wenzelm@6405
   344
fun session_entries [] = "</ul>"
wenzelm@6405
   345
  | session_entries es =
wenzelm@37941
   346
      "</ul>\n</div>\n<div class=\"sessions\">\n\
wenzelm@17080
   347
      \<h2>Sessions</h2>\n<ul>\n" ^ implode (map entry es) ^ "</ul>";
wenzelm@6324
   348
wenzelm@6324
   349
wenzelm@6324
   350
(* theory *)
wenzelm@6324
   351
wenzelm@27861
   352
val theory_source = enclose
wenzelm@37941
   353
  "\n</div>\n<div class=\"source\">\n<pre>"
wenzelm@37941
   354
  "</pre>\n";
wenzelm@6324
   355
wenzelm@6324
   356
wenzelm@6324
   357
local
wenzelm@27490
   358
  fun file (href, path, loadit) =
wenzelm@27490
   359
    href_path href (if loadit then file_path path else enclose "(" ")" (file_path path));
wenzelm@6361
   360
wenzelm@6376
   361
  fun theory up A =
wenzelm@6376
   362
    begin_document ("Theory " ^ A) ^ "\n" ^ up_link up ^
wenzelm@23622
   363
    command "theory" ^ " " ^ name A;
wenzelm@16267
   364
wenzelm@16267
   365
  fun imports Bs =
wenzelm@16267
   366
    keyword "imports" ^ " " ^ space_implode " " (map (uncurry href_opt_path o apsnd name) Bs);
wenzelm@16267
   367
wenzelm@27829
   368
  fun uses Ps = keyword "uses" ^ " " ^ space_implode " " (map file Ps) ^ "<br/>\n";
wenzelm@6324
   369
in
wenzelm@6324
   370
wenzelm@16267
   371
fun begin_theory up A Bs Ps body =
wenzelm@27829
   372
  theory up A ^ "<br/>\n" ^
wenzelm@27829
   373
  imports Bs ^ "<br/>\n" ^
wenzelm@16267
   374
  (if null Ps then "" else uses Ps) ^
wenzelm@16267
   375
  body;
wenzelm@16267
   376
wenzelm@6324
   377
end;
wenzelm@6324
   378
wenzelm@6324
   379
wenzelm@37940
   380
(* external file *)
wenzelm@6324
   381
wenzelm@37940
   382
fun external_file path str =
wenzelm@21858
   383
  begin_document ("File " ^ Url.implode path) ^
wenzelm@37941
   384
  "\n</div><div class=\"external_source\">\n" ^
wenzelm@14571
   385
  verbatim str ^
wenzelm@37941
   386
  "\n</div>\n<div class=\"external_footer\">" ^
kleing@14541
   387
  end_document;
wenzelm@6324
   388
wenzelm@7572
   389
end;