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