src/Pure/Thy/html.ML
author kleing
Mon, 12 Apr 2004 23:52:51 +0200
changeset 14541 0a7743e2f8dd
parent 14534 7a46bdcd92f2
child 14552 e88f52b775a5
permissions -rw-r--r--
use css use Graphrowser.jar instead of .class files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/HTML.ML
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
9415
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
     3
    Author:     Markus Wenzel and Stefan Berghofer, TU Muenchen
8808
wenzelm
parents: 8190
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
     5
9415
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
     6
HTML presentation elements.
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
     7
*)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
     8
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
     9
signature HTML =
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    10
sig
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    11
  val output: string -> string
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    12
  val output_width: string -> string * real
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    13
  type text (* = string *)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    14
  val plain: string -> text
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    15
  val name: string -> text
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    16
  val keyword: string -> text
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    17
  val file_name: string -> text
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
    18
  val file_path: Url.T -> text
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    19
  val href_name: string -> text -> text
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
    20
  val href_path: Url.T -> text -> text
6376
wenzelm
parents: 6361
diff changeset
    21
  val href_opt_name: string option -> text -> text
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
    22
  val href_opt_path: Url.T option -> text -> text
6376
wenzelm
parents: 6361
diff changeset
    23
  val para: text -> text
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    24
  val preform: text -> text
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    25
  val verbatim: string -> text
7725
760021510e6b begin_index: document;
wenzelm
parents: 7634
diff changeset
    26
  val begin_index: Url.T * string -> Url.T * string -> Url.T option
760021510e6b begin_index: document;
wenzelm
parents: 7634
diff changeset
    27
    -> Url.T option -> Url.T -> text
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
    28
  val end_index: text
9415
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
    29
  val applet_pages: string -> Url.T * string -> (string * string) list
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
    30
  val theory_entry: Url.T * string -> text
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
    31
  val session_entries: (Url.T * string) list -> text
8190
wenzelm
parents: 8088
diff changeset
    32
  val verbatim_source: Symbol.symbol list -> text
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
    33
  val begin_theory: Url.T * string -> string -> (Url.T option * string) list ->
7408
1ec1567c1307 added theorems;
wenzelm
parents: 6754
diff changeset
    34
    (Url.T option * Url.T * bool option) list -> text -> text
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    35
  val end_theory: text
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
    36
  val ml_file: Url.T -> string -> text
13531
5825aef91ac5 simplified results;
wenzelm
parents: 12413
diff changeset
    37
  val results: string -> (string * thm list) list -> text
8088
6ae943d080de chapter;
wenzelm
parents: 7831
diff changeset
    38
  val chapter: string -> text
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    39
  val section: string -> text
7634
c326808da921 more sections;
wenzelm
parents: 7572
diff changeset
    40
  val subsection: string -> text
c326808da921 more sections;
wenzelm
parents: 7572
diff changeset
    41
  val subsubsection: string -> text
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    42
  val setup: (theory -> theory) list
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    43
end;
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    44
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    45
structure HTML: HTML =
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    46
struct
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    47
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    48
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    49
(** HTML print modes **)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    50
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    51
(* mode *)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    52
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    53
val htmlN = "HTML";
10573
1751ab881289 append print modes;
wenzelm
parents: 9963
diff changeset
    54
fun html_mode f x = setmp print_mode (htmlN :: ! print_mode) f x;
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    55
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    56
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    57
(* symbol output *)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    58
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
    59
local
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
    60
  val escape = fn "<" => "&lt;" | ">" => "&gt;" | "&" => "&amp;" | c => c;
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
    61
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
    62
  val output_sym =
9963
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    63
    fn "\\<spacespace>" => (2.0, "&nbsp;&nbsp;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    64
     | "\\<exclamdown>" => (1.0, "&iexcl;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    65
     | "\\<cent>" => (1.0, "&cent;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    66
     | "\\<pounds>" => (1.0, "&pound;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    67
     | "\\<currency>" => (1.0, "&curren;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    68
     | "\\<yen>" => (1.0, "&yen;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    69
     | "\\<bar>" => (1.0, "&brvbar;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    70
     | "\\<section>" => (1.0, "&sect;")
10837
7d640de604e4 added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents: 10831
diff changeset
    71
     | "\\<dieresis>" => (1.0, "&uml;")
9963
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    72
     | "\\<copyright>" => (1.0, "&copy;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    73
     | "\\<ordfeminine>" => (1.0, "&ordf;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    74
     | "\\<guillemotleft>" => (1.0, "&laquo;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    75
     | "\\<not>" => (1.0, "&not;")
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
    76
     | "\\<hyphen>" => (1.0, "&shy;")
9963
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    77
     | "\\<registered>" => (1.0, "&reg;")
10831
024bdf8e52a4 replaced \<macron> by \<inverse>;
wenzelm
parents: 10573
diff changeset
    78
     | "\\<inverse>" => (1.0, "&macr;")
9963
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    79
     | "\\<degree>" => (1.0, "&deg;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    80
     | "\\<plusminus>" => (1.0, "&plusmn;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    81
     | "\\<twosuperior>" => (1.0, "&sup2;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    82
     | "\\<threesuperior>" => (1.0, "&sup3;")
10837
7d640de604e4 added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents: 10831
diff changeset
    83
     | "\\<acute>" => (1.0, "&acute;")
9963
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    84
     | "\\<mu>" => (1.0, "&micro;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    85
     | "\\<paragraph>" => (1.0, "&para;")
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
    86
     | "\\<cdot>" => (1.0, "&middot;")
10837
7d640de604e4 added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents: 10831
diff changeset
    87
     | "\\<cedilla>" => (1.0, "&cedil;")
9963
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    88
     | "\\<onesuperior>" => (1.0, "&sup1;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    89
     | "\\<ordmasculine>" => (1.0, "&ordm;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    90
     | "\\<guillemotright>" => (1.0, "&raquo;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    91
     | "\\<onequarter>" => (1.0, "&frac14;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    92
     | "\\<onehalf>" => (1.0, "&frac12;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    93
     | "\\<threequarters>" => (1.0, "&frac34;")
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    94
     | "\\<questiondown>" => (1.0, "&iquest;")
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
    95
     | "\\<times>" => (1.0, "&times;")
10837
7d640de604e4 added \<dieresis>, \<acute>, \<cedilla>, \<emptyset>;
wenzelm
parents: 10831
diff changeset
    96
     | "\\<emptyset>" => (1.0, "&Oslash;")
9963
6342d9c7fe46 handle more symbols;
wenzelm
parents: 9415
diff changeset
    97
     | "\\<div>" => (1.0, "&divide;")
14534
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
    98
     | "\\<^bsub>" => (0.0, "<sub>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
    99
     | "\\<^esub>" => (0.0, "</sub>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   100
     | "\\<^bsup>" => (0.0, "<sup>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   101
     | "\\<^esup>" => (0.0, "</sup>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   102
(* keep \<^sub> etc, so it does not get destroyed by default case *)
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   103
     | "\\<^sup>" => (0.0, "\\<^sup>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   104
     | "\\<^sub>" => (0.0, "\\<^sub>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   105
     | "\\<^isup>" => (0.0, "\\<^isup>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   106
     | "\\<^isub>" => (0.0, "\\<^isub>")
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   107
     | s => (real (size s), implode (map escape (explode s)));
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   108
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   109
  fun add_sym (width, (w: real, s)) = (width + w, s);
14534
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   110
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   111
  fun script (0, "\\<^sub>") = (1,"<sub>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   112
    | script (0, "\\<^isub>") = (1,"<sub>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   113
    | script (1, x) = (0, x ^ "</sub>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   114
    | script (0, "\\<^sup>") = (2,"<sup>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   115
    | script (0, "\\<^isup>") = (2,"<sup>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   116
    | script (2, x) = (0, x ^ "</sup>")
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   117
    | script (s, x) = (s,x);
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   118
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   119
  fun scrs (s, []) = (s,[])
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   120
    | scrs (s, x::xs) = let val (s', x') = script (s, x)
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   121
                            val (s'', xs') = scrs (s', xs)
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   122
                        in (s'', x'::xs') end;
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   123
                           
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   124
  fun scripts ss = #2 (scrs (0,ss));
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   125
in
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   126
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   127
fun output_width str =
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   128
  if not (exists_string (equal "<" orf equal ">" orf equal "&") str) then (str, real (size str))
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   129
  else
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   130
    let val (width, syms) = foldl_map add_sym (0.0, map output_sym (Symbol.explode str))
14534
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   131
    in (implode (scripts syms), width) end;
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   132
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   133
val output = #1 o output_width;
14534
7a46bdcd92f2 treat sub/super scripts
kleing
parents: 14083
diff changeset
   134
val output_symbols = scripts o (map (#2 o output_sym))
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   135
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   136
end;
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   137
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   138
10954
a555bfb66c2d setup indent;
wenzelm
parents: 10873
diff changeset
   139
val _ = Symbol.add_mode htmlN (output_width, Symbol.default_indent);
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   140
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   141
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   142
(* token translations *)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   143
14541
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   144
fun style stl =
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   145
  apfst (enclose ("<span class=" ^ quote stl ^ ">") "</span>") o output_width;
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   146
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   147
val html_trans =
14541
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   148
 [("class", style "tclass"),
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   149
  ("tfree", style "tfree"),
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   150
  ("tvar",  style "tvar"),
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   151
  ("free",  style "free"),
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   152
  ("bound", style "bound"),
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   153
  ("var",   style "var"),
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   154
  ("xstr",  style "xstr")];
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   155
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   156
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   157
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   158
(** HTML markup **)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   159
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   160
type text = string;
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   161
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   162
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   163
(* atoms *)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   164
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   165
val plain = output;
14541
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   166
fun name s = "<span class=\"name\">" ^ output s ^ "</span>";
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   167
fun keyword s = "<span class=\"keyword\">" ^ output s ^ "</span>";
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   168
fun file_name s = "<span class=\"filename\">" ^ output s ^ "</span>";
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
   169
val file_path = file_name o Url.pack;
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   170
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   171
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   172
(* misc *)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   173
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   174
fun href_name s txt = "<a href=" ^ quote s ^ ">" ^ txt ^ "</a>";
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
   175
fun href_path path txt = href_name (Url.pack path) txt;
6376
wenzelm
parents: 6361
diff changeset
   176
wenzelm
parents: 6361
diff changeset
   177
fun href_opt_name None txt = txt
wenzelm
parents: 6361
diff changeset
   178
  | href_opt_name (Some s) txt = href_name s txt;
wenzelm
parents: 6361
diff changeset
   179
wenzelm
parents: 6361
diff changeset
   180
fun href_opt_path None txt = txt
wenzelm
parents: 6361
diff changeset
   181
  | href_opt_path (Some p) txt = href_path p txt;
wenzelm
parents: 6361
diff changeset
   182
12413
f879fcc9412d tuned line breaks in HTML source;
wenzelm
parents: 12151
diff changeset
   183
fun para txt = "\n<p>" ^ txt ^ "</p>\n";
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   184
fun preform txt = "<pre>" ^ txt ^ "</pre>";
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   185
val verbatim = preform o output;
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   186
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   187
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   188
(* document *)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   189
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   190
fun begin_document title =
14083
aed5d25c4a0c Added DOCTYPE and Content-type to HTML documents.
webertj
parents: 13531
diff changeset
   191
  "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n\
aed5d25c4a0c Added DOCTYPE and Content-type to HTML documents.
webertj
parents: 13531
diff changeset
   192
  \\n\
aed5d25c4a0c Added DOCTYPE and Content-type to HTML documents.
webertj
parents: 13531
diff changeset
   193
  \<html>\n\
6405
wenzelm
parents: 6376
diff changeset
   194
  \<head>\n\
14083
aed5d25c4a0c Added DOCTYPE and Content-type to HTML documents.
webertj
parents: 13531
diff changeset
   195
  \<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n\
6405
wenzelm
parents: 6376
diff changeset
   196
  \<title>" ^ plain (title ^ " (" ^ version ^ ")") ^ "</title>\n\
14541
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   197
  \<link rel=\"stylesheet\" type=\"text/css\" href=\"isabelle.css\">\n\
6405
wenzelm
parents: 6376
diff changeset
   198
  \</head>\n\
wenzelm
parents: 6376
diff changeset
   199
  \\n\
wenzelm
parents: 6376
diff changeset
   200
  \<body>\n\
14541
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   201
  \<div class=\"head\">\
6405
wenzelm
parents: 6376
diff changeset
   202
  \<h1>" ^ plain title ^ "</h1>\n"
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   203
14541
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   204
val end_document = "\n</div>\n</body>\n</html>\n";
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   205
6754
c23c542a32e5 tuned markup;
wenzelm
parents: 6649
diff changeset
   206
fun gen_link how (path, name) = para (href_path path how ^ " to index of " ^ plain name);
c23c542a32e5 tuned markup;
wenzelm
parents: 6649
diff changeset
   207
val up_link = gen_link "Up";
c23c542a32e5 tuned markup;
wenzelm
parents: 6649
diff changeset
   208
val back_link = gen_link "Back";
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   209
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   210
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   211
(* session index *)
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   212
7725
760021510e6b begin_index: document;
wenzelm
parents: 7634
diff changeset
   213
fun begin_index up (index_path, session) opt_readme opt_doc graph =
6754
c23c542a32e5 tuned markup;
wenzelm
parents: 6649
diff changeset
   214
  begin_document ("Index of " ^ session) ^ up_link up ^
c23c542a32e5 tuned markup;
wenzelm
parents: 6649
diff changeset
   215
  para ("View " ^ href_path graph "theory dependencies" ^
7725
760021510e6b begin_index: document;
wenzelm
parents: 7634
diff changeset
   216
    (case opt_readme of None => "" | Some p => "<br>\nView " ^ href_path p "README") ^
760021510e6b begin_index: document;
wenzelm
parents: 7634
diff changeset
   217
    (case opt_doc of None => "" | Some p => "<br>\nView " ^ href_path p "document")) ^
14541
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   218
  "\n</div>\n<hr>\n<div class=\"theories\">\n<h2>Theories</h2>\n<ul>\n";
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   219
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   220
val end_index = end_document;
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   221
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
   222
fun choice chs s = space_implode " " (map (fn (s', lnk) =>
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
   223
  enclose "[" "]" (if s = s' then keyword s' else href_name lnk s')) chs);
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
   224
9415
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
   225
fun applet_pages session back =
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
   226
  let
9415
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
   227
    val sizes =
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
   228
     [("small", "small.html", ("500", "400")),
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
   229
      ("medium", "medium.html", ("650", "520")),
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
   230
      ("large", "large.html", ("800", "640"))];
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
   231
9415
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
   232
    fun applet_page (size, name, (width, height)) =
6754
c23c542a32e5 tuned markup;
wenzelm
parents: 6649
diff changeset
   233
      let
c23c542a32e5 tuned markup;
wenzelm
parents: 6649
diff changeset
   234
        val browser_size = "Set browser size: " ^
9415
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
   235
          choice (map (fn (y, z, _) => (y, z)) sizes) size;
6754
c23c542a32e5 tuned markup;
wenzelm
parents: 6649
diff changeset
   236
      in
c23c542a32e5 tuned markup;
wenzelm
parents: 6649
diff changeset
   237
        (name, begin_document ("Theory dependencies of " ^ session) ^
c23c542a32e5 tuned markup;
wenzelm
parents: 6649
diff changeset
   238
          back_link back ^
9415
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
   239
          para browser_size ^
14541
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   240
          "\n</div>\n<hr>\n<div class=\"graphbrowser\">\n<applet code=\"GraphBrowser/GraphBrowser.class\" \
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   241
          \archive=\"GraphBrowser.jar\" \
9045
a5bfcd4c2a5e Removed codebase attribute from applet_pages.
berghofe
parents: 8808
diff changeset
   242
          \width=" ^ width ^ " height=" ^ height ^ ">\n\
9415
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
   243
          \<param name=\"graphfile\" value=\"" ^ "session.graph" ^ "\">\n\
6754
c23c542a32e5 tuned markup;
wenzelm
parents: 6649
diff changeset
   244
          \</applet>\n<hr>" ^ end_document)
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
   245
      end;
9415
daa2296f23ea removed all_sessions;
wenzelm
parents: 9045
diff changeset
   246
  in map applet_page sizes end;
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
   247
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
   248
6405
wenzelm
parents: 6376
diff changeset
   249
fun entry (p, s) = "<li>" ^ href_path p (plain s) ^ "\n";
wenzelm
parents: 6376
diff changeset
   250
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   251
val theory_entry = entry;
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   252
6405
wenzelm
parents: 6376
diff changeset
   253
fun session_entries [] = "</ul>"
wenzelm
parents: 6376
diff changeset
   254
  | session_entries es =
14541
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   255
      "</ul>\n</div>\n<hr>\n<div class=\"sessions\">\n<h2>Sessions</h2>\n<ul>\n" ^ implode (map entry es) ^ "</ul>";
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   256
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   257
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   258
(* theory *)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   259
14541
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   260
fun verbatim_source ss = "\n</div>\n<hr>\n<div class=\"source\">\n<pre>" ^ 
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   261
                         implode (output_symbols ss)  ^ 
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   262
                         "</pre>\n</div>\n<hr>\n<div class=\"theorems\">\n";
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   263
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   264
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   265
local
7408
1ec1567c1307 added theorems;
wenzelm
parents: 6754
diff changeset
   266
  fun encl None = enclose "[" "]"
1ec1567c1307 added theorems;
wenzelm
parents: 6754
diff changeset
   267
    | encl (Some false) = enclose "(" ")"
1ec1567c1307 added theorems;
wenzelm
parents: 6754
diff changeset
   268
    | encl (Some true) = I;
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   269
7408
1ec1567c1307 added theorems;
wenzelm
parents: 6754
diff changeset
   270
  fun file (opt_ref, path, loadit) = href_opt_path opt_ref (encl loadit (file_path path));
7831
2a13c396201d files: separate by " ";
wenzelm
parents: 7725
diff changeset
   271
  val files = space_implode " " o map file;
6376
wenzelm
parents: 6361
diff changeset
   272
  val parents = space_implode " + " o map (uncurry href_opt_path o apsnd name);
6361
3a45ad4a95eb theory: include parent links;
wenzelm
parents: 6347
diff changeset
   273
6376
wenzelm
parents: 6361
diff changeset
   274
  fun theory up A =
wenzelm
parents: 6361
diff changeset
   275
    begin_document ("Theory " ^ A) ^ "\n" ^ up_link up ^
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   276
    keyword "theory" ^ " " ^ name A ^ " = ";
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   277
in
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   278
6376
wenzelm
parents: 6361
diff changeset
   279
fun begin_theory up A Bs [] body = theory up A ^ parents Bs ^ ":\n" ^ body
12413
f879fcc9412d tuned line breaks in HTML source;
wenzelm
parents: 12151
diff changeset
   280
  | begin_theory up A Bs Ps body = theory up A ^ parents Bs ^ "<br>\n" ^ keyword "files" ^
6376
wenzelm
parents: 6361
diff changeset
   281
      " " ^ files Ps ^ ":" ^ "\n" ^ body;
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   282
end;
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   283
6338
bf0d22535e47 output: some symbol translations;
wenzelm
parents: 6324
diff changeset
   284
val end_theory = end_document;
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   285
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   286
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   287
(* ML file *)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   288
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   289
fun ml_file path str =
6649
2156012be986 Reimplemented graph generator.
berghofe
parents: 6405
diff changeset
   290
  begin_document ("File " ^ Url.pack path) ^
14541
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   291
  "\n</div>\n<hr><div class=\"mlsource\">\n" ^ 
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   292
  verbatim str ^ 
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   293
  "\n</div>\n<hr>\n<div class=\"mlfooter\">\n" ^ 
0a7743e2f8dd use css
kleing
parents: 14534
diff changeset
   294
  end_document;
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   295
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   296
7408
1ec1567c1307 added theorems;
wenzelm
parents: 6754
diff changeset
   297
(* theorems *)
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   298
7572
6e6dafacbc28 present results;
wenzelm
parents: 7408
diff changeset
   299
local
6e6dafacbc28 present results;
wenzelm
parents: 7408
diff changeset
   300
7408
1ec1567c1307 added theorems;
wenzelm
parents: 6754
diff changeset
   301
val string_of_thm =
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   302
  Pretty.setmp_margin 80 Pretty.string_of o
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   303
    Display.pretty_thm_no_quote o #1 o Drule.freeze_thaw;
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   304
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   305
fun thm th = preform (prefix_lines "  " (html_mode string_of_thm th));
7408
1ec1567c1307 added theorems;
wenzelm
parents: 6754
diff changeset
   306
7572
6e6dafacbc28 present results;
wenzelm
parents: 7408
diff changeset
   307
fun thm_name "" = ""
6e6dafacbc28 present results;
wenzelm
parents: 7408
diff changeset
   308
  | thm_name a = " " ^ name (a ^ ":");
6e6dafacbc28 present results;
wenzelm
parents: 7408
diff changeset
   309
6e6dafacbc28 present results;
wenzelm
parents: 7408
diff changeset
   310
in
6e6dafacbc28 present results;
wenzelm
parents: 7408
diff changeset
   311
13531
5825aef91ac5 simplified results;
wenzelm
parents: 12413
diff changeset
   312
fun result k (a, ths) = para (cat_lines ((keyword k ^ thm_name a) :: map thm ths));
7572
6e6dafacbc28 present results;
wenzelm
parents: 7408
diff changeset
   313
13531
5825aef91ac5 simplified results;
wenzelm
parents: 12413
diff changeset
   314
fun results _ [] = ""
5825aef91ac5 simplified results;
wenzelm
parents: 12413
diff changeset
   315
  | results k (res :: ress) = cat_lines (result k res :: map (result "and") ress);
7572
6e6dafacbc28 present results;
wenzelm
parents: 7408
diff changeset
   316
6e6dafacbc28 present results;
wenzelm
parents: 7408
diff changeset
   317
end;
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   318
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   319
7634
c326808da921 more sections;
wenzelm
parents: 7572
diff changeset
   320
(* sections *)
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   321
8088
6ae943d080de chapter;
wenzelm
parents: 7831
diff changeset
   322
fun chapter heading = "\n\n<h1>" ^ plain heading ^ "</h1>\n";
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   323
fun section heading = "\n\n<h2>" ^ plain heading ^ "</h2>\n";
7634
c326808da921 more sections;
wenzelm
parents: 7572
diff changeset
   324
fun subsection heading = "\n\n<h3>" ^ plain heading ^ "</h3>\n";
c326808da921 more sections;
wenzelm
parents: 7572
diff changeset
   325
fun subsubsection heading = "\n\n<h4>" ^ plain heading ^ "</h4>\n";
6324
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   326
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   327
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   328
(** theory setup **)
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   329
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   330
val setup =
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   331
 [Theory.add_mode_tokentrfuns htmlN html_trans];
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   332
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   333
3b7111b360b1 HTML markup elements.
wenzelm
parents:
diff changeset
   334
end;