author | wenzelm |
Sat, 30 Jan 2021 17:15:14 +0100 | |
changeset 73203 | 9c10b4fa17b5 |
parent 73202 | 8a17c7bf530a |
child 73204 | aa3d4cf7825a |
permissions | -rw-r--r-- |
33984 | 1 |
/* Title: Pure/Thy/html.scala |
2 |
Author: Makarius |
|
3 |
||
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
50201
diff
changeset
|
4 |
HTML presentation elements. |
33984 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
55618 | 9 |
|
33984 | 10 |
object HTML |
11 |
{ |
|
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
12 |
/* output text with control symbols */ |
59063 | 13 |
|
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
14 |
private val control = |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
15 |
Map( |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
16 |
Symbol.sub -> "sub", Symbol.sub_decoded -> "sub", |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
17 |
Symbol.sup -> "sup", Symbol.sup_decoded -> "sup", |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
18 |
Symbol.bold -> "b", Symbol.bold_decoded -> "b") |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
19 |
|
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
20 |
private val control_block = |
62104
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
60215
diff
changeset
|
21 |
Map( |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
22 |
Symbol.bsub -> "<sub>", Symbol.bsub_decoded -> "<sub>", |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
23 |
Symbol.esub -> "</sub>", Symbol.esub_decoded -> "</sub>", |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
24 |
Symbol.bsup -> "<sup>", Symbol.bsup_decoded -> "<sup>", |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
25 |
Symbol.esup -> "</sup>", Symbol.esup_decoded -> "</sup>") |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
26 |
|
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
27 |
def is_control(sym: Symbol.Symbol): Boolean = control.isDefinedAt(sym) |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
28 |
|
73202 | 29 |
def output(s: StringBuilder, text: String, hidden: Boolean, permissive: Boolean) |
66018
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
30 |
{ |
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
31 |
def output_char(c: Char): Unit = |
73203 | 32 |
XML.output_char(s, c, permissive = permissive) |
66018
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
33 |
|
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
34 |
def output_string(str: String): Unit = |
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
35 |
str.iterator.foreach(output_char) |
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
36 |
|
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
37 |
def output_hidden(body: => Unit): Unit = |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
38 |
if (hidden) { s ++= "<span class=\"hidden\">"; body; s ++= "</span>" } |
37200
0f3edc64356a
added HTML.encode (in Scala), similar to HTML.output in ML;
wenzelm
parents:
36016
diff
changeset
|
39 |
|
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
40 |
def output_symbol(sym: Symbol.Symbol): Unit = |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
41 |
if (sym != "") { |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
42 |
control_block.get(sym) match { |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
43 |
case Some(html) if html.startsWith("</") => |
66018
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
44 |
s ++= html; output_hidden(output_string(sym)) |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
45 |
case Some(html) => |
66018
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
46 |
output_hidden(output_string(sym)); s ++= html |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
47 |
case None => |
67255
f1f983484878
HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents:
66212
diff
changeset
|
48 |
if (hidden && Symbol.is_control_encoded(sym)) { |
f1f983484878
HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents:
66212
diff
changeset
|
49 |
output_hidden(output_string(Symbol.control_prefix)) |
f1f983484878
HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents:
66212
diff
changeset
|
50 |
s ++= "<span class=\"control\">" |
f1f983484878
HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents:
66212
diff
changeset
|
51 |
output_string(Symbol.control_name(sym).get) |
f1f983484878
HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents:
66212
diff
changeset
|
52 |
s ++= "</span>" |
f1f983484878
HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents:
66212
diff
changeset
|
53 |
output_hidden(output_string(Symbol.control_suffix)) |
f1f983484878
HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents:
66212
diff
changeset
|
54 |
} |
f1f983484878
HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents:
66212
diff
changeset
|
55 |
else output_string(sym) |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
56 |
} |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
57 |
} |
59063 | 58 |
|
62104
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
60215
diff
changeset
|
59 |
var ctrl = "" |
59063 | 60 |
for (sym <- Symbol.iterator(text)) { |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
61 |
if (is_control(sym)) { output_symbol(ctrl); ctrl = sym } |
59063 | 62 |
else { |
62104
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
60215
diff
changeset
|
63 |
control.get(ctrl) match { |
66006
cec184536dfd
uniform notion of Symbol.is_controllable (see also 265d9300d523);
wenzelm
parents:
66001
diff
changeset
|
64 |
case Some(elem) if Symbol.is_controllable(sym) => |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
65 |
output_hidden(output_symbol(ctrl)) |
65991 | 66 |
s += '<'; s ++= elem; s += '>' |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
67 |
output_symbol(sym) |
65991 | 68 |
s ++= "</"; s ++= elem; s += '>' |
59063 | 69 |
case _ => |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
70 |
output_symbol(ctrl) |
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
71 |
output_symbol(sym) |
59063 | 72 |
} |
62104
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
60215
diff
changeset
|
73 |
ctrl = "" |
59063 | 74 |
} |
37200
0f3edc64356a
added HTML.encode (in Scala), similar to HTML.output in ML;
wenzelm
parents:
36016
diff
changeset
|
75 |
} |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
76 |
output_symbol(ctrl) |
64355 | 77 |
} |
59063 | 78 |
|
66018
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
79 |
def output(text: String): String = |
73202 | 80 |
Library.make_string(output(_, text, hidden = false, permissive = true)) |
64355 | 81 |
|
82 |
||
83 |
/* output XML as HTML */ |
|
84 |
||
65834
67a6e0f166c2
extra space only for some structual elements, but not <a>, <b>, <em> etc. (amending 8a0fe5469ba0);
wenzelm
parents:
65773
diff
changeset
|
85 |
private val structural_elements = |
67a6e0f166c2
extra space only for some structual elements, but not <a>, <b>, <em> etc. (amending 8a0fe5469ba0);
wenzelm
parents:
65773
diff
changeset
|
86 |
Set("head", "body", "meta", "div", "pre", "p", "title", "h1", "h2", "h3", "h4", "h5", "h6", |
67a6e0f166c2
extra space only for some structual elements, but not <a>, <b>, <em> etc. (amending 8a0fe5469ba0);
wenzelm
parents:
65773
diff
changeset
|
87 |
"ul", "ol", "dl", "li", "dt", "dd") |
67a6e0f166c2
extra space only for some structual elements, but not <a>, <b>, <em> etc. (amending 8a0fe5469ba0);
wenzelm
parents:
65773
diff
changeset
|
88 |
|
73202 | 89 |
def output(s: StringBuilder, body: XML.Body, hidden: Boolean, structural: Boolean) |
64355 | 90 |
{ |
65991 | 91 |
def elem(markup: Markup) |
92 |
{ |
|
93 |
s ++= markup.name |
|
94 |
for ((a, b) <- markup.properties) { |
|
66018
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
95 |
s += ' ' |
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
96 |
s ++= a |
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
97 |
s += '=' |
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
98 |
s += '"' |
73202 | 99 |
output(s, b, hidden = hidden, permissive = false) |
66018
9ce3720976dc
permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents:
66006
diff
changeset
|
100 |
s += '"' |
65991 | 101 |
} |
102 |
} |
|
64355 | 103 |
def tree(t: XML.Tree): Unit = |
104 |
t match { |
|
105 |
case XML.Elem(markup, Nil) => |
|
65991 | 106 |
s += '<'; elem(markup); s ++= "/>" |
64355 | 107 |
case XML.Elem(markup, ts) => |
67337
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
108 |
if (structural && structural_elements(markup.name)) s += '\n' |
65991 | 109 |
s += '<'; elem(markup); s += '>' |
64355 | 110 |
ts.foreach(tree) |
65991 | 111 |
s ++= "</"; s ++= markup.name; s += '>' |
67337
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
112 |
if (structural && structural_elements(markup.name)) s += '\n' |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
113 |
case XML.Text(txt) => |
73202 | 114 |
output(s, txt, hidden = hidden, permissive = true) |
64355 | 115 |
} |
116 |
body.foreach(tree) |
|
37200
0f3edc64356a
added HTML.encode (in Scala), similar to HTML.output in ML;
wenzelm
parents:
36016
diff
changeset
|
117 |
} |
0f3edc64356a
added HTML.encode (in Scala), similar to HTML.output in ML;
wenzelm
parents:
36016
diff
changeset
|
118 |
|
67337
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
119 |
def output(body: XML.Body, hidden: Boolean, structural: Boolean): String = |
73202 | 120 |
Library.make_string(output(_, body, hidden, structural)) |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
121 |
|
67337
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
122 |
def output(tree: XML.Tree, hidden: Boolean, structural: Boolean): String = |
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
123 |
output(List(tree), hidden, structural) |
64355 | 124 |
|
125 |
||
65753 | 126 |
/* attributes */ |
127 |
||
65992 | 128 |
class Attribute(val name: String, value: String) |
129 |
{ |
|
130 |
def xml: XML.Attribute = name -> value |
|
131 |
def apply(elem: XML.Elem): XML.Elem = elem + xml |
|
132 |
} |
|
65942 | 133 |
|
65992 | 134 |
def id(s: String): Attribute = new Attribute("id", s) |
65993 | 135 |
def class_(name: String): Attribute = new Attribute("class", name) |
65946 | 136 |
|
65992 | 137 |
def width(w: Int): Attribute = new Attribute("width", w.toString) |
138 |
def height(h: Int): Attribute = new Attribute("height", h.toString) |
|
65946 | 139 |
def size(w: Int, h: Int)(elem: XML.Elem): XML.Elem = width(w)(height(h)(elem)) |
65753 | 140 |
|
141 |
||
64359 | 142 |
/* structured markup operators */ |
143 |
||
144 |
def text(txt: String): XML.Body = if (txt.isEmpty) Nil else List(XML.Text(txt)) |
|
65753 | 145 |
val break: XML.Body = List(XML.elem("br")) |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72376
diff
changeset
|
146 |
val nl: XML.Body = List(XML.Text("\n")) |
64359 | 147 |
|
65992 | 148 |
class Operator(val name: String) |
149 |
{ |
|
150 |
def apply(body: XML.Body): XML.Elem = XML.elem(name, body) |
|
151 |
def apply(att: Attribute, body: XML.Body): XML.Elem = att(apply(body)) |
|
65993 | 152 |
def apply(c: String, body: XML.Body): XML.Elem = apply(class_(c), body) |
65992 | 153 |
} |
64356 | 154 |
|
64359 | 155 |
class Heading(name: String) extends Operator(name) |
65992 | 156 |
{ |
157 |
def apply(txt: String): XML.Elem = super.apply(text(txt)) |
|
158 |
def apply(att: Attribute, txt: String): XML.Elem = super.apply(att, text(txt)) |
|
159 |
def apply(c: String, txt: String): XML.Elem = super.apply(c, text(txt)) |
|
160 |
} |
|
64359 | 161 |
|
162 |
val div = new Operator("div") |
|
163 |
val span = new Operator("span") |
|
65753 | 164 |
val pre = new Operator("pre") |
64359 | 165 |
val par = new Operator("p") |
166 |
val emph = new Operator("em") |
|
167 |
val bold = new Operator("b") |
|
65771 | 168 |
val code = new Operator("code") |
67336 | 169 |
val item = new Operator("li") |
170 |
val list = new Operator("ul") |
|
171 |
val enum = new Operator("ol") |
|
172 |
val descr = new Operator("dl") |
|
173 |
val dt = new Operator("dt") |
|
174 |
val dd = new Operator("dd") |
|
64355 | 175 |
|
64359 | 176 |
val title = new Heading("title") |
177 |
val chapter = new Heading("h1") |
|
178 |
val section = new Heading("h2") |
|
179 |
val subsection = new Heading("h3") |
|
180 |
val subsubsection = new Heading("h4") |
|
181 |
val paragraph = new Heading("h5") |
|
182 |
val subparagraph = new Heading("h6") |
|
183 |
||
67336 | 184 |
def itemize(items: List[XML.Body]): XML.Elem = list(items.map(item(_))) |
185 |
def enumerate(items: List[XML.Body]): XML.Elem = enum(items.map(item(_))) |
|
64359 | 186 |
def description(items: List[(XML.Body, XML.Body)]): XML.Elem = |
67336 | 187 |
descr(items.flatMap({ case (x, y) => List(dt(x), dd(y)) })) |
64359 | 188 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72376
diff
changeset
|
189 |
def link(href: String, body: XML.Body): XML.Elem = |
64359 | 190 |
XML.Elem(Markup("a", List("href" -> href)), if (body.isEmpty) text(href) else body) |
64355 | 191 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72376
diff
changeset
|
192 |
def link(path: Path, body: XML.Body): XML.Elem = link(path.implode, body) |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72376
diff
changeset
|
193 |
|
65753 | 194 |
def image(src: String, alt: String = ""): XML.Elem = |
195 |
XML.Elem(Markup("img", List("src" -> src) ::: proper_string(alt).map("alt" -> _).toList), Nil) |
|
196 |
||
66040 | 197 |
def source(body: XML.Body): XML.Elem = pre("source", body) |
198 |
def source(src: String): XML.Elem = source(text(src)) |
|
65988 | 199 |
|
65941 | 200 |
def style(s: String): XML.Elem = XML.elem("style", text(s)) |
66000 | 201 |
def style_file(href: String): XML.Elem = |
202 |
XML.Elem(Markup("link", List("rel" -> "stylesheet", "type" -> "text/css", "href" -> href)), Nil) |
|
66212 | 203 |
def style_file(path: Path): XML.Elem = style_file(Url.print_file(path.file)) |
66000 | 204 |
|
66210 | 205 |
def script(s: String): XML.Elem = XML.elem("script", text(s)) |
206 |
def script_file(href: String): XML.Elem = XML.Elem(Markup("script", List("src" -> href)), Nil) |
|
66212 | 207 |
def script_file(path: Path): XML.Elem = script_file(Url.print_file(path.file)) |
208 |
||
37200
0f3edc64356a
added HTML.encode (in Scala), similar to HTML.output in ML;
wenzelm
parents:
36016
diff
changeset
|
209 |
|
65892 | 210 |
/* messages */ |
211 |
||
65939 | 212 |
// background |
65993 | 213 |
val writeln_message: Attribute = class_("writeln_message") |
214 |
val warning_message: Attribute = class_("warning_message") |
|
215 |
val error_message: Attribute = class_("error_message") |
|
65892 | 216 |
|
65939 | 217 |
// underline |
65993 | 218 |
val writeln: Attribute = class_("writeln") |
219 |
val warning: Attribute = class_("warning") |
|
220 |
val error: Attribute = class_("error") |
|
65892 | 221 |
|
65944 | 222 |
|
223 |
/* tooltips */ |
|
224 |
||
225 |
def tooltip(item: XML.Body, tip: XML.Body): XML.Elem = |
|
65992 | 226 |
span(item ::: List(div("tooltip", tip))) |
65944 | 227 |
|
228 |
def tooltip_errors(item: XML.Body, msgs: List[XML.Body]): XML.Elem = |
|
229 |
HTML.error(tooltip(item, msgs.map(msg => error_message(pre(msg))))) |
|
65892 | 230 |
|
231 |
||
66196 | 232 |
/* GUI elements */ |
233 |
||
234 |
object GUI |
|
235 |
{ |
|
236 |
private def optional_value(text: String): XML.Attributes = |
|
237 |
proper_string(text).map(a => "value" -> a).toList |
|
238 |
||
239 |
private def optional_name(name: String): XML.Attributes = |
|
240 |
proper_string(name).map(a => "name" -> a).toList |
|
241 |
||
242 |
private def optional_title(tooltip: String): XML.Attributes = |
|
243 |
proper_string(tooltip).map(a => "title" -> a).toList |
|
244 |
||
245 |
private def optional_submit(submit: Boolean): XML.Attributes = |
|
246 |
if (submit) List("onChange" -> "this.form.submit()") else Nil |
|
247 |
||
248 |
private def optional_checked(selected: Boolean): XML.Attributes = |
|
249 |
if (selected) List("checked" -> "") else Nil |
|
250 |
||
251 |
private def optional_action(action: String): XML.Attributes = |
|
252 |
proper_string(action).map(a => "action" -> a).toList |
|
253 |
||
66210 | 254 |
private def optional_onclick(script: String): XML.Attributes = |
255 |
proper_string(script).map(a => "onclick" -> a).toList |
|
256 |
||
257 |
private def optional_onchange(script: String): XML.Attributes = |
|
258 |
proper_string(script).map(a => "onchange" -> a).toList |
|
259 |
||
260 |
def button(body: XML.Body, name: String = "", tooltip: String = "", submit: Boolean = false, |
|
261 |
script: String = ""): XML.Elem = |
|
66196 | 262 |
XML.Elem( |
263 |
Markup("button", |
|
264 |
List("type" -> (if (submit) "submit" else "button"), "value" -> "true") ::: |
|
66210 | 265 |
optional_name(name) ::: optional_title(tooltip) ::: optional_onclick(script)), body) |
66196 | 266 |
|
267 |
def checkbox(body: XML.Body, name: String = "", tooltip: String = "", submit: Boolean = false, |
|
66210 | 268 |
selected: Boolean = false, script: String = ""): XML.Elem = |
66196 | 269 |
XML.elem("label", |
270 |
XML.elem( |
|
271 |
Markup("input", |
|
272 |
List("type" -> "checkbox", "value" -> "true") ::: optional_name(name) ::: |
|
273 |
optional_title(tooltip) ::: optional_submit(submit) ::: |
|
66210 | 274 |
optional_checked(selected) ::: optional_onchange(script))) :: body) |
66196 | 275 |
|
276 |
def text_field(columns: Int = 0, text: String = "", name: String = "", tooltip: String = "", |
|
66210 | 277 |
submit: Boolean = false, script: String = ""): XML.Elem = |
66196 | 278 |
XML.elem(Markup("input", |
279 |
List("type" -> "text") ::: |
|
280 |
(if (columns > 0) List("size" -> columns.toString) else Nil) ::: |
|
66210 | 281 |
optional_value(text) ::: optional_name(name) ::: optional_title(tooltip) ::: |
282 |
optional_submit(submit) ::: optional_onchange(script))) |
|
66196 | 283 |
|
284 |
def parameter(text: String = "", name: String = ""): XML.Elem = |
|
285 |
XML.elem( |
|
286 |
Markup("input", List("type" -> "hidden") ::: optional_value(text) ::: optional_name(name))) |
|
287 |
||
66209 | 288 |
def form(body: XML.Body, name: String = "", action: String = "", http_post: Boolean = false) |
289 |
: XML.Elem = |
|
290 |
XML.Elem( |
|
291 |
Markup("form", optional_name(name) ::: optional_action(action) ::: |
|
292 |
(if (http_post) List("method" -> "post") else Nil)), body) |
|
66196 | 293 |
} |
294 |
||
295 |
||
66200 | 296 |
/* GUI layout */ |
297 |
||
298 |
object Wrap_Panel |
|
299 |
{ |
|
300 |
object Alignment extends Enumeration |
|
301 |
{ |
|
302 |
val left, right, center = Value |
|
303 |
} |
|
304 |
||
305 |
def apply(contents: List[XML.Elem], name: String = "", action: String = "", |
|
66206 | 306 |
alignment: Alignment.Value = Alignment.right): XML.Elem = |
66200 | 307 |
{ |
308 |
val body = Library.separate(XML.Text(" "), contents) |
|
309 |
GUI.form(List(div(body) + ("style" -> ("text-align: " + alignment))), |
|
310 |
name = name, action = action) |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
||
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
315 |
/* document */ |
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
316 |
|
64359 | 317 |
val header: String = |
69804 | 318 |
XML.header + |
319 |
"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
64359 | 320 |
<html xmlns="http://www.w3.org/1999/xhtml">""" |
321 |
||
73129 | 322 |
val footer: String = """</html>""" |
323 |
||
64359 | 324 |
val head_meta: XML.Elem = |
325 |
XML.Elem(Markup("meta", |
|
326 |
List("http-equiv" -> "Content-Type", "content" -> "text/html; charset=utf-8")), Nil) |
|
327 |
||
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
328 |
def output_document(head: XML.Body, body: XML.Body, |
67337
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
329 |
css: String = "isabelle.css", |
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
330 |
hidden: Boolean = true, |
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
331 |
structural: Boolean = true): String = |
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
332 |
{ |
64359 | 333 |
cat_lines( |
73129 | 334 |
List( |
335 |
header, |
|
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
336 |
output( |
66000 | 337 |
XML.elem("head", head_meta :: (if (css == "") Nil else List(style_file(css))) ::: head), |
67337
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
338 |
hidden = hidden, structural = structural), |
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
339 |
output(XML.elem("body", body), |
73129 | 340 |
hidden = hidden, structural = structural), |
341 |
footer)) |
|
65997
e3dc9ea67a62
output control symbols like ML version, with optionally hidden source;
wenzelm
parents:
65993
diff
changeset
|
342 |
} |
64359 | 343 |
|
65838 | 344 |
|
66000 | 345 |
/* fonts */ |
346 |
||
347 |
def fonts_url(): String => String = |
|
69374 | 348 |
(for (entry <- Isabelle_Fonts.fonts(hidden = true)) |
70743
342b0a1fc86d
proper file name instead of font name (amending dc9a39c3f75d);
wenzelm
parents:
69804
diff
changeset
|
349 |
yield (entry.path.file_name -> Url.print_file(entry.path.file))).toMap |
66000 | 350 |
|
351 |
def fonts_dir(prefix: String)(ttf_name: String): String = |
|
352 |
prefix + "/" + ttf_name |
|
353 |
||
354 |
def fonts_css(make_url: String => String = fonts_url()): String = |
|
355 |
{ |
|
69360 | 356 |
def font_face(entry: Isabelle_Fonts.Entry): String = |
66000 | 357 |
cat_lines( |
358 |
List( |
|
359 |
"@font-face {", |
|
69360 | 360 |
" font-family: '" + entry.family + "';", |
69366 | 361 |
" src: url('" + make_url(entry.path.file_name) + "') format('truetype');") ::: |
69360 | 362 |
(if (entry.is_bold) List(" font-weight: bold;") else Nil) ::: |
363 |
(if (entry.is_italic) List(" font-style: italic;") else Nil) ::: |
|
66000 | 364 |
List("}")) |
365 |
||
71601 | 366 |
("/* Isabelle fonts */" :: Isabelle_Fonts.fonts(hidden = true).map(font_face)) |
69362 | 367 |
.mkString("", "\n\n", "\n") |
66000 | 368 |
} |
369 |
||
370 |
||
65838 | 371 |
/* document directory */ |
372 |
||
65998 | 373 |
def isabelle_css: Path = Path.explode("~~/etc/isabelle.css") |
374 |
||
66000 | 375 |
def write_isabelle_css(dir: Path, make_url: String => String = fonts_dir("fonts")) |
376 |
{ |
|
377 |
File.write(dir + isabelle_css.base, |
|
69362 | 378 |
fonts_css(make_url) + "\n\n" + File.read(isabelle_css)) |
66000 | 379 |
} |
380 |
||
72376 | 381 |
def init_dir(dir: Path): Unit = |
382 |
write_isabelle_css(Isabelle_System.make_directory(dir)) |
|
65836 | 383 |
|
65838 | 384 |
def write_document(dir: Path, name: String, head: XML.Body, body: XML.Body, |
69366 | 385 |
css: String = isabelle_css.file_name, |
67337
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
386 |
hidden: Boolean = true, |
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
387 |
structural: Boolean = true) |
65838 | 388 |
{ |
389 |
init_dir(dir) |
|
67337
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
390 |
File.write(dir + Path.basic(name), |
4254cfd15b00
more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents:
67336
diff
changeset
|
391 |
output_document(head, body, css = css, hidden = hidden, structural = structural)) |
65838 | 392 |
} |
33984 | 393 |
} |