author | paulson <lp15@cam.ac.uk> |
Fri, 27 Apr 2018 20:59:34 +0100 | |
changeset 68052 | e98988801fa9 |
parent 67306 | 897344e33c26 |
child 69804 | 9efccbad7d42 |
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 |
||
67306 | 27 |
fun span "" = ("<span>", "</span>") |
28 |
| span class = ("<span class=" ^ quote (XML.text class) ^ ">", "</span>"); |
|
29 |
||
66044 | 30 |
val enclose_span = uncurry enclose o span; |
33985 | 31 |
|
66044 | 32 |
val hidden = enclose_span Markup.hiddenN; |
33985 | 33 |
|
34 |
||
6324 | 35 |
(* symbol output *) |
36 |
||
61381 | 37 |
abstype symbols = Symbols of string Symtab.table |
38 |
with |
|
39 |
||
40 |
fun make_symbols codes = |
|
41 |
let |
|
42 |
val mapping = |
|
63806 | 43 |
map (apsnd (fn c => "&#" ^ Value.print_int c ^ ";")) codes @ |
61381 | 44 |
[("'", "'"), |
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
45 |
("\<^bsub>", hidden "⇘" ^ "<sub>"), |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
46 |
("\<^esub>", hidden "⇙" ^ "</sub>"), |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
47 |
("\<^bsup>", hidden "⇗" ^ "<sup>"), |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
48 |
("\<^esup>", hidden "⇖" ^ "</sup>")]; |
61381 | 49 |
in Symbols (fold Symtab.update mapping Symtab.empty) end; |
50 |
||
51 |
val no_symbols = make_symbols []; |
|
52 |
||
53 |
fun output_sym (Symbols tab) s = |
|
63934 | 54 |
(case Symtab.lookup tab s of |
55 |
SOME x => x |
|
56 |
| NONE => XML.text s); |
|
61381 | 57 |
|
58 |
end; |
|
59 |
||
6338 | 60 |
local |
61376
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
61 |
|
61381 | 62 |
fun output_markup (bg, en) symbols s1 s2 = |
63 |
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
|
64 |
|
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
65 |
val output_sub = output_markup ("<sub>", "</sub>"); |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
66 |
val output_sup = output_markup ("<sup>", "</sup>"); |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
67 |
val output_bold = output_markup (span "bold"); |
17178 | 68 |
|
61381 | 69 |
fun output_syms _ [] result = implode (rev result) |
70 |
| output_syms symbols (s1 :: rest) result = |
|
61376
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
71 |
let |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
61374
diff
changeset
|
72 |
val (s2, ss) = (case rest of [] => ("", []) | s2 :: ss => (s2, ss)); |
61381 | 73 |
val (s, r) = |
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
74 |
if s1 = "\<^sub>" then (output_sub symbols "⇩" s2, ss) |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
75 |
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
|
76 |
else if s1 = "\<^bold>" then (output_bold symbols "❙" s2, ss) |
61381 | 77 |
else (output_sym symbols s1, rest); |
78 |
in output_syms symbols r (s :: result) end; |
|
14534 | 79 |
|
6338 | 80 |
in |
6324 | 81 |
|
61381 | 82 |
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
|
83 |
|
6338 | 84 |
end; |
85 |
||
6324 | 86 |
|
61379
c57820ceead3
more direct HTML presentation, without print mode;
wenzelm
parents:
61376
diff
changeset
|
87 |
(* presentation *) |
c57820ceead3
more direct HTML presentation, without print mode;
wenzelm
parents:
61376
diff
changeset
|
88 |
|
61381 | 89 |
fun present_span symbols keywords = |
90 |
let |
|
66044 | 91 |
fun present_markup (name, props) = |
92 |
(case Properties.get props Markup.kindN of |
|
93 |
SOME kind => |
|
94 |
if kind = Markup.commandN orelse kind = Markup.keywordN then enclose_span kind else I |
|
95 |
| NONE => I) #> enclose_span name; |
|
61381 | 96 |
fun present_token tok = |
66044 | 97 |
fold_rev present_markup (Token.markups keywords tok) |
98 |
(output symbols (Token.unparse tok)); |
|
61381 | 99 |
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
|
100 |
|
c57820ceead3
more direct HTML presentation, without print mode;
wenzelm
parents:
61376
diff
changeset
|
101 |
|
6324 | 102 |
|
103 |
(** HTML markup **) |
|
104 |
||
105 |
type text = string; |
|
106 |
||
107 |
||
108 |
(* atoms *) |
|
109 |
||
61381 | 110 |
val name = enclose "<span class=\"name\">" "</span>" oo output; |
111 |
val keyword = enclose "<span class=\"keyword\">" "</span>" oo output; |
|
112 |
val command = enclose "<span class=\"command\">" "</span>" oo output; |
|
6324 | 113 |
|
114 |
||
115 |
(* misc *) |
|
116 |
||
28840 | 117 |
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
|
118 |
fun href_path path txt = href_name (Url.implode path) txt; |
6376 | 119 |
|
15531 | 120 |
fun href_opt_path NONE txt = txt |
121 |
| href_opt_path (SOME p) txt = href_path p txt; |
|
6376 | 122 |
|
12413 | 123 |
fun para txt = "\n<p>" ^ txt ^ "</p>\n"; |
6324 | 124 |
|
125 |
||
126 |
(* document *) |
|
127 |
||
61381 | 128 |
fun begin_document symbols title = |
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
129 |
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
130 |
"<!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
|
131 |
"\"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
|
132 |
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
133 |
"<head>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
134 |
"<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
|
135 |
"<title>" ^ output symbols (title ^ " (" ^ Distribution.version ^ ")") ^ "</title>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
136 |
"<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
|
137 |
"</head>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
138 |
"\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
139 |
"<body>\n" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
140 |
"<div class=\"head\">" ^ |
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
61381
diff
changeset
|
141 |
"<h1>" ^ output symbols title ^ "</h1>\n"; |
6324 | 142 |
|
14541 | 143 |
val end_document = "\n</div>\n</body>\n</html>\n"; |
6324 | 144 |
|
6338 | 145 |
|
146 |
(* session index *) |
|
147 |
||
61381 | 148 |
fun begin_session_index symbols session graph docs = |
149 |
begin_document symbols ("Session " ^ output symbols session) ^ |
|
6754 | 150 |
para ("View " ^ href_path graph "theory dependencies" ^ |
27829 | 151 |
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
|
152 |
"\n</div>\n<div class=\"theories\">\n<h2>Theories</h2>\n<ul>\n"; |
6338 | 153 |
|
61381 | 154 |
fun theory_entry symbols (p, s) = "<li>" ^ href_path p (output symbols s) ^ "</li>\n"; |
6324 | 155 |
|
156 |
||
157 |
(* theory *) |
|
158 |
||
61381 | 159 |
fun theory symbols A Bs txt = |
160 |
begin_document symbols ("Theory " ^ A) ^ "\n" ^ |
|
161 |
command symbols "theory" ^ " " ^ name symbols A ^ "<br/>\n" ^ |
|
162 |
keyword symbols "imports" ^ " " ^ |
|
163 |
space_implode " " (map (uncurry href_opt_path o apsnd (name symbols)) Bs) ^ |
|
54456 | 164 |
"<br/>\n" ^ |
61374 | 165 |
enclose "\n</div>\n<div class=\"source\">\n<pre class=\"source\">" "</pre>\n" txt ^ |
54456 | 166 |
end_document; |
16267
0773b17922d8
present new-style theory header, with 'imports' and 'uses';
wenzelm
parents:
16196
diff
changeset
|
167 |
|
6324 | 168 |
end; |