author | wenzelm |
Mon, 05 Sep 2016 23:11:00 +0200 | |
changeset 63806 | c54a53ef1873 |
parent 62529 | 8b7bdfc09f3b |
child 63934 | 397b25cee74c |
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 = |
|
51 |
if Symbol.is_raw s then Symbol.decode_raw s |
|
52 |
else |
|
53 |
(case Symtab.lookup tab s of |
|
54 |
SOME x => x |
|
55 |
| NONE => XML.text s); |
|
56 |
||
57 |
end; |
|
58 |
||
6338 | 59 |
local |
61376
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
60 |
|
61381 | 61 |
fun output_markup (bg, en) symbols s1 s2 = |
62 |
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
|
63 |
|
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
64 |
val output_sub = output_markup ("<sub>", "</sub>"); |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
65 |
val output_sup = output_markup ("<sup>", "</sup>"); |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
66 |
val output_bold = output_markup (span "bold"); |
17178 | 67 |
|
61381 | 68 |
fun output_syms _ [] result = implode (rev result) |
69 |
| output_syms symbols (s1 :: rest) result = |
|
61376
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
70 |
let |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
71 |
val (s2, ss) = (case rest of [] => ("", []) | s2 :: ss => (s2, ss)); |
61381 | 72 |
val (s, r) = |
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
73 |
if s1 = "\<^sub>" then (output_sub symbols "⇩" s2, ss) |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
74 |
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
|
75 |
else if s1 = "\<^bold>" then (output_bold symbols "❙" s2, ss) |
61381 | 76 |
else (output_sym symbols s1, rest); |
77 |
in output_syms symbols r (s :: result) end; |
|
14534 | 78 |
|
6338 | 79 |
in |
6324 | 80 |
|
61381 | 81 |
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
|
82 |
|
6338 | 83 |
end; |
84 |
||
6324 | 85 |
|
61379
c57820ceead3
more direct HTML presentation, without print mode;
wenzelm
parents:
61376
diff
changeset
|
86 |
(* presentation *) |
c57820ceead3
more direct HTML presentation, without print mode;
wenzelm
parents:
61376
diff
changeset
|
87 |
|
61381 | 88 |
fun present_span symbols keywords = |
89 |
let |
|
90 |
fun present_token tok = |
|
91 |
fold_rev (uncurry enclose o span o #1) |
|
92 |
(Token.markups keywords tok) (output symbols (Token.unparse tok)); |
|
93 |
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
|
94 |
|
c57820ceead3
more direct HTML presentation, without print mode;
wenzelm
parents:
61376
diff
changeset
|
95 |
|
6324 | 96 |
|
97 |
(** HTML markup **) |
|
98 |
||
99 |
type text = string; |
|
100 |
||
101 |
||
102 |
(* atoms *) |
|
103 |
||
61381 | 104 |
val name = enclose "<span class=\"name\">" "</span>" oo output; |
105 |
val keyword = enclose "<span class=\"keyword\">" "</span>" oo output; |
|
106 |
val command = enclose "<span class=\"command\">" "</span>" oo output; |
|
6324 | 107 |
|
108 |
||
109 |
(* misc *) |
|
110 |
||
28840 | 111 |
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
|
112 |
fun href_path path txt = href_name (Url.implode path) txt; |
6376 | 113 |
|
15531 | 114 |
fun href_opt_path NONE txt = txt |
115 |
| href_opt_path (SOME p) txt = href_path p txt; |
|
6376 | 116 |
|
12413 | 117 |
fun para txt = "\n<p>" ^ txt ^ "</p>\n"; |
6324 | 118 |
|
119 |
||
120 |
(* document *) |
|
121 |
||
61381 | 122 |
fun begin_document symbols title = |
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
123 |
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
124 |
"<!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
|
125 |
"\"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
|
126 |
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
127 |
"<head>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
128 |
"<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
|
129 |
"<title>" ^ output symbols (title ^ " (" ^ Distribution.version ^ ")") ^ "</title>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
130 |
"<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
|
131 |
"</head>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
132 |
"\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
133 |
"<body>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
134 |
"<div class=\"head\">" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
135 |
"<h1>" ^ output symbols title ^ "</h1>\n"; |
6324 | 136 |
|
14541 | 137 |
val end_document = "\n</div>\n</body>\n</html>\n"; |
6324 | 138 |
|
6338 | 139 |
|
140 |
(* session index *) |
|
141 |
||
61381 | 142 |
fun begin_session_index symbols session graph docs = |
143 |
begin_document symbols ("Session " ^ output symbols session) ^ |
|
6754 | 144 |
para ("View " ^ href_path graph "theory dependencies" ^ |
27829 | 145 |
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
|
146 |
"\n</div>\n<div class=\"theories\">\n<h2>Theories</h2>\n<ul>\n"; |
6338 | 147 |
|
61381 | 148 |
fun theory_entry symbols (p, s) = "<li>" ^ href_path p (output symbols s) ^ "</li>\n"; |
6324 | 149 |
|
150 |
||
151 |
(* theory *) |
|
152 |
||
61381 | 153 |
fun theory symbols A Bs txt = |
154 |
begin_document symbols ("Theory " ^ A) ^ "\n" ^ |
|
155 |
command symbols "theory" ^ " " ^ name symbols A ^ "<br/>\n" ^ |
|
156 |
keyword symbols "imports" ^ " " ^ |
|
157 |
space_implode " " (map (uncurry href_opt_path o apsnd (name symbols)) Bs) ^ |
|
54456 | 158 |
"<br/>\n" ^ |
61374 | 159 |
enclose "\n</div>\n<div class=\"source\">\n<pre class=\"source\">" "</pre>\n" txt ^ |
54456 | 160 |
end_document; |
16267
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
161 |
|
6324 | 162 |
end; |