author | wenzelm |
Fri, 05 Nov 2021 20:42:06 +0100 | |
changeset 74708 | b2df121ccfc1 |
parent 74707 | a44d14207050 |
child 74709 | d73a7e3c618c |
permissions | -rw-r--r-- |
73718 | 1 |
/* Title: Pure/Thy/presentation.scala |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
3 |
|
73718 | 4 |
HTML presentation of PIDE document content. |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
6 |
|
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
8 |
|
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
9 |
|
74677 | 10 |
import scala.annotation.tailrec |
51402 | 11 |
import scala.collection.immutable.SortedMap |
74677 | 12 |
import scala.collection.mutable |
51402 | 13 |
|
14 |
||
72652 | 15 |
object Presentation |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
16 |
{ |
72957 | 17 |
/** HTML documents **/ |
18 |
||
73718 | 19 |
/* HTML context */ |
20 |
||
72962 | 21 |
val fonts_path = Path.explode("fonts") |
22 |
||
72957 | 23 |
sealed case class HTML_Document(title: String, content: String) |
24 |
||
72959 | 25 |
def html_context(fonts_url: String => String = HTML.fonts_url()): HTML_Context = |
26 |
new HTML_Context(fonts_url) |
|
27 |
||
28 |
final class HTML_Context private[Presentation](fonts_url: String => String) |
|
29 |
{ |
|
74706 | 30 |
val term_cache: Term.Cache = Term.Cache.make() |
31 |
||
74697 | 32 |
private val theory_cache = Synchronized(Map.empty[String, Export_Theory.Theory]) |
33 |
||
34 |
def cache_theory(thy_name: String, make_thy: => Export_Theory.Theory): Export_Theory.Theory = |
|
35 |
{ |
|
36 |
theory_cache.change_result(thys => |
|
37 |
{ |
|
38 |
thys.get(thy_name) match { |
|
39 |
case Some(thy) => (thy, thys) |
|
40 |
case None => |
|
41 |
val thy = make_thy |
|
42 |
(thy, thys + (thy_name -> thy)) |
|
43 |
} |
|
44 |
}) |
|
45 |
} |
|
46 |
||
73340 | 47 |
def init_fonts(dir: Path): Unit = |
72962 | 48 |
{ |
49 |
val fonts_dir = Isabelle_System.make_directory(dir + fonts_path) |
|
50 |
for (entry <- Isabelle_Fonts.fonts(hidden = true)) |
|
73317 | 51 |
Isabelle_System.copy_file(entry.path, fonts_dir) |
72962 | 52 |
} |
53 |
||
54 |
def head(title: String, rest: XML.Body = Nil): XML.Tree = |
|
55 |
HTML.div("head", HTML.chapter(title) :: rest) |
|
56 |
||
57 |
def source(body: XML.Body): XML.Tree = HTML.pre("source", body) |
|
58 |
||
74677 | 59 |
def offset_ref(offset: Text.Range): String = |
60 |
"offset/" + offset.start + ".." + offset.stop |
|
61 |
||
72962 | 62 |
def contents(heading: String, items: List[XML.Body], css_class: String = "contents") |
63 |
: List[XML.Elem] = |
|
64 |
{ |
|
65 |
if (items.isEmpty) Nil |
|
66 |
else List(HTML.div(css_class, List(HTML.section(heading), HTML.itemize(items)))) |
|
67 |
} |
|
68 |
||
72959 | 69 |
def output_document(title: String, body: XML.Body): String = |
70 |
HTML.output_document( |
|
71 |
List( |
|
72 |
HTML.style(HTML.fonts_css(fonts_url) + "\n\n" + File.read(HTML.isabelle_css)), |
|
73 |
HTML.title(title)), |
|
74 |
List(HTML.source(body)), css = "", structural = false) |
|
75 |
||
76 |
def html_document(title: String, body: XML.Body): HTML_Document = |
|
77 |
HTML_Document(title, output_document(title, body)) |
|
78 |
} |
|
79 |
||
72957 | 80 |
|
73055 | 81 |
/* presentation elements */ |
82 |
||
83 |
sealed case class Elements( |
|
84 |
html: Markup.Elements = Markup.Elements.empty, |
|
73056 | 85 |
entity: Markup.Elements = Markup.Elements.empty, |
73055 | 86 |
language: Markup.Elements = Markup.Elements.empty) |
72957 | 87 |
|
73055 | 88 |
val elements1: Elements = |
89 |
Elements( |
|
74677 | 90 |
html = Rendering.foreground_elements ++ Rendering.text_color_elements + |
73056 | 91 |
Markup.NUMERAL + Markup.COMMENT + Markup.ENTITY + Markup.LANGUAGE, |
74677 | 92 |
entity = Markup.Elements(Markup.THEORY, Markup.TYPE_NAME, Markup.CONSTANT, Markup.FACT, |
93 |
Markup.CLASS, Markup.LOCALE, Markup.FREE)) |
|
73036 | 94 |
|
73055 | 95 |
val elements2: Elements = |
96 |
Elements( |
|
97 |
html = elements1.html ++ Rendering.markdown_elements, |
|
73056 | 98 |
language = Markup.Elements(Markup.Language.DOCUMENT)) |
73055 | 99 |
|
74678 | 100 |
|
101 |
/* formal entities */ |
|
74677 | 102 |
|
103 |
type Entity = Export_Theory.Entity[Export_Theory.No_Content] |
|
104 |
||
105 |
case class Entity_Context(node: Document.Node.Name) |
|
106 |
{ |
|
107 |
val seen_ranges: mutable.Set[Symbol.Range] = mutable.Set.empty |
|
108 |
} |
|
73055 | 109 |
|
74678 | 110 |
|
73718 | 111 |
/* HTML output */ |
73036 | 112 |
|
72957 | 113 |
private val div_elements = |
114 |
Set(HTML.div.name, HTML.pre.name, HTML.par.name, HTML.list.name, HTML.enum.name, |
|
115 |
HTML.descr.name) |
|
116 |
||
73056 | 117 |
def make_html( |
74677 | 118 |
name: Document.Node.Name, |
73056 | 119 |
elements: Elements, |
74677 | 120 |
entity_anchor: (Entity_Context, Symbol.Range, XML.Body) => Option[XML.Tree], |
121 |
entity_link: (Entity_Context, Properties.T, XML.Body) => Option[XML.Tree], |
|
73056 | 122 |
xml: XML.Body): XML.Body = |
73054 | 123 |
{ |
74677 | 124 |
val context = Entity_Context(name) |
125 |
||
73054 | 126 |
def html_div(html: XML.Body): Boolean = |
127 |
html exists { |
|
128 |
case XML.Elem(markup, body) => div_elements.contains(markup.name) || html_div(body) |
|
129 |
case XML.Text(_) => false |
|
130 |
} |
|
72957 | 131 |
|
73055 | 132 |
def html_class(c: String, html: XML.Body): XML.Body = |
133 |
if (c == "") html |
|
134 |
else if (html_div(html)) List(HTML.div(c, html)) |
|
135 |
else List(HTML.span(c, html)) |
|
72957 | 136 |
|
74677 | 137 |
def html_body(xml_body: XML.Body, end_offset: Symbol.Offset): (XML.Body, Symbol.Offset) = |
138 |
xml_body.foldRight((List.empty[XML.Tree], end_offset)) { case (tree, (res, end_offset1)) => |
|
139 |
val (res1, offset) = html_body_single(tree, end_offset1) |
|
140 |
(res1 ++ res, offset) |
|
141 |
} |
|
142 |
||
143 |
@tailrec |
|
144 |
def html_body_single(xml_tree: XML.Tree, end_offset: Symbol.Offset): (XML.Body, Symbol.Offset) = |
|
145 |
xml_tree match { |
|
146 |
case XML.Wrapped_Elem(markup, _, body) => html_body_single(XML.Elem(markup, body), end_offset) |
|
73056 | 147 |
case XML.Elem(Markup(Markup.ENTITY, props @ Markup.Kind(kind)), body) => |
74677 | 148 |
val (body1, offset) = html_body(body, end_offset) |
73056 | 149 |
if (elements.entity(kind)) { |
74677 | 150 |
entity_link(context, props, body1) match { |
151 |
case Some(link) => (List(link), offset) |
|
152 |
case None => (body1, offset) |
|
73056 | 153 |
} |
154 |
} |
|
74677 | 155 |
else (body1, offset) |
73055 | 156 |
case XML.Elem(Markup(Markup.LANGUAGE, Markup.Name(name)), body) => |
74677 | 157 |
val (body1, offset) = html_body(body, end_offset) |
158 |
(html_class(if (elements.language(name)) name else "", body1), offset) |
|
73055 | 159 |
case XML.Elem(Markup(Markup.MARKDOWN_PARAGRAPH, _), body) => |
74677 | 160 |
val (body1, offset) = html_body(body, end_offset) |
161 |
(List(HTML.par(body1)), offset) |
|
73055 | 162 |
case XML.Elem(Markup(Markup.MARKDOWN_ITEM, _), body) => |
74677 | 163 |
val (body1, offset) = html_body(body, end_offset) |
164 |
(List(HTML.item(body1)), offset) |
|
165 |
case XML.Elem(Markup(Markup.Markdown_Bullet.name, _), text) => |
|
74683
c8327efc7af1
clarified signature: more direct XML.symbol_length;
wenzelm
parents:
74682
diff
changeset
|
166 |
(Nil, end_offset - XML.symbol_length(text)) |
73054 | 167 |
case XML.Elem(Markup.Markdown_List(kind), body) => |
74677 | 168 |
val (body1, offset) = html_body(body, end_offset) |
169 |
if (kind == Markup.ENUMERATE) (List(HTML.enum(body1)), offset) |
|
170 |
else (List(HTML.list(body1)), offset) |
|
73054 | 171 |
case XML.Elem(markup, body) => |
172 |
val name = markup.name |
|
74677 | 173 |
val (body1, offset) = html_body(body, end_offset) |
73054 | 174 |
val html = |
175 |
markup.properties match { |
|
176 |
case Markup.Kind(kind) if kind == Markup.COMMAND || kind == Markup.KEYWORD => |
|
74677 | 177 |
html_class(kind, body1) |
73054 | 178 |
case _ => |
74677 | 179 |
body1 |
73054 | 180 |
} |
181 |
Rendering.foreground.get(name) orElse Rendering.text_color.get(name) match { |
|
74677 | 182 |
case Some(c) => (html_class(c.toString, html), offset) |
183 |
case None => (html_class(name, html), offset) |
|
72957 | 184 |
} |
73054 | 185 |
case XML.Text(text) => |
74682
ce4adcc85f6c
more direct Symbol.length: Symbol.decode is redundant, symbol counts are invariant under it;
wenzelm
parents:
74679
diff
changeset
|
186 |
val offset = end_offset - Symbol.length(text) |
ce4adcc85f6c
more direct Symbol.length: Symbol.decode is redundant, symbol counts are invariant under it;
wenzelm
parents:
74679
diff
changeset
|
187 |
val body = HTML.text(Symbol.decode(text)) |
74677 | 188 |
entity_anchor(context, Text.Range(offset, end_offset), body) match { |
189 |
case Some(body1) => (List(body1), offset) |
|
190 |
case None => (body, offset) |
|
191 |
} |
|
73054 | 192 |
} |
193 |
||
74683
c8327efc7af1
clarified signature: more direct XML.symbol_length;
wenzelm
parents:
74682
diff
changeset
|
194 |
html_body(xml, XML.symbol_length(xml) + 1)._1 |
73054 | 195 |
} |
72957 | 196 |
|
197 |
||
198 |
/* PIDE HTML document */ |
|
199 |
||
200 |
def html_document( |
|
201 |
resources: Resources, |
|
202 |
snapshot: Document.Snapshot, |
|
72962 | 203 |
html_context: HTML_Context, |
73055 | 204 |
elements: Elements, |
72959 | 205 |
plain_text: Boolean = false): HTML_Document = |
72957 | 206 |
{ |
73120
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
wenzelm
parents:
73059
diff
changeset
|
207 |
require(!snapshot.is_outdated, "document snapshot outdated") |
72957 | 208 |
|
209 |
val name = snapshot.node_name |
|
210 |
if (plain_text) { |
|
72962 | 211 |
val title = "File " + Symbol.cartouche_decoded(name.path.file_name) |
72959 | 212 |
val body = HTML.text(snapshot.node.source) |
72962 | 213 |
html_context.html_document(title, body) |
72957 | 214 |
} |
215 |
else { |
|
72962 | 216 |
resources.html_document(snapshot) getOrElse { |
217 |
val title = |
|
218 |
if (name.is_theory) "Theory " + quote(name.theory_base_name) |
|
219 |
else "File " + Symbol.cartouche_decoded(name.path.file_name) |
|
74677 | 220 |
val xml = snapshot.xml_markup(elements = elements.html) |
221 |
val body = make_html(name, elements, (_, _, _) => None, (_, _, _) => None, xml) |
|
72962 | 222 |
html_context.html_document(title, body) |
72957 | 223 |
} |
224 |
} |
|
225 |
} |
|
226 |
||
227 |
||
228 |
||
73718 | 229 |
/** HTML presentation **/ |
72649 | 230 |
|
72648 | 231 |
/* presentation context */ |
232 |
||
233 |
object Context |
|
234 |
{ |
|
235 |
val none: Context = new Context { def enabled: Boolean = false } |
|
236 |
val standard: Context = new Context { def enabled: Boolean = true } |
|
237 |
||
238 |
def dir(path: Path): Context = |
|
239 |
new Context { |
|
240 |
def enabled: Boolean = true |
|
241 |
override def dir(store: Sessions.Store): Path = path |
|
242 |
} |
|
243 |
||
244 |
def make(s: String): Context = |
|
245 |
if (s == ":") standard else dir(Path.explode(s)) |
|
246 |
} |
|
247 |
||
248 |
abstract class Context private |
|
249 |
{ |
|
250 |
def enabled: Boolean |
|
251 |
def enabled(info: Sessions.Info): Boolean = enabled || info.browser_info |
|
252 |
def dir(store: Sessions.Store): Path = store.presentation_dir |
|
253 |
def dir(store: Sessions.Store, info: Sessions.Info): Path = |
|
72670 | 254 |
dir(store) + Path.explode(info.chapter_session) |
72648 | 255 |
} |
256 |
||
257 |
||
72955
942bf91545fa
clarified comments: file-system access is always unsynchronized;
wenzelm
parents:
72882
diff
changeset
|
258 |
/* maintain chapter index */ |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
259 |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
260 |
private val sessions_path = Path.basic(".sessions") |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
261 |
|
51402 | 262 |
private def read_sessions(dir: Path): List[(String, String)] = |
263 |
{ |
|
51416 | 264 |
val path = dir + sessions_path |
265 |
if (path.is_file) { |
|
266 |
import XML.Decode._ |
|
65344
b99283eed13c
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65089
diff
changeset
|
267 |
list(pair(string, string))(Symbol.decode_yxml(File.read(path))) |
51416 | 268 |
} |
269 |
else Nil |
|
51402 | 270 |
} |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
271 |
|
74699 | 272 |
def update_chapter_index( |
273 |
presentation_dir: Path, chapter: String, new_sessions: List[(String, String)]): Unit = |
|
51402 | 274 |
{ |
74699 | 275 |
val dir = Isabelle_System.make_directory(presentation_dir + Path.basic(chapter)) |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
276 |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
277 |
val sessions0 = |
51406
950b897f95bb
proper path -- I/O was hidden due to permissiveness;
wenzelm
parents:
51402
diff
changeset
|
278 |
try { read_sessions(dir) } |
51987 | 279 |
catch { case _: XML.Error => Nil } |
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
280 |
|
51402 | 281 |
val sessions = (SortedMap.empty[String, String] ++ sessions0 ++ new_sessions).toList |
74699 | 282 |
File.write(dir + sessions_path, |
283 |
{ |
|
284 |
import XML.Encode._ |
|
285 |
YXML.string_of_body(list(pair(string, string))(sessions)) |
|
286 |
}) |
|
51402 | 287 |
|
65988 | 288 |
val title = "Isabelle/" + chapter + " sessions" |
289 |
HTML.write_document(dir, "index.html", |
|
73523
2cd23d587db9
further clarification of Isabelle distribution identification -- avoid odd patching of sources;
wenzelm
parents:
73474
diff
changeset
|
290 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
65988 | 291 |
HTML.chapter(title) :: |
292 |
(if (sessions.isEmpty) Nil |
|
293 |
else |
|
65992 | 294 |
List(HTML.div("sessions", |
295 |
List(HTML.description( |
|
65988 | 296 |
sessions.map({ case (name, description) => |
69318 | 297 |
val descr = Symbol.trim_blank_lines(description) |
65989 | 298 |
(List(HTML.link(name + "/index.html", HTML.text(name))), |
69318 | 299 |
if (descr == "") Nil |
300 |
else HTML.break ::: List(HTML.pre(HTML.text(descr)))) }))))))) |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
301 |
} |
61372 | 302 |
|
74700
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
303 |
def update_global_index(presentation_dir: Path): Unit = |
61372 | 304 |
{ |
74700
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
305 |
Isabelle_System.make_directory(presentation_dir) |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
306 |
Isabelle_System.copy_file(Path.explode("~~/lib/logo/isabelle.gif"), |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
307 |
presentation_dir + Path.explode("isabelle.gif")) |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
308 |
val title = "The " + XML.text(Isabelle_System.isabelle_name()) + " Library" |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
309 |
File.write(presentation_dir + Path.explode("index.html"), |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
310 |
HTML.header + |
73529 | 311 |
""" |
73528
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
312 |
<head> |
73529 | 313 |
""" + HTML.head_meta + """ |
73528
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
314 |
<title>""" + title + """</title> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
315 |
</head> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
316 |
|
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
317 |
<body text="#000000" bgcolor="#FFFFFF" link="#0000FF" vlink="#000099" alink="#404040"> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
318 |
<center> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
319 |
<table width="100%" border="0" cellspacing="10" cellpadding="0"> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
320 |
<tr> |
74676 | 321 |
<td width="20%" valign="middle" align="center"><a href="https://isabelle.in.tum.de/"><img align="bottom" src="isabelle.gif" width="100" height="86" alt="[Isabelle]" border="0" /></a></td> |
73528
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
322 |
|
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
323 |
<td width="80%" valign="middle" align="center"> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
324 |
<table width="90%" border="0" cellspacing="0" cellpadding="20"> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
325 |
<tr> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
326 |
<td valign="middle" align="center" bgcolor="#AACCCC"><font face="Helvetica,Arial" size="+2">""" + title + """</font></td> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
327 |
</tr> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
328 |
</table> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
329 |
</td> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
330 |
</tr> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
331 |
</table> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
332 |
</center> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
333 |
<hr /> |
74670
b2604cd4d131
recover library_index_content.template from c337c798f64c: required for website/build/main;
wenzelm
parents:
73718
diff
changeset
|
334 |
""" + File.read(Path.explode("~~/lib/html/library_index_content.template")) + |
b2604cd4d131
recover library_index_content.template from c337c798f64c: required for website/build/main;
wenzelm
parents:
73718
diff
changeset
|
335 |
""" |
73528
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
336 |
</body> |
73529 | 337 |
""" + HTML.footer) |
61372 | 338 |
} |
339 |
||
340 |
||
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
341 |
/* present session */ |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
342 |
|
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
343 |
val session_graph_path = Path.explode("session_graph.pdf") |
72959 | 344 |
val readme_path = Path.explode("README.html") |
345 |
val files_path = Path.explode("files") |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
346 |
|
74677 | 347 |
def html_name(name: Document.Node.Name): String = Path.explode(name.theory_base_name).html.implode |
348 |
def html_path(path: Path): String = (files_path + path.squash.html).implode |
|
349 |
||
350 |
def session_relative(deps: Sessions.Deps, session0: String, session1: String): Option[String] = |
|
351 |
{ |
|
352 |
for { |
|
353 |
info0 <- deps.sessions_structure.get(session0) |
|
354 |
info1 <- deps.sessions_structure.get(session1) |
|
355 |
} yield info0.relative_path(info1) |
|
356 |
} |
|
357 |
||
358 |
def node_relative( |
|
359 |
deps: Sessions.Deps, |
|
360 |
session0: String, |
|
361 |
node_name: Document.Node.Name): Option[String] = |
|
362 |
{ |
|
363 |
val session1 = deps(session0).theory_qualifier(node_name) |
|
364 |
session_relative(deps, session0, session1) |
|
365 |
} |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
366 |
|
73042 | 367 |
def theory_link(deps: Sessions.Deps, session0: String, |
74677 | 368 |
name: Document.Node.Name, body: XML.Body, anchor: Option[String] = None): Option[XML.Tree] = |
73042 | 369 |
{ |
370 |
val session1 = deps(session0).theory_qualifier(name) |
|
73057 | 371 |
val info0 = deps.sessions_structure.get(session0) |
372 |
val info1 = deps.sessions_structure.get(session1) |
|
74677 | 373 |
val fragment = if (anchor.isDefined) "#" + anchor.get else "" |
73057 | 374 |
if (info0.isDefined && info1.isDefined) { |
74677 | 375 |
Some(HTML.link(info0.get.relative_path(info1.get) + html_name(name) + fragment, body)) |
73057 | 376 |
} |
377 |
else None |
|
73042 | 378 |
} |
379 |
||
72648 | 380 |
def session_html( |
72962 | 381 |
resources: Resources, |
72648 | 382 |
session: String, |
383 |
deps: Sessions.Deps, |
|
72683 | 384 |
db_context: Sessions.Database_Context, |
72992 | 385 |
progress: Progress = new Progress, |
73022
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
386 |
verbose: Boolean = false, |
72962 | 387 |
html_context: HTML_Context, |
73055 | 388 |
elements: Elements, |
74697 | 389 |
presentation: Context): Unit = |
61372 | 390 |
{ |
74703
9d7f95c43584
observer proper session hierarchy (according to build_graph): thus exported artifacts are always valid;
wenzelm
parents:
74702
diff
changeset
|
391 |
val hierarchy = deps.sessions_structure.hierarchy(session) |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
392 |
val info = deps.sessions_structure(session) |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
393 |
val options = info.options |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
394 |
val base = deps(session) |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
395 |
|
72683 | 396 |
val session_dir = presentation.dir(db_context.store, info) |
72962 | 397 |
|
398 |
html_context.init_fonts(session_dir) |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
399 |
|
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
400 |
Bytes.write(session_dir + session_graph_path, |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
401 |
graphview.Graph_File.make_pdf(options, base.session_graph_display)) |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
402 |
|
72673
8ff7a0e394f9
clarified PDF/HTML presentation, based on pdf blobs from session database (e.g. from earlier builds);
wenzelm
parents:
72670
diff
changeset
|
403 |
val documents = |
72683 | 404 |
for { |
405 |
doc <- info.document_variants |
|
73718 | 406 |
document <- db_context.input_database(session)(Document_Build.read_document(_, _, doc.name)) |
73022
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
407 |
} yield { |
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
408 |
if (verbose) progress.echo("Presenting document " + session + "/" + doc.name) |
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
409 |
Bytes.write(session_dir + doc.path.pdf, document.pdf) |
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
410 |
doc |
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
411 |
} |
72673
8ff7a0e394f9
clarified PDF/HTML presentation, based on pdf blobs from session database (e.g. from earlier builds);
wenzelm
parents:
72670
diff
changeset
|
412 |
|
73041 | 413 |
val view_links = |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
414 |
{ |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
415 |
val deps_link = |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
416 |
HTML.link(session_graph_path, HTML.text("theory dependencies")) |
61372 | 417 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
418 |
val readme_links = |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
419 |
if ((info.dir + readme_path).is_file) { |
73317 | 420 |
Isabelle_System.copy_file(info.dir + readme_path, session_dir + readme_path) |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
421 |
List(HTML.link(readme_path, HTML.text("README"))) |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
422 |
} |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
423 |
else Nil |
62971
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
424 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
425 |
val document_links = |
72673
8ff7a0e394f9
clarified PDF/HTML presentation, based on pdf blobs from session database (e.g. from earlier builds);
wenzelm
parents:
72670
diff
changeset
|
426 |
documents.map(doc => HTML.link(doc.path.pdf, HTML.text(doc.name))) |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
427 |
|
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
428 |
Library.separate(HTML.break ::: HTML.nl, |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
429 |
(deps_link :: readme_links ::: document_links). |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
430 |
map(link => HTML.text("View ") ::: List(link))).flatten |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
431 |
} |
62971
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
432 |
|
74707 | 433 |
val theory_exports: Map[String, Export_Theory.Theory] = |
74702 | 434 |
(for ((_, entry) <- base.known_theories.iterator) yield { |
435 |
val thy_name = entry.name.theory |
|
436 |
val theory = |
|
437 |
if (thy_name == Thy_Header.PURE) Export_Theory.no_theory |
|
438 |
else { |
|
439 |
html_context.cache_theory(thy_name, |
|
440 |
{ |
|
74706 | 441 |
val provider = Export.Provider.database_context(db_context, hierarchy, thy_name) |
442 |
Export_Theory.read_theory( |
|
443 |
provider, session, thy_name, cache = html_context.term_cache) |
|
74702 | 444 |
}) |
445 |
} |
|
446 |
thy_name -> theory |
|
447 |
}).toMap |
|
74677 | 448 |
|
72989 | 449 |
val theories: List[XML.Body] = |
72962 | 450 |
{ |
451 |
var seen_files = List.empty[(Path, String, Document.Node.Name)] |
|
73056 | 452 |
|
74678 | 453 |
def node_file(node: Document.Node.Name): String = |
74677 | 454 |
if (node.node.endsWith(".thy")) html_name(node) else html_path(Path.explode(node.node)) |
455 |
||
74678 | 456 |
def entity_anchor( |
457 |
context: Entity_Context, range: Symbol.Range, body: XML.Body): Option[XML.Elem] = |
|
74677 | 458 |
{ |
459 |
body match { |
|
460 |
case List(XML.Elem(Markup("span", List("id" -> _)), _)) => None |
|
461 |
case _ => |
|
462 |
Some { |
|
74704 | 463 |
val entities = |
74707 | 464 |
theory_exports.get(context.node.theory).flatMap(_.entity_by_range.get(range)) |
74704 | 465 |
.getOrElse(Nil) |
74678 | 466 |
val body1 = |
467 |
if (context.seen_ranges.contains(range)) { |
|
74679 | 468 |
HTML.entity_def(HTML.span(HTML.id(html_context.offset_ref(range)), body)) |
74678 | 469 |
} |
470 |
else HTML.span(body) |
|
74705
909afe2361b1
prefer "NAME|KIND" format, as already used in Isabelle/MMT and Isabelle/Dedukti;
wenzelm
parents:
74704
diff
changeset
|
471 |
entities.map(_.kname).foldLeft(body1) { |
74704 | 472 |
case (elem, id) => HTML.entity_def(HTML.span(HTML.id(id), List(elem))) |
74677 | 473 |
} |
474 |
} |
|
475 |
} |
|
476 |
} |
|
477 |
||
74694
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
478 |
def entity_ref(thy_name: String, kind: String, name: String): Option[String] = |
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
479 |
for { |
74707 | 480 |
thy <- theory_exports.get(thy_name) |
74708 | 481 |
entity <- thy.entity_by_kind_name.get((kind, name)) |
74705
909afe2361b1
prefer "NAME|KIND" format, as already used in Isabelle/MMT and Isabelle/Dedukti;
wenzelm
parents:
74704
diff
changeset
|
482 |
} yield entity.kname |
74677 | 483 |
|
74694
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
484 |
def offset_ref(context: Entity_Context, thy_name: String, props: Properties.T): Option[String] = |
74678 | 485 |
{ |
74694
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
486 |
if (thy_name == context.node.theory) { |
74677 | 487 |
for { |
488 |
offset <- Position.Def_Offset.unapply(props) |
|
489 |
end_offset <- Position.Def_End_Offset.unapply(props) |
|
490 |
range = Text.Range(offset, end_offset) |
|
491 |
} yield { |
|
492 |
context.seen_ranges += range |
|
493 |
html_context.offset_ref(range) |
|
494 |
} |
|
74694
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
495 |
} |
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
496 |
else None |
74677 | 497 |
} |
498 |
||
74678 | 499 |
def entity_link( |
500 |
context: Entity_Context, props: Properties.T, body: XML.Body): Option[XML.Elem] = |
|
74677 | 501 |
{ |
74694
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
502 |
(props, props, props, props, props) match { |
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
503 |
case (Markup.Kind(Markup.THEORY), Markup.Name(theory), Position.Def_File(thy_file), _, _) => |
73057 | 504 |
val node_name = resources.file_node(Path.explode(thy_file), theory = theory) |
74678 | 505 |
node_relative(deps, session, node_name).map(html_dir => |
506 |
HTML.link(html_dir + html_name(node_name), body)) |
|
74677 | 507 |
case (Markup.Ref(_), Position.Def_File(thy_file), Position.Def_Theory(def_theory), |
74694
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
508 |
Markup.Kind(kind), Markup.Name(name)) => |
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
509 |
val thy_name = if (def_theory.nonEmpty) def_theory else context.node.theory |
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
510 |
val node_name = resources.file_node(Path.explode(thy_file), theory = thy_name) |
74677 | 511 |
for { |
512 |
html_dir <- node_relative(deps, session, node_name) |
|
513 |
html_file = node_file(node_name) |
|
74694
2d9d92116fac
clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents:
74693
diff
changeset
|
514 |
html_ref <- entity_ref(thy_name, kind, name).orElse(offset_ref(context, thy_name, props)) |
74677 | 515 |
} yield { |
74679 | 516 |
HTML.entity_ref(HTML.link(html_dir + html_file + "#" + html_ref, body)) |
74677 | 517 |
} |
73056 | 518 |
case _ => None |
519 |
} |
|
74677 | 520 |
} |
73056 | 521 |
|
73215 | 522 |
sealed case class Theory( |
523 |
name: Document.Node.Name, |
|
524 |
command: Command, |
|
525 |
files_html: List[(Path, XML.Tree)], |
|
526 |
html: XML.Tree) |
|
527 |
||
528 |
def read_theory(name: Document.Node.Name): Option[Theory] = |
|
529 |
{ |
|
530 |
progress.expose_interrupt() |
|
73216 | 531 |
if (verbose) progress.echo("Presenting theory " + name) |
73215 | 532 |
|
533 |
for (command <- Build_Job.read_theory(db_context, resources, session, name.theory)) |
|
534 |
yield { |
|
535 |
val snapshot = Document.State.init.snippet(command) |
|
73214 | 536 |
|
73215 | 537 |
val files_html = |
538 |
for { |
|
539 |
(src_path, xml) <- snapshot.xml_markup_blobs(elements = elements.html) |
|
540 |
if xml.nonEmpty |
|
541 |
} |
|
542 |
yield { |
|
543 |
progress.expose_interrupt() |
|
73216 | 544 |
if (verbose) progress.echo("Presenting file " + src_path) |
545 |
||
74677 | 546 |
(src_path, html_context.source( |
547 |
make_html(name, elements, entity_anchor, entity_link, xml))) |
|
73215 | 548 |
} |
549 |
||
550 |
val html = |
|
551 |
html_context.source( |
|
74677 | 552 |
make_html(name, elements, entity_anchor, entity_link, |
553 |
snapshot.xml_markup(elements = elements.html))) |
|
73215 | 554 |
|
555 |
Theory(name, command, files_html, html) |
|
556 |
} |
|
557 |
} |
|
558 |
||
559 |
for (thy <- Par_List.map(read_theory, base.session_theories).flatten) |
|
72669 | 560 |
yield { |
72989 | 561 |
val files = |
73215 | 562 |
for { (src_path, file_html) <- thy.files_html } |
73043 | 563 |
yield { |
74677 | 564 |
val file_name = html_path(src_path) |
72989 | 565 |
|
566 |
seen_files.find(p => p._1 == src_path || p._2 == file_name) match { |
|
73215 | 567 |
case None => seen_files ::= (src_path, file_name, thy.name) |
72989 | 568 |
case Some((_, _, thy_name1)) => |
569 |
error("Incoherent use of file name " + src_path + " as " + quote(file_name) + |
|
73215 | 570 |
" in theory " + thy_name1 + " vs. " + thy.name) |
72989 | 571 |
} |
72669 | 572 |
|
72989 | 573 |
val file_path = session_dir + Path.explode(file_name) |
574 |
html_context.init_fonts(file_path.dir) |
|
575 |
||
576 |
val file_title = "File " + Symbol.cartouche_decoded(src_path.implode_short) |
|
577 |
HTML.write_document(file_path.dir, file_path.file_name, |
|
73215 | 578 |
List(HTML.title(file_title)), List(html_context.head(file_title), file_html)) |
72989 | 579 |
|
580 |
List(HTML.link(file_name, HTML.text(file_title))) |
|
73043 | 581 |
} |
72989 | 582 |
|
73215 | 583 |
val thy_title = "Theory " + thy.name.theory_base_name |
72989 | 584 |
|
73215 | 585 |
HTML.write_document(session_dir, html_name(thy.name), |
586 |
List(HTML.title(thy_title)), List(html_context.head(thy_title), thy.html)) |
|
587 |
||
588 |
List(HTML.link(html_name(thy.name), |
|
589 |
HTML.text(thy.name.theory_base_name) ::: |
|
72989 | 590 |
(if (files.isEmpty) Nil else List(HTML.itemize(files))))) |
72669 | 591 |
} |
72989 | 592 |
} |
61500 | 593 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
594 |
val title = "Session " + session |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
595 |
HTML.write_document(session_dir, "index.html", |
73523
2cd23d587db9
further clarification of Isabelle distribution identification -- avoid odd patching of sources;
wenzelm
parents:
73474
diff
changeset
|
596 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
73041 | 597 |
html_context.head(title, List(HTML.par(view_links))) :: |
72989 | 598 |
html_context.contents("Theories", theories)) |
61372 | 599 |
} |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
600 |
} |