author | wenzelm |
Wed, 12 Apr 2017 17:48:19 +0200 | |
changeset 65468 | c41791ad75c3 |
parent 63934 | 397b25cee74c |
child 66044 | bd7516709051 |
permissions | -rw-r--r-- |
24584 | 1 |
(* Title: Pure/Thy/html.ML |
9415 | 2 |
Author: Markus Wenzel and Stefan Berghofer, TU Muenchen |
6324 | 3 |
|
9415 | 4 |
HTML presentation elements. |
6324 | 5 |
*) |
6 |
||
7 |
signature HTML = |
|
8 |
sig |
|
61381 | 9 |
type symbols |
10 |
val make_symbols: (string * int) list -> symbols |
|
11 |
val no_symbols: symbols |
|
12 |
val present_span: symbols -> Keyword.keywords -> Command_Span.span -> Output.output |
|
23622 | 13 |
type text = string |
61381 | 14 |
val begin_document: symbols -> string -> text |
23724 | 15 |
val end_document: text |
61381 | 16 |
val begin_session_index: symbols -> string -> Url.T -> (Url.T * string) list -> text |
17 |
val theory_entry: symbols -> Url.T * string -> text |
|
18 |
val theory: symbols -> string -> (Url.T option * string) list -> text -> text |
|
6324 | 19 |
end; |
20 |
||
21 |
structure HTML: HTML = |
|
22 |
struct |
|
23 |
||
24 |
||
33985 | 25 |
(* common markup *) |
26 |
||
27 |
fun span class = ("<span class=" ^ quote (XML.text class) ^ ">", "</span>"); |
|
28 |
||
61379
c57820ceead3
more direct HTML presentation, without print mode;
wenzelm
parents:
61376
diff
changeset
|
29 |
val hidden = span Markup.hiddenN |-> enclose; |
33985 | 30 |
|
31 |
||
6324 | 32 |
(* symbol output *) |
33 |
||
61381 | 34 |
abstype symbols = Symbols of string Symtab.table |
35 |
with |
|
36 |
||
37 |
fun make_symbols codes = |
|
38 |
let |
|
39 |
val mapping = |
|
63806 | 40 |
map (apsnd (fn c => "&#" ^ Value.print_int c ^ ";")) codes @ |
61381 | 41 |
[("'", "'"), |
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
42 |
("\<^bsub>", hidden "⇘" ^ "<sub>"), |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
43 |
("\<^esub>", hidden "⇙" ^ "</sub>"), |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
44 |
("\<^bsup>", hidden "⇗" ^ "<sup>"), |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
45 |
("\<^esup>", hidden "⇖" ^ "</sup>")]; |
61381 | 46 |
in Symbols (fold Symtab.update mapping Symtab.empty) end; |
47 |
||
48 |
val no_symbols = make_symbols []; |
|
49 |
||
50 |
fun output_sym (Symbols tab) s = |
|
63934 | 51 |
(case Symtab.lookup tab s of |
52 |
SOME x => x |
|
53 |
| NONE => XML.text s); |
|
61381 | 54 |
|
55 |
end; |
|
56 |
||
6338 | 57 |
local |
61376
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
58 |
|
61381 | 59 |
fun output_markup (bg, en) symbols s1 s2 = |
60 |
hidden s1 ^ enclose bg en (output_sym symbols s2); |
|
61376
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
61 |
|
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
62 |
val output_sub = output_markup ("<sub>", "</sub>"); |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
63 |
val output_sup = output_markup ("<sup>", "</sup>"); |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
64 |
val output_bold = output_markup (span "bold"); |
17178 | 65 |
|
61381 | 66 |
fun output_syms _ [] result = implode (rev result) |
67 |
| output_syms symbols (s1 :: rest) result = |
|
61376
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
68 |
let |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
69 |
val (s2, ss) = (case rest of [] => ("", []) | s2 :: ss => (s2, ss)); |
61381 | 70 |
val (s, r) = |
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
71 |
if s1 = "\<^sub>" then (output_sub symbols "⇩" s2, ss) |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
72 |
else if s1 = "\<^sup>" then (output_sup symbols "⇧" s2, ss) |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
73 |
else if s1 = "\<^bold>" then (output_bold symbols "❙" s2, ss) |
61381 | 74 |
else (output_sym symbols s1, rest); |
75 |
in output_syms symbols r (s :: result) end; |
|
14534 | 76 |
|
6338 | 77 |
in |
6324 | 78 |
|
61381 | 79 |
fun output symbols str = output_syms symbols (Symbol.explode str) []; |
61376
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
80 |
|
6338 | 81 |
end; |
82 |
||
6324 | 83 |
|
61379
c57820ceead3
more direct HTML presentation, without print mode;
wenzelm
parents:
61376
diff
changeset
|
84 |
(* presentation *) |
c57820ceead3
more direct HTML presentation, without print mode;
wenzelm
parents:
61376
diff
changeset
|
85 |
|
61381 | 86 |
fun present_span symbols keywords = |
87 |
let |
|
88 |
fun present_token tok = |
|
89 |
fold_rev (uncurry enclose o span o #1) |
|
90 |
(Token.markups keywords tok) (output symbols (Token.unparse tok)); |
|
91 |
in implode o map present_token o Command_Span.content end; |
|
61379
c57820ceead3
more direct HTML presentation, without print mode;
wenzelm
parents:
61376
diff
changeset
|
92 |
|
c57820ceead3
more direct HTML presentation, without print mode;
wenzelm
parents:
61376
diff
changeset
|
93 |
|
6324 | 94 |
|
95 |
(** HTML markup **) |
|
96 |
||
97 |
type text = string; |
|
98 |
||
99 |
||
100 |
(* atoms *) |
|
101 |
||
61381 | 102 |
val name = enclose "<span class=\"name\">" "</span>" oo output; |
103 |
val keyword = enclose "<span class=\"keyword\">" "</span>" oo output; |
|
104 |
val command = enclose "<span class=\"command\">" "</span>" oo output; |
|
6324 | 105 |
|
106 |
||
107 |
(* misc *) |
|
108 |
||
28840 | 109 |
fun href_name s txt = "<a href=" ^ quote s ^ ">" ^ txt ^ "</a>"; |
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
20742
diff
changeset
|
110 |
fun href_path path txt = href_name (Url.implode path) txt; |
6376 | 111 |
|
15531 | 112 |
fun href_opt_path NONE txt = txt |
113 |
| href_opt_path (SOME p) txt = href_path p txt; |
|
6376 | 114 |
|
12413 | 115 |
fun para txt = "\n<p>" ^ txt ^ "</p>\n"; |
6324 | 116 |
|
117 |
||
118 |
(* document *) |
|
119 |
||
61381 | 120 |
fun begin_document symbols title = |
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
121 |
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
122 |
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
123 |
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
124 |
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
125 |
"<head>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
126 |
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
127 |
"<title>" ^ output symbols (title ^ " (" ^ Distribution.version ^ ")") ^ "</title>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
128 |
"<link media=\"all\" rel=\"stylesheet\" type=\"text/css\" href=\"isabelle.css\"/>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
129 |
"</head>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
130 |
"\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
131 |
"<body>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
132 |
"<div class=\"head\">" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
133 |
"<h1>" ^ output symbols title ^ "</h1>\n"; |
6324 | 134 |
|
14541 | 135 |
val end_document = "\n</div>\n</body>\n</html>\n"; |
6324 | 136 |
|
6338 | 137 |
|
138 |
(* session index *) |
|
139 |
||
61381 | 140 |
fun begin_session_index symbols session graph docs = |
141 |
begin_document symbols ("Session " ^ output symbols session) ^ |
|
6754 | 142 |
para ("View " ^ href_path graph "theory dependencies" ^ |
27829 | 143 |
implode (map (fn (p, name) => "<br/>\nView " ^ href_path p name) docs)) ^ |
37941
1d812ff95a14
refrain from generating <hr/> and from "hiding" it in isabelle.css -- the latter might be used in other situations as well;
wenzelm
parents:
37940
diff
changeset
|
144 |
"\n</div>\n<div class=\"theories\">\n<h2>Theories</h2>\n<ul>\n"; |
6338 | 145 |
|
61381 | 146 |
fun theory_entry symbols (p, s) = "<li>" ^ href_path p (output symbols s) ^ "</li>\n"; |
6324 | 147 |
|
148 |
||
149 |
(* theory *) |
|
150 |
||
61381 | 151 |
fun theory symbols A Bs txt = |
152 |
begin_document symbols ("Theory " ^ A) ^ "\n" ^ |
|
153 |
command symbols "theory" ^ " " ^ name symbols A ^ "<br/>\n" ^ |
|
154 |
keyword symbols "imports" ^ " " ^ |
|
155 |
space_implode " " (map (uncurry href_opt_path o apsnd (name symbols)) Bs) ^ |
|
54456 | 156 |
"<br/>\n" ^ |
61374 | 157 |
enclose "\n</div>\n<div class=\"source\">\n<pre class=\"source\">" "</pre>\n" txt ^ |
54456 | 158 |
end_document; |
16267
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
159 |
|
6324 | 160 |
end; |