src/Pure/Thy/html.ML
author wenzelm
Mon Aug 11 20:56:32 2008 +0200 (2008-08-11)
changeset 27830 68de2a2780b3
parent 27829 c073006e0137
child 27832 992c6d984925
permissions -rw-r--r--
<pre>: removed xml:space, is already default;
result(s): avoid improper nesting of <pre> within <p>;
haftmann@24584
     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@23724
    10
  val html_mode: ('a -> 'b) -> 'a -> 'b
wenzelm@23622
    11
  type text = string
wenzelm@6324
    12
  val plain: string -> text
wenzelm@6324
    13
  val name: string -> text
wenzelm@6324
    14
  val keyword: string -> text
wenzelm@23622
    15
  val command: 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
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@23724
    25
  val begin_document: string -> text
wenzelm@23724
    26
  val end_document: text
wenzelm@17080
    27
  val begin_index: Url.T * string -> Url.T * string -> (Url.T * string) list -> 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@27490
    34
    (Url.T * Url.T * bool) list -> text -> text
wenzelm@6324
    35
  val end_theory: text
berghofe@6649
    36
  val ml_file: Url.T -> string -> text
wenzelm@22122
    37
  val results: Proof.context -> 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
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@23935
    53
fun html_mode f x = PrintMode.with_modes [htmlN] f x;
wenzelm@6324
    54
wenzelm@6324
    55
wenzelm@6324
    56
(* symbol output *)
wenzelm@6324
    57
wenzelm@6338
    58
local
wenzelm@16196
    59
  val html_syms = Symtab.make
wenzelm@23622
    60
   [("\\<spacespace>", (2, "&nbsp;&nbsp;")),
wenzelm@23622
    61
    ("\\<exclamdown>", (1, "&iexcl;")),
wenzelm@23622
    62
    ("\\<cent>", (1, "&cent;")),
wenzelm@23622
    63
    ("\\<pounds>", (1, "&pound;")),
wenzelm@23622
    64
    ("\\<currency>", (1, "&curren;")),
wenzelm@23622
    65
    ("\\<yen>", (1, "&yen;")),
wenzelm@23622
    66
    ("\\<bar>", (1, "&brvbar;")),
wenzelm@23622
    67
    ("\\<section>", (1, "&sect;")),
wenzelm@23622
    68
    ("\\<dieresis>", (1, "&uml;")),
wenzelm@23622
    69
    ("\\<copyright>", (1, "&copy;")),
wenzelm@23622
    70
    ("\\<ordfeminine>", (1, "&ordf;")),
wenzelm@23622
    71
    ("\\<guillemotleft>", (1, "&laquo;")),
wenzelm@23622
    72
    ("\\<not>", (1, "&not;")),
wenzelm@23622
    73
    ("\\<hyphen>", (1, "&shy;")),
wenzelm@23622
    74
    ("\\<registered>", (1, "&reg;")),
wenzelm@23622
    75
    ("\\<inverse>", (1, "&macr;")),
wenzelm@23622
    76
    ("\\<degree>", (1, "&deg;")),
wenzelm@23622
    77
    ("\\<plusminus>", (1, "&plusmn;")),
wenzelm@23622
    78
    ("\\<twosuperior>", (1, "&sup2;")),
wenzelm@23622
    79
    ("\\<threesuperior>", (1, "&sup3;")),
wenzelm@23622
    80
    ("\\<acute>", (1, "&acute;")),
wenzelm@23622
    81
    ("\\<paragraph>", (1, "&para;")),
wenzelm@23622
    82
    ("\\<cdot>", (1, "&middot;")),
wenzelm@23622
    83
    ("\\<cedilla>", (1, "&cedil;")),
wenzelm@23622
    84
    ("\\<onesuperior>", (1, "&sup1;")),
wenzelm@23622
    85
    ("\\<ordmasculine>", (1, "&ordm;")),
wenzelm@23622
    86
    ("\\<guillemotright>", (1, "&raquo;")),
wenzelm@23622
    87
    ("\\<onequarter>", (1, "&frac14;")),
wenzelm@23622
    88
    ("\\<onehalf>", (1, "&frac12;")),
wenzelm@23622
    89
    ("\\<threequarters>", (1, "&frac34;")),
wenzelm@23622
    90
    ("\\<questiondown>", (1, "&iquest;")),
wenzelm@23622
    91
    ("\\<times>", (1, "&times;")),
wenzelm@23622
    92
    ("\\<div>", (1, "&divide;")),
wenzelm@23622
    93
    ("\\<circ>", (1, "o")),
wenzelm@23622
    94
    ("\\<Alpha>", (1, "&Alpha;")),
wenzelm@23622
    95
    ("\\<Beta>", (1, "&Beta;")),
wenzelm@23622
    96
    ("\\<Gamma>", (1, "&Gamma;")),
wenzelm@23622
    97
    ("\\<Delta>", (1, "&Delta;")),
wenzelm@23622
    98
    ("\\<Epsilon>", (1, "&Epsilon;")),
wenzelm@23622
    99
    ("\\<Zeta>", (1, "&Zeta;")),
wenzelm@23622
   100
    ("\\<Eta>", (1, "&Eta;")),
wenzelm@23622
   101
    ("\\<Theta>", (1, "&Theta;")),
wenzelm@23622
   102
    ("\\<Iota>", (1, "&Iota;")),
wenzelm@23622
   103
    ("\\<Kappa>", (1, "&Kappa;")),
wenzelm@23622
   104
    ("\\<Lambda>", (1, "&Lambda;")),
wenzelm@23622
   105
    ("\\<Mu>", (1, "&Mu;")),
wenzelm@23622
   106
    ("\\<Nu>", (1, "&Nu;")),
wenzelm@23622
   107
    ("\\<Xi>", (1, "&Xi;")),
wenzelm@23622
   108
    ("\\<Omicron>", (1, "&Omicron;")),
wenzelm@23622
   109
    ("\\<Pi>", (1, "&Pi;")),
wenzelm@23622
   110
    ("\\<Rho>", (1, "&Rho;")),
wenzelm@23622
   111
    ("\\<Sigma>", (1, "&Sigma;")),
wenzelm@23622
   112
    ("\\<Tau>", (1, "&Tau;")),
wenzelm@23622
   113
    ("\\<Upsilon>", (1, "&Upsilon;")),
wenzelm@23622
   114
    ("\\<Phi>", (1, "&Phi;")),
wenzelm@23622
   115
    ("\\<Chi>", (1, "&Chi;")),
wenzelm@23622
   116
    ("\\<Psi>", (1, "&Psi;")),
wenzelm@23622
   117
    ("\\<Omega>", (1, "&Omega;")),
wenzelm@23622
   118
    ("\\<alpha>", (1, "&alpha;")),
wenzelm@23622
   119
    ("\\<beta>", (1, "&beta;")),
wenzelm@23622
   120
    ("\\<gamma>", (1, "&gamma;")),
wenzelm@23622
   121
    ("\\<delta>", (1, "&delta;")),
wenzelm@23622
   122
    ("\\<epsilon>", (1, "&epsilon;")),
wenzelm@23622
   123
    ("\\<zeta>", (1, "&zeta;")),
wenzelm@23622
   124
    ("\\<eta>", (1, "&eta;")),
wenzelm@23622
   125
    ("\\<theta>", (1, "&thetasym;")),
wenzelm@23622
   126
    ("\\<iota>", (1, "&iota;")),
wenzelm@23622
   127
    ("\\<kappa>", (1, "&kappa;")),
wenzelm@23622
   128
    ("\\<lambda>", (1, "&lambda;")),
wenzelm@23622
   129
    ("\\<mu>", (1, "&mu;")),
wenzelm@23622
   130
    ("\\<nu>", (1, "&nu;")),
wenzelm@23622
   131
    ("\\<xi>", (1, "&xi;")),
wenzelm@23622
   132
    ("\\<omicron>", (1, "&omicron;")),
wenzelm@23622
   133
    ("\\<pi>", (1, "&pi;")),
wenzelm@23622
   134
    ("\\<rho>", (1, "&rho;")),
wenzelm@23622
   135
    ("\\<sigma>", (1, "&sigma;")),
wenzelm@23622
   136
    ("\\<tau>", (1, "&tau;")),
wenzelm@23622
   137
    ("\\<upsilon>", (1, "&upsilon;")),
wenzelm@23622
   138
    ("\\<phi>", (1, "&phi;")),
wenzelm@23622
   139
    ("\\<chi>", (1, "&chi;")),
wenzelm@23622
   140
    ("\\<psi>", (1, "&psi;")),
wenzelm@23622
   141
    ("\\<omega>", (1, "&omega;")),
wenzelm@23622
   142
    ("\\<bullet>", (1, "&bull;")),
wenzelm@23622
   143
    ("\\<dots>", (1, "&hellip;")),
wenzelm@23622
   144
    ("\\<Re>", (1, "&real;")),
wenzelm@23622
   145
    ("\\<Im>", (1, "&image;")),
wenzelm@23622
   146
    ("\\<wp>", (1, "&weierp;")),
wenzelm@23622
   147
    ("\\<forall>", (1, "&forall;")),
wenzelm@23622
   148
    ("\\<partial>", (1, "&part;")),
wenzelm@23622
   149
    ("\\<exists>", (1, "&exist;")),
wenzelm@23622
   150
    ("\\<emptyset>", (1, "&empty;")),
wenzelm@23622
   151
    ("\\<nabla>", (1, "&nabla;")),
wenzelm@23622
   152
    ("\\<in>", (1, "&isin;")),
wenzelm@23622
   153
    ("\\<notin>", (1, "&notin;")),
wenzelm@23622
   154
    ("\\<Prod>", (1, "&prod;")),
wenzelm@23622
   155
    ("\\<Sum>", (1, "&sum;")),
wenzelm@23622
   156
    ("\\<star>", (1, "&lowast;")),
wenzelm@23622
   157
    ("\\<propto>", (1, "&prop;")),
wenzelm@23622
   158
    ("\\<infinity>", (1, "&infin;")),
wenzelm@23622
   159
    ("\\<angle>", (1, "&ang;")),
wenzelm@23622
   160
    ("\\<and>", (1, "&and;")),
wenzelm@23622
   161
    ("\\<or>", (1, "&or;")),
wenzelm@23622
   162
    ("\\<inter>", (1, "&cap;")),
wenzelm@23622
   163
    ("\\<union>", (1, "&cup;")),
wenzelm@23622
   164
    ("\\<sim>", (1, "&sim;")),
wenzelm@23622
   165
    ("\\<cong>", (1, "&cong;")),
wenzelm@23622
   166
    ("\\<approx>", (1, "&asymp;")),
wenzelm@23622
   167
    ("\\<noteq>", (1, "&ne;")),
wenzelm@23622
   168
    ("\\<equiv>", (1, "&equiv;")),
wenzelm@23622
   169
    ("\\<le>", (1, "&le;")),
wenzelm@23622
   170
    ("\\<ge>", (1, "&ge;")),
wenzelm@23622
   171
    ("\\<subset>", (1, "&sub;")),
wenzelm@23622
   172
    ("\\<supset>", (1, "&sup;")),
wenzelm@23622
   173
    ("\\<subseteq>", (1, "&sube;")),
wenzelm@23622
   174
    ("\\<supseteq>", (1, "&supe;")),
wenzelm@23622
   175
    ("\\<oplus>", (1, "&oplus;")),
wenzelm@23622
   176
    ("\\<otimes>", (1, "&otimes;")),
wenzelm@23622
   177
    ("\\<bottom>", (1, "&perp;")),
wenzelm@23622
   178
    ("\\<lceil>", (1, "&lceil;")),
wenzelm@23622
   179
    ("\\<rceil>", (1, "&rceil;")),
wenzelm@23622
   180
    ("\\<lfloor>", (1, "&lfloor;")),
wenzelm@23622
   181
    ("\\<rfloor>", (1, "&rfloor;")),
wenzelm@23622
   182
    ("\\<langle>", (1, "&lang;")),
wenzelm@23622
   183
    ("\\<rangle>", (1, "&rang;")),
wenzelm@23622
   184
    ("\\<lozenge>", (1, "&loz;")),
wenzelm@23622
   185
    ("\\<spadesuit>", (1, "&spades;")),
wenzelm@23622
   186
    ("\\<clubsuit>", (1, "&clubs;")),
wenzelm@23622
   187
    ("\\<heartsuit>", (1, "&hearts;")),
wenzelm@23622
   188
    ("\\<diamondsuit>", (1, "&diams;")),
wenzelm@23622
   189
    ("\\<lbrakk>", (2, "[|")),
wenzelm@23622
   190
    ("\\<rbrakk>", (2, "|]")),
wenzelm@23622
   191
    ("\\<Longrightarrow>", (3, "==&gt;")),
wenzelm@23622
   192
    ("\\<Rightarrow>", (2, "=&gt;")),
wenzelm@23622
   193
    ("\\<And>", (2, "!!")),
wenzelm@23622
   194
    ("\\<Colon>", (2, "::")),
wenzelm@23622
   195
    ("\\<lparr>", (2, "(|")),
wenzelm@23622
   196
    ("\\<rparr>", (2, "|)),")),
wenzelm@23622
   197
    ("\\<longleftrightarrow>", (3, "&lt;-&gt;")),
wenzelm@23622
   198
    ("\\<longrightarrow>", (3, "--&gt;")),
wenzelm@23622
   199
    ("\\<rightarrow>", (2, "-&gt;")),
wenzelm@23622
   200
    ("\\<^bsub>", (0, "<sub>")),
wenzelm@23622
   201
    ("\\<^esub>", (0, "</sub>")),
wenzelm@23622
   202
    ("\\<^bsup>", (0, "<sup>")),
wenzelm@23622
   203
    ("\\<^esup>", (0, "</sup>"))];
wenzelm@17178
   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@26709
   209
      | NONE => (size s, XML.text 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@26709
   235
val _ = Output.add_mode htmlN output_width Symbol.encode_raw;
wenzelm@26709
   236
wenzelm@6338
   237
end;
wenzelm@6338
   238
wenzelm@6324
   239
wenzelm@26709
   240
(* common markup *)
wenzelm@23622
   241
wenzelm@26709
   242
fun span s = ("<span class=" ^ Library.quote (XML.text s) ^ ">", "</span>");
wenzelm@6324
   243
wenzelm@27829
   244
val _ = Markup.add_mode htmlN (fn (name, _) => span name);
wenzelm@15801
   245
wenzelm@6324
   246
wenzelm@6324
   247
wenzelm@6324
   248
(** HTML markup **)
wenzelm@6324
   249
wenzelm@6324
   250
type text = string;
wenzelm@6324
   251
wenzelm@6324
   252
wenzelm@6324
   253
(* atoms *)
wenzelm@6324
   254
wenzelm@6324
   255
val plain = output;
wenzelm@19265
   256
val name = enclose "<span class=\"name\">" "</span>" o output;
wenzelm@19265
   257
val keyword = enclose "<span class=\"keyword\">" "</span>" o output;
wenzelm@23622
   258
val command = enclose "<span class=\"command\">" "</span>" o output;
wenzelm@19265
   259
val file_name = enclose "<span class=\"filename\">" "</span>" o output;
wenzelm@21858
   260
val file_path = file_name o Url.implode;
wenzelm@6324
   261
wenzelm@6324
   262
wenzelm@6324
   263
(* misc *)
wenzelm@6324
   264
berghofe@14598
   265
fun href_name s txt = "<a href=" ^ Library.quote s ^ ">" ^ txt ^ "</a>";
wenzelm@21858
   266
fun href_path path txt = href_name (Url.implode path) txt;
wenzelm@6376
   267
skalberg@15531
   268
fun href_opt_path NONE txt = txt
skalberg@15531
   269
  | href_opt_path (SOME p) txt = href_path p txt;
wenzelm@6376
   270
wenzelm@12413
   271
fun para txt = "\n<p>" ^ txt ^ "</p>\n";
wenzelm@27830
   272
fun preform txt = "<pre>" ^ txt ^ "</pre>";
wenzelm@6324
   273
val verbatim = preform o output;
wenzelm@6324
   274
wenzelm@6324
   275
wenzelm@6324
   276
(* document *)
wenzelm@6324
   277
wenzelm@27829
   278
val charset = ref "ISO-8859-1";
wenzelm@24101
   279
fun with_charset s = setmp_noncritical charset s;
wenzelm@17470
   280
wenzelm@6324
   281
fun begin_document title =
wenzelm@27829
   282
  let val cs = ! charset in
wenzelm@27829
   283
    "<?xml version=\"1.0\" encoding=\"" ^ cs ^ "\" ?>\n\
wenzelm@27829
   284
    \<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \
wenzelm@27829
   285
    \\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\
wenzelm@27829
   286
    \<html xmlns=\"http://www.w3.org/1999/xhtml\">\n\
wenzelm@27829
   287
    \<head>\n\
wenzelm@27829
   288
    \<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" ^ cs ^ "\"/>\n\
wenzelm@27829
   289
    \<title>" ^ plain (title ^ " (" ^ Distribution.version ^ ")") ^ "</title>\n\
wenzelm@27829
   290
    \<link media=\"all\" rel=\"stylesheet\" type=\"text/css\" href=\"isabelle.css\"/>\n\
wenzelm@27829
   291
    \</head>\n\
wenzelm@27829
   292
    \\n\
wenzelm@27829
   293
    \<body>\n\
wenzelm@27829
   294
    \<div class=\"head\">\
wenzelm@27829
   295
    \<h1>" ^ plain title ^ "</h1>\n"
wenzelm@27829
   296
  end;
wenzelm@6324
   297
kleing@14541
   298
val end_document = "\n</div>\n</body>\n</html>\n";
wenzelm@6324
   299
wenzelm@6754
   300
fun gen_link how (path, name) = para (href_path path how ^ " to index of " ^ plain name);
wenzelm@6754
   301
val up_link = gen_link "Up";
wenzelm@6754
   302
val back_link = gen_link "Back";
wenzelm@6338
   303
wenzelm@6338
   304
wenzelm@6338
   305
(* session index *)
wenzelm@6338
   306
wenzelm@17080
   307
fun begin_index up (index_path, session) docs graph =
wenzelm@6754
   308
  begin_document ("Index of " ^ session) ^ up_link up ^
wenzelm@6754
   309
  para ("View " ^ href_path graph "theory dependencies" ^
wenzelm@27829
   310
    implode (map (fn (p, name) => "<br/>\nView " ^ href_path p name) docs)) ^
wenzelm@27829
   311
  "\n</div>\n<hr/>\n<div class=\"theories\">\n<h2>Theories</h2>\n<ul>\n";
wenzelm@6338
   312
wenzelm@6338
   313
val end_index = end_document;
wenzelm@6338
   314
berghofe@6649
   315
fun choice chs s = space_implode " " (map (fn (s', lnk) =>
berghofe@6649
   316
  enclose "[" "]" (if s = s' then keyword s' else href_name lnk s')) chs);
berghofe@6649
   317
wenzelm@9415
   318
fun applet_pages session back =
berghofe@6649
   319
  let
wenzelm@9415
   320
    val sizes =
wenzelm@9415
   321
     [("small", "small.html", ("500", "400")),
wenzelm@9415
   322
      ("medium", "medium.html", ("650", "520")),
wenzelm@9415
   323
      ("large", "large.html", ("800", "640"))];
berghofe@6649
   324
wenzelm@9415
   325
    fun applet_page (size, name, (width, height)) =
wenzelm@6754
   326
      let
wenzelm@6754
   327
        val browser_size = "Set browser size: " ^
wenzelm@9415
   328
          choice (map (fn (y, z, _) => (y, z)) sizes) size;
wenzelm@6754
   329
      in
wenzelm@6754
   330
        (name, begin_document ("Theory dependencies of " ^ session) ^
wenzelm@6754
   331
          back_link back ^
wenzelm@9415
   332
          para browser_size ^
wenzelm@27829
   333
          "\n</div>\n<hr/>\n<div class=\"graphbrowser\">\n\
wenzelm@17080
   334
          \<applet code=\"GraphBrowser/GraphBrowser.class\" \
kleing@14541
   335
          \archive=\"GraphBrowser.jar\" \
berghofe@9045
   336
          \width=" ^ width ^ " height=" ^ height ^ ">\n\
wenzelm@9415
   337
          \<param name=\"graphfile\" value=\"" ^ "session.graph" ^ "\">\n\
wenzelm@27829
   338
          \</applet>\n<hr/>" ^ end_document)
berghofe@6649
   339
      end;
wenzelm@9415
   340
  in map applet_page sizes end;
berghofe@6649
   341
berghofe@6649
   342
wenzelm@27829
   343
fun entry (p, s) = "<li>" ^ href_path p (plain s) ^ "</li>\n";
wenzelm@6405
   344
wenzelm@6338
   345
val theory_entry = entry;
wenzelm@6338
   346
wenzelm@6405
   347
fun session_entries [] = "</ul>"
wenzelm@6405
   348
  | session_entries es =
wenzelm@27829
   349
      "</ul>\n</div>\n<hr/>\n<div class=\"sessions\">\n\
wenzelm@17080
   350
      \<h2>Sessions</h2>\n<ul>\n" ^ implode (map entry es) ^ "</ul>";
wenzelm@6324
   351
wenzelm@6324
   352
wenzelm@6324
   353
(* theory *)
wenzelm@6324
   354
wenzelm@14571
   355
fun verbatim_source ss =
wenzelm@27830
   356
  "\n</div>\n<hr/>\n<div class=\"source\">\n<pre>" ^
wenzelm@17178
   357
  implode (output_symbols ss) ^
wenzelm@27829
   358
  "</pre>\n</div>\n<hr/>\n<div class=\"theorems\">\n";
wenzelm@6324
   359
wenzelm@6324
   360
wenzelm@6324
   361
local
wenzelm@27490
   362
  fun file (href, path, loadit) =
wenzelm@27490
   363
    href_path href (if loadit then file_path path else enclose "(" ")" (file_path path));
wenzelm@6361
   364
wenzelm@6376
   365
  fun theory up A =
wenzelm@6376
   366
    begin_document ("Theory " ^ A) ^ "\n" ^ up_link up ^
wenzelm@23622
   367
    command "theory" ^ " " ^ name A;
wenzelm@16267
   368
wenzelm@16267
   369
  fun imports Bs =
wenzelm@16267
   370
    keyword "imports" ^ " " ^ space_implode " " (map (uncurry href_opt_path o apsnd name) Bs);
wenzelm@16267
   371
wenzelm@27829
   372
  fun uses Ps = keyword "uses" ^ " " ^ space_implode " " (map file Ps) ^ "<br/>\n";
wenzelm@6324
   373
in
wenzelm@6324
   374
wenzelm@16267
   375
fun begin_theory up A Bs Ps body =
wenzelm@27829
   376
  theory up A ^ "<br/>\n" ^
wenzelm@27829
   377
  imports Bs ^ "<br/>\n" ^
wenzelm@16267
   378
  (if null Ps then "" else uses Ps) ^
wenzelm@27829
   379
  keyword "begin" ^ "<br/>\n" ^
wenzelm@16267
   380
  body;
wenzelm@16267
   381
wenzelm@6324
   382
end;
wenzelm@6324
   383
wenzelm@6338
   384
val end_theory = end_document;
wenzelm@6324
   385
wenzelm@6324
   386
wenzelm@6324
   387
(* ML file *)
wenzelm@6324
   388
wenzelm@6324
   389
fun ml_file path str =
wenzelm@21858
   390
  begin_document ("File " ^ Url.implode path) ^
wenzelm@27829
   391
  "\n</div>\n<hr/><div class=\"mlsource\">\n" ^
wenzelm@14571
   392
  verbatim str ^
wenzelm@27829
   393
  "\n</div>\n<hr/>\n<div class=\"mlfooter\">\n" ^
kleing@14541
   394
  end_document;
wenzelm@6324
   395
wenzelm@6324
   396
wenzelm@7408
   397
(* theorems *)
wenzelm@6324
   398
wenzelm@7572
   399
local
wenzelm@7572
   400
wenzelm@22122
   401
fun string_of_thm ctxt =
wenzelm@14839
   402
  Output.output o Pretty.setmp_margin 80 Pretty.string_of o
wenzelm@22122
   403
    setmp show_question_marks false (ProofContext.pretty_thm ctxt);
wenzelm@6324
   404
wenzelm@27830
   405
fun thm ctxt th = prefix_lines "  " (html_mode (string_of_thm ctxt) th);
wenzelm@7408
   406
wenzelm@7572
   407
fun thm_name "" = ""
wenzelm@7572
   408
  | thm_name a = " " ^ name (a ^ ":");
wenzelm@7572
   409
wenzelm@7572
   410
in
wenzelm@7572
   411
wenzelm@27830
   412
fun result ctxt k (a, ths) = preform (cat_lines ((command k ^ thm_name a) :: map (thm ctxt) ths));
wenzelm@7572
   413
wenzelm@22122
   414
fun results _ _ [] = ""
wenzelm@22122
   415
  | results ctxt k (res :: ress) = cat_lines (result ctxt k res :: map (result ctxt "and") ress);
wenzelm@7572
   416
wenzelm@7572
   417
end;
wenzelm@6324
   418
wenzelm@6324
   419
wenzelm@7634
   420
(* sections *)
wenzelm@6324
   421
wenzelm@8088
   422
fun chapter heading = "\n\n<h1>" ^ plain heading ^ "</h1>\n";
wenzelm@6324
   423
fun section heading = "\n\n<h2>" ^ plain heading ^ "</h2>\n";
wenzelm@7634
   424
fun subsection heading = "\n\n<h3>" ^ plain heading ^ "</h3>\n";
wenzelm@7634
   425
fun subsubsection heading = "\n\n<h4>" ^ plain heading ^ "</h4>\n";
wenzelm@6324
   426
wenzelm@6324
   427
end;