author | wenzelm |
Fri, 26 Aug 2022 21:49:13 +0200 | |
changeset 75990 | aaa0148e7c8f |
parent 75989 | 46c6f649a943 |
child 75991 | 0dbf2b2c04f4 |
permissions | -rw-r--r-- |
75941 | 1 |
/* Title: Pure/Thy/browser_info.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 |
|
75949
b09dab301d72
tuned comments, following "isabelle build" usage;
wenzelm
parents:
75947
diff
changeset
|
4 |
HTML/PDF presentation of PIDE document information. |
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 |
||
75941 | 15 |
object Browser_Info { |
75945 | 16 |
/* browser_info store configuration */ |
75943 | 17 |
|
18 |
object Config { |
|
19 |
val none: Config = new Config { def enabled: Boolean = false } |
|
20 |
val standard: Config = new Config { def enabled: Boolean = true } |
|
21 |
||
22 |
def dir(path: Path): Config = |
|
23 |
new Config { |
|
24 |
def enabled: Boolean = true |
|
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
25 |
override def presentation_dir(store: Sessions.Store): Path = path |
75943 | 26 |
} |
72957 | 27 |
|
75943 | 28 |
def make(s: String): Config = |
29 |
if (s == ":") standard else dir(Path.explode(s)) |
|
30 |
} |
|
31 |
||
32 |
abstract class Config private { |
|
33 |
def enabled: Boolean |
|
34 |
def enabled(info: Sessions.Info): Boolean = enabled || info.browser_info |
|
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
35 |
def presentation_dir(store: Sessions.Store): Path = store.presentation_dir |
75943 | 36 |
} |
37 |
||
38 |
||
75961 | 39 |
/* meta data within the file-system */ |
40 |
||
41 |
object Meta_Data { |
|
42 |
/* directory */ |
|
43 |
||
44 |
val PATH: Path = Path.explode(".browser_info") |
|
45 |
||
46 |
def check_directory(dir: Path): Unit = { |
|
47 |
if (dir.is_dir && !(dir + PATH).is_dir && File.read_dir(dir).nonEmpty) { |
|
48 |
error("Existing content in " + dir.expand + " lacks " + PATH + " meta data.\n" + |
|
49 |
"To avoid potential disaster, it has not been changed automatically.\n" + |
|
50 |
"If this is the intended directory, please move/remove/empty it manually.") |
|
51 |
} |
|
52 |
} |
|
53 |
||
54 |
def init_directory(dir: Path): Path = { |
|
55 |
check_directory(dir) |
|
56 |
Isabelle_System.make_directory(dir + PATH) |
|
57 |
dir |
|
58 |
} |
|
59 |
||
75982
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
60 |
def clean_directory(dir: Path): Path = { |
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
61 |
check_directory(dir) |
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
62 |
Isabelle_System.rm_tree(dir) // guarded by check_directory! |
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
63 |
Isabelle_System.new_directory(dir + PATH) |
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
64 |
} |
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
65 |
|
75961 | 66 |
|
67 |
/* content */ |
|
68 |
||
69 |
def make_path(dir: Path, name: String): Path = |
|
70 |
dir + PATH + Path.basic(name) |
|
71 |
||
72 |
def value(dir: Path, name: String): String = { |
|
73 |
val path = make_path(dir, name) |
|
74 |
if (path.is_file) File.read(path) else "" |
|
75 |
} |
|
76 |
||
77 |
def change(dir: Path, name: String)(f: String => String): Unit = { |
|
78 |
val path = make_path(dir, name) |
|
79 |
val x = value(dir, name) |
|
80 |
val y = |
|
81 |
try { f(x) } |
|
82 |
catch { case ERROR(msg) => error("Failed to change " + path.expand + ":\n" + msg)} |
|
83 |
if (x != y) File.write(path, y) |
|
84 |
} |
|
85 |
||
86 |
||
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
87 |
/* build_uuid */ |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
88 |
|
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
89 |
val BUILD_UUID = "build_uuid" |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
90 |
|
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
91 |
def check_build_uuid(dir: Path, uuid: String): Boolean = { |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
92 |
val uuid0 = value(dir, BUILD_UUID) |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
93 |
uuid0.nonEmpty && uuid.nonEmpty && uuid0 == uuid |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
94 |
} |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
95 |
|
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
96 |
def set_build_uuid(dir: Path, uuid: String): Unit = |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
97 |
change(dir, BUILD_UUID)(_ => uuid) |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
98 |
|
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
99 |
|
75961 | 100 |
/* index */ |
101 |
||
102 |
val INDEX = "index.json" |
|
103 |
||
104 |
object Item { |
|
105 |
def parse(json: JSON.T): Item = { |
|
106 |
def err(): Nothing = |
|
107 |
error("Bad JSON object for item:\n" + JSON.Format.pretty_print(json)) |
|
108 |
val obj = JSON.Object.unapply(json) getOrElse err() |
|
109 |
||
110 |
val name = JSON.string(obj, "name") getOrElse err() |
|
111 |
val description = JSON.string(obj, "description") getOrElse "" |
|
112 |
Item(name, description = Symbol.trim_blank_lines(description)) |
|
113 |
} |
|
114 |
} |
|
115 |
||
116 |
sealed case class Item(name: String, description: String = "") { |
|
117 |
def json: JSON.T = JSON.Object("name" -> name, "description" -> description) |
|
118 |
} |
|
119 |
||
120 |
object Index { |
|
121 |
def parse(s: JSON.S, kind: String): Index = { |
|
122 |
if (s.isEmpty) Index(kind, Nil) |
|
123 |
else { |
|
124 |
def err(): Nothing = error("Bad JSON object " + kind + " index:\n" + s) |
|
125 |
||
126 |
val json = JSON.parse(s) |
|
127 |
val obj = JSON.Object.unapply(json) getOrElse err() |
|
128 |
||
129 |
val kind1 = JSON.string(obj, "kind") getOrElse err() |
|
130 |
val items = JSON.list(obj, "items", x => Some(Item.parse(x))) getOrElse err() |
|
131 |
if (kind == kind1) Index(kind, items) |
|
132 |
else error("Expected index kind " + quote(kind) + " but found " + quote(kind1)) |
|
133 |
} |
|
134 |
} |
|
135 |
} |
|
136 |
||
137 |
sealed case class Index(kind: String, items: List[Item]) { |
|
75990 | 138 |
def ++ (more_items: List[Item]): Index = { |
139 |
val items1 = items.filterNot(item => more_items.exists(_.name == item.name)) |
|
140 |
val items2 = (more_items ::: items1).sortBy(_.name) |
|
141 |
Index(kind, items2) |
|
142 |
} |
|
143 |
def + (item: Item): Index = this ++ List(item) |
|
75961 | 144 |
|
145 |
def json: JSON.T = JSON.Object("kind" -> kind, "items" -> items.map(_.json)) |
|
146 |
def print_json: JSON.S = JSON.Format.pretty_print(json) |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
||
75945 | 151 |
/* presentation elements */ |
152 |
||
153 |
sealed case class Elements( |
|
154 |
html: Markup.Elements = Markup.Elements.empty, |
|
155 |
entity: Markup.Elements = Markup.Elements.empty, |
|
156 |
language: Markup.Elements = Markup.Elements.empty) |
|
157 |
||
75979 | 158 |
val default_elements: Elements = |
75945 | 159 |
Elements( |
160 |
html = Rendering.foreground_elements ++ Rendering.text_color_elements + |
|
161 |
Markup.NUMERAL + Markup.COMMENT + Markup.ENTITY + Markup.LANGUAGE, |
|
162 |
entity = Markup.Elements(Markup.THEORY, Markup.TYPE_NAME, Markup.CONSTANT, Markup.FACT, |
|
163 |
Markup.CLASS, Markup.LOCALE, Markup.FREE)) |
|
164 |
||
75979 | 165 |
val extra_elements: Elements = |
75945 | 166 |
Elements( |
75979 | 167 |
html = default_elements.html ++ Rendering.markdown_elements, |
75945 | 168 |
language = Markup.Elements(Markup.Language.DOCUMENT)) |
169 |
||
170 |
||
75943 | 171 |
|
75949
b09dab301d72
tuned comments, following "isabelle build" usage;
wenzelm
parents:
75947
diff
changeset
|
172 |
/** HTML/PDF presentation context **/ |
73718 | 173 |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
174 |
def context( |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
175 |
sessions_structure: Sessions.Structure, |
75979 | 176 |
elements: Elements = default_elements, |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
177 |
root_dir: Path = Path.current, |
75907 | 178 |
document_info: Document_Info = Document_Info.empty |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
179 |
): Context = new Context(sessions_structure, elements, root_dir, document_info) |
72957 | 180 |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
181 |
class Context private[Browser_Info]( |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
182 |
sessions_structure: Sessions.Structure, |
75897 | 183 |
val elements: Elements, |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
184 |
val root_dir: Path, |
75907 | 185 |
val document_info: Document_Info |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
186 |
) { |
74818
3064e165c660
clarified HTML_Context.theory_exports: prefer value-oriented parallelism;
wenzelm
parents:
74816
diff
changeset
|
187 |
/* directory structure and resources */ |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
188 |
|
75907 | 189 |
def theory_by_name(session: String, theory: String): Option[Document_Info.Theory] = |
190 |
document_info.theory_by_name(session, theory) |
|
75894 | 191 |
|
75907 | 192 |
def theory_by_file(session: String, file: String): Option[Document_Info.Theory] = |
193 |
document_info.theory_by_file(session, file) |
|
75897 | 194 |
|
75980 | 195 |
def session_chapter(session: String): String = |
196 |
sessions_structure(session).chapter |
|
197 |
||
75981 | 198 |
def chapter_dir(session: String): Path = |
199 |
root_dir + Path.basic(session_chapter(session)) |
|
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
200 |
|
75981 | 201 |
def session_dir(session: String): Path = |
202 |
chapter_dir(session) + Path.basic(session) |
|
75961 | 203 |
|
75946 | 204 |
def theory_dir(theory: Document_Info.Theory): Path = |
205 |
session_dir(theory.dynamic_session) |
|
206 |
||
75907 | 207 |
def theory_html(theory: Document_Info.Theory): Path = |
75917
20b918404aa3
evade clash with index.html (allow "Index.thy" even on case-insensitive file-systems);
wenzelm
parents:
75916
diff
changeset
|
208 |
{ |
75926
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
209 |
def check(name: String): Option[Path] = { |
75977
59aa034220bf
more robust: ensure that chapter/session/theory do not contain special notation (like "/" or "..");
wenzelm
parents:
75971
diff
changeset
|
210 |
val path = Path.basic(name).html |
75926
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
211 |
if (Path.eq_case_insensitive(path, Path.index_html)) None |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
212 |
else Some(path) |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
213 |
} |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
214 |
check(theory.print_short) orElse check(theory.name) getOrElse |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
215 |
error("Illegal global theory name " + quote(theory.name) + |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
216 |
" (conflict with " + Path.index_html + ")") |
75917
20b918404aa3
evade clash with index.html (allow "Index.thy" even on case-insensitive file-systems);
wenzelm
parents:
75916
diff
changeset
|
217 |
} |
75900 | 218 |
|
75915
95d7459e5bc0
clarified directory layout (again): mimic original directory layout, notably ISABELLE_HOME;
wenzelm
parents:
75914
diff
changeset
|
219 |
def file_html(file: String): Path = |
95d7459e5bc0
clarified directory layout (again): mimic original directory layout, notably ISABELLE_HOME;
wenzelm
parents:
75914
diff
changeset
|
220 |
Path.explode(file).squash.html |
75900 | 221 |
|
75914
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75913
diff
changeset
|
222 |
def smart_html(theory: Document_Info.Theory, file: String): Path = |
75915
95d7459e5bc0
clarified directory layout (again): mimic original directory layout, notably ISABELLE_HOME;
wenzelm
parents:
75914
diff
changeset
|
223 |
if (File.is_thy(file)) theory_html(theory) else file_html(file) |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
224 |
|
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
225 |
|
74769 | 226 |
/* HTML content */ |
227 |
||
72962 | 228 |
def head(title: String, rest: XML.Body = Nil): XML.Tree = |
229 |
HTML.div("head", HTML.chapter(title) :: rest) |
|
230 |
||
231 |
def source(body: XML.Body): XML.Tree = HTML.pre("source", body) |
|
232 |
||
75393 | 233 |
def contents( |
234 |
heading: String, |
|
235 |
items: List[XML.Body], |
|
236 |
css_class: String = "contents" |
|
237 |
) : List[XML.Elem] = { |
|
72962 | 238 |
if (items.isEmpty) Nil |
239 |
else List(HTML.div(css_class, List(HTML.section(heading), HTML.itemize(items)))) |
|
240 |
} |
|
241 |
||
75944 | 242 |
|
243 |
/* preview PIDE document */ |
|
244 |
||
75969 | 245 |
lazy val isabelle_css: String = File.read(HTML.isabelle_css) |
74768 | 246 |
|
75393 | 247 |
def html_document(title: String, body: XML.Body, fonts_css: String): HTML_Document = { |
74709 | 248 |
val content = |
249 |
HTML.output_document( |
|
250 |
List( |
|
74768 | 251 |
HTML.style(fonts_css + "\n\n" + isabelle_css), |
74709 | 252 |
HTML.title(title)), |
253 |
List(HTML.source(body)), css = "", structural = false) |
|
254 |
HTML_Document(title, content) |
|
255 |
} |
|
75944 | 256 |
|
257 |
def preview_document( |
|
258 |
snapshot: Document.Snapshot, |
|
259 |
plain_text: Boolean = false, |
|
260 |
fonts_css: String = HTML.fonts_css() |
|
261 |
): HTML_Document = { |
|
262 |
require(!snapshot.is_outdated, "document snapshot outdated") |
|
263 |
||
264 |
val name = snapshot.node_name |
|
265 |
if (plain_text) { |
|
266 |
val title = "File " + Symbol.cartouche_decoded(name.path.file_name) |
|
267 |
val body = HTML.text(snapshot.node.source) |
|
268 |
html_document(title, body, fonts_css) |
|
269 |
} |
|
270 |
else { |
|
271 |
Resources.html_document(snapshot) getOrElse { |
|
272 |
val title = |
|
273 |
if (name.is_theory) "Theory " + quote(name.theory_base_name) |
|
274 |
else "File " + Symbol.cartouche_decoded(name.path.file_name) |
|
275 |
val xml = snapshot.xml_markup(elements = elements.html) |
|
276 |
val body = Node_Context.empty.make_html(elements, xml) |
|
277 |
html_document(title, body, fonts_css) |
|
278 |
} |
|
279 |
} |
|
280 |
} |
|
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
281 |
|
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
282 |
|
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
283 |
/* maintain presentation structure */ |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
284 |
|
75980 | 285 |
def update_chapter(session_name: String, session_description: String): Unit = synchronized { |
75981 | 286 |
val dir = Meta_Data.init_directory(chapter_dir(session_name)) |
75961 | 287 |
Meta_Data.change(dir, Meta_Data.INDEX) { text => |
288 |
val index0 = Meta_Data.Index.parse(text, "chapter") |
|
289 |
val item = Meta_Data.Item(session_name, description = session_description) |
|
290 |
val index = index0 + item |
|
291 |
val sessions = index.items |
|
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
292 |
|
75961 | 293 |
if (index != index0) { |
75981 | 294 |
val title = "Isabelle/" + session_chapter(session_name) + " sessions" |
75961 | 295 |
HTML.write_document(dir, "index.html", |
296 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
|
297 |
HTML.chapter(title) :: |
|
298 |
(if (sessions.isEmpty) Nil |
|
299 |
else |
|
300 |
List(HTML.div("sessions", |
|
301 |
List(HTML.description( |
|
302 |
sessions.map(session => |
|
303 |
(List(HTML.link(session.name + "/index.html", HTML.text(session.name))), |
|
304 |
if (session.description.isEmpty) Nil |
|
305 |
else HTML.break ::: List(HTML.pre(HTML.text(session.description)))))))))), |
|
306 |
root = Some(root_dir)) |
|
307 |
} |
|
75953
32c4f8766831
clarified synchronized operations: approximate file-system transactions;
wenzelm
parents:
75952
diff
changeset
|
308 |
|
75961 | 309 |
index.print_json |
310 |
} |
|
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
311 |
} |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
312 |
|
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
313 |
def update_root(): Unit = synchronized { |
75961 | 314 |
Meta_Data.init_directory(root_dir) |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
315 |
HTML.init_fonts(root_dir) |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
316 |
Isabelle_System.copy_file(Path.explode("~~/lib/logo/isabelle.gif"), |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
317 |
root_dir + Path.explode("isabelle.gif")) |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
318 |
|
75989
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
319 |
Meta_Data.change(root_dir, Meta_Data.INDEX) { text => |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
320 |
val index0 = Meta_Data.Index.parse(text, "root") |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
321 |
val index = { |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
322 |
val items1 = |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
323 |
for (entry <- sessions_structure.chapter_defs.list) |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
324 |
yield Meta_Data.Item(entry.name, description = entry.description) |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
325 |
val items2 = |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
326 |
(for { |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
327 |
(name, _) <- sessions_structure.chapters.iterator |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
328 |
if !items1.exists(_.name == name) |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
329 |
} yield Meta_Data.Item(name)).toList |
75990 | 330 |
index0 ++ (items1 ::: items2) |
75989
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
331 |
} |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
332 |
val chapters = index.items |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
333 |
|
75989
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
334 |
if (index != index0) { |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
335 |
val title = "The " + XML.text(Isabelle_System.isabelle_name()) + " Library" |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
336 |
HTML.write_document(root_dir, "index.html", |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
337 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
338 |
HTML.chapter(title) :: |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
339 |
(if (chapters.isEmpty) Nil |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
340 |
else |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
341 |
List(HTML.div("sessions", |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
342 |
List(HTML.description( |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
343 |
chapters.map(chapter => |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
344 |
(List(HTML.link(chapter.name + "/index.html", HTML.text(chapter.name))), |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
345 |
if (chapter.description.isEmpty) Nil |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
346 |
else HTML.break ::: List(HTML.pre(HTML.text(chapter.description)))))))))), |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
347 |
root = Some(root_dir)) |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
348 |
} |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
349 |
|
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
350 |
index.print_json |
46c6f649a943
produce root index based on sessions_structure.chapter_defs;
wenzelm
parents:
75982
diff
changeset
|
351 |
} |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
352 |
} |
72959 | 353 |
} |
354 |
||
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
355 |
sealed case class HTML_Document(title: String, content: String) |
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
356 |
|
72957 | 357 |
|
74678 | 358 |
/* formal entities */ |
74677 | 359 |
|
75891 | 360 |
object Theory_Ref { |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
361 |
def unapply(props: Properties.T): Option[String] = |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
362 |
(props, props) match { |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
363 |
case (Markup.Kind(Markup.THEORY), Markup.Name(theory)) => Some(theory) |
75891 | 364 |
case _ => None |
365 |
} |
|
366 |
} |
|
74765 | 367 |
|
75891 | 368 |
object Entity_Ref { |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
369 |
def unapply(props: Properties.T): Option[(String, String, String)] = |
75891 | 370 |
(props, props, props, props) match { |
75913 | 371 |
case (Markup.Entity.Ref.Prop(_), Position.Def_File(file), Markup.Kind(kind), Markup.Name(name)) |
372 |
if Path.is_wellformed(file) => Some((file, kind, name)) |
|
75891 | 373 |
case _ => None |
374 |
} |
|
375 |
} |
|
74765 | 376 |
|
75927 | 377 |
object Node_Context { |
378 |
val empty: Node_Context = new Node_Context |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
379 |
|
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
380 |
def make( |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
381 |
context: Context, |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
382 |
session_name: String, |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
383 |
theory_name: String, |
75929
811092261546
proper node_dir within presentation_dir, not source file directory;
wenzelm
parents:
75928
diff
changeset
|
384 |
file_name: String, |
811092261546
proper node_dir within presentation_dir, not source file directory;
wenzelm
parents:
75928
diff
changeset
|
385 |
node_dir: Path, |
75927 | 386 |
): Node_Context = |
387 |
new Node_Context { |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
388 |
private val seen_ranges: mutable.Set[Symbol.Range] = mutable.Set.empty |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
389 |
|
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
390 |
override def make_def(range: Symbol.Range, body: XML.Body): Option[XML.Elem] = |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
391 |
body match { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
392 |
case List(XML.Elem(Markup("span", List("id" -> _)), _)) => None |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
393 |
case _ => |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
394 |
for (theory <- context.theory_by_name(session_name, theory_name)) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
395 |
yield { |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
396 |
val body1 = |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
397 |
if (seen_ranges.contains(range)) { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
398 |
HTML.entity_def(HTML.span(HTML.id(offset_id(range)), body)) |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
399 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
400 |
else HTML.span(body) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
401 |
theory.get_defs(file_name, range).foldLeft(body1) { |
75896 | 402 |
case (elem, entity) => |
403 |
HTML.entity_def(HTML.span(HTML.id(entity.kname), List(elem))) |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
404 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
405 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
406 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
407 |
|
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
408 |
private def offset_id(range: Text.Range): String = |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
409 |
"offset_" + range.start + ".." + range.stop |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
410 |
|
75393 | 411 |
override def make_ref(props: Properties.T, body: XML.Body): Option[XML.Elem] = { |
74765 | 412 |
props match { |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
413 |
case Theory_Ref(thy_name) => |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
414 |
for (theory <- context.theory_by_name(session_name, thy_name)) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
415 |
yield { |
75946 | 416 |
val html_path = context.theory_dir(theory) + context.theory_html(theory) |
75933 | 417 |
val html_link = HTML.relative_href(html_path, base = Some(node_dir)) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
418 |
HTML.link(html_link, body) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
419 |
} |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
420 |
case Entity_Ref(def_file, kind, name) => |
75907 | 421 |
def logical_ref(theory: Document_Info.Theory): Option[String] = |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
422 |
theory.get_def(def_file, kind, name).map(_.kname) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
423 |
|
75907 | 424 |
def physical_ref(theory: Document_Info.Theory): Option[String] = |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
425 |
props match { |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
426 |
case Position.Def_Range(range) if theory.name == theory_name => |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
427 |
seen_ranges += range |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
428 |
Some(offset_id(range)) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
429 |
case _ => None |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
430 |
} |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
431 |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
432 |
for { |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
433 |
theory <- context.theory_by_file(session_name, def_file) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
434 |
html_ref <- logical_ref(theory) orElse physical_ref(theory) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
435 |
} |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
436 |
yield { |
75946 | 437 |
val html_path = context.theory_dir(theory) + context.smart_html(theory, def_file) |
75933 | 438 |
val html_link = HTML.relative_href(html_path, base = Some(node_dir)) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
439 |
HTML.entity_ref(HTML.link(html_link + "#" + html_ref, body)) |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
440 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
441 |
case _ => None |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
442 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
443 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
444 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
445 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
446 |
|
75927 | 447 |
class Node_Context { |
74753 | 448 |
def make_def(range: Symbol.Range, body: XML.Body): Option[XML.Elem] = None |
449 |
def make_ref(props: Properties.T, body: XML.Body): Option[XML.Elem] = None |
|
73055 | 450 |
|
75928 | 451 |
val div_elements: Set[String] = |
452 |
Set(HTML.div.name, HTML.pre.name, HTML.par.name, HTML.list.name, HTML.`enum`.name, |
|
453 |
HTML.descr.name) |
|
72957 | 454 |
|
75928 | 455 |
def make_html(elements: Elements, xml: XML.Body): XML.Body = { |
456 |
def html_div(html: XML.Body): Boolean = |
|
457 |
html exists { |
|
458 |
case XML.Elem(markup, body) => div_elements.contains(markup.name) || html_div(body) |
|
459 |
case XML.Text(_) => false |
|
460 |
} |
|
461 |
||
462 |
def html_class(c: String, html: XML.Body): XML.Body = |
|
463 |
if (c == "") html |
|
464 |
else if (html_div(html)) List(HTML.div(c, html)) |
|
465 |
else List(HTML.span(c, html)) |
|
72957 | 466 |
|
75928 | 467 |
def html_body(xml_body: XML.Body, end_offset: Symbol.Offset): (XML.Body, Symbol.Offset) = |
468 |
xml_body.foldRight((List.empty[XML.Tree], end_offset)) { case (tree, (res, end_offset1)) => |
|
469 |
val (res1, offset) = html_body_single(tree, end_offset1) |
|
470 |
(res1 ++ res, offset) |
|
471 |
} |
|
74677 | 472 |
|
75928 | 473 |
@tailrec |
474 |
def html_body_single(xml_tree: XML.Tree, end_offset: Symbol.Offset): (XML.Body, Symbol.Offset) = |
|
475 |
xml_tree match { |
|
476 |
case XML.Wrapped_Elem(markup, _, body) => html_body_single(XML.Elem(markup, body), end_offset) |
|
477 |
case XML.Elem(Markup(Markup.ENTITY, props @ Markup.Kind(kind)), body) => |
|
478 |
val (body1, offset) = html_body(body, end_offset) |
|
479 |
if (elements.entity(kind)) { |
|
480 |
make_ref(props, body1) match { |
|
481 |
case Some(link) => (List(link), offset) |
|
482 |
case None => (body1, offset) |
|
483 |
} |
|
73056 | 484 |
} |
75928 | 485 |
else (body1, offset) |
486 |
case XML.Elem(Markup(Markup.LANGUAGE, Markup.Name(name)), body) => |
|
487 |
val (body1, offset) = html_body(body, end_offset) |
|
488 |
(html_class(if (elements.language(name)) name else "", body1), offset) |
|
489 |
case XML.Elem(Markup(Markup.MARKDOWN_PARAGRAPH, _), body) => |
|
490 |
val (body1, offset) = html_body(body, end_offset) |
|
491 |
(List(HTML.par(body1)), offset) |
|
492 |
case XML.Elem(Markup(Markup.MARKDOWN_ITEM, _), body) => |
|
493 |
val (body1, offset) = html_body(body, end_offset) |
|
494 |
(List(HTML.item(body1)), offset) |
|
495 |
case XML.Elem(Markup(Markup.Markdown_Bullet.name, _), text) => |
|
496 |
(Nil, end_offset - XML.symbol_length(text)) |
|
497 |
case XML.Elem(Markup.Markdown_List(kind), body) => |
|
498 |
val (body1, offset) = html_body(body, end_offset) |
|
499 |
if (kind == Markup.ENUMERATE) (List(HTML.`enum`(body1)), offset) |
|
500 |
else (List(HTML.list(body1)), offset) |
|
501 |
case XML.Elem(markup, body) => |
|
502 |
val name = markup.name |
|
503 |
val (body1, offset) = html_body(body, end_offset) |
|
504 |
val html = |
|
505 |
markup.properties match { |
|
506 |
case Markup.Kind(kind) if kind == Markup.COMMAND || kind == Markup.KEYWORD => |
|
507 |
html_class(kind, body1) |
|
508 |
case _ => |
|
509 |
body1 |
|
510 |
} |
|
511 |
Rendering.foreground.get(name) orElse Rendering.text_color.get(name) match { |
|
512 |
case Some(c) => (html_class(c.toString, html), offset) |
|
513 |
case None => (html_class(name, html), offset) |
|
73054 | 514 |
} |
75928 | 515 |
case XML.Text(text) => |
516 |
val offset = end_offset - Symbol.length(text) |
|
517 |
val body = HTML.text(Symbol.decode(text)) |
|
518 |
make_def(Text.Range(offset, end_offset), body) match { |
|
519 |
case Some(body1) => (List(body1), offset) |
|
520 |
case None => (body, offset) |
|
521 |
} |
|
522 |
} |
|
73054 | 523 |
|
75928 | 524 |
html_body(xml, XML.symbol_length(xml) + 1)._1 |
525 |
} |
|
73054 | 526 |
} |
72957 | 527 |
|
528 |
||
529 |
||
75945 | 530 |
/** build presentation **/ |
72649 | 531 |
|
75888 | 532 |
val session_graph_path: Path = Path.explode("session_graph.pdf") |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
533 |
|
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
534 |
def build_session( |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
535 |
context: Context, |
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75774
diff
changeset
|
536 |
session_context: Export.Session_Context, |
72992 | 537 |
progress: Progress = new Progress, |
73022
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
538 |
verbose: Boolean = false, |
75393 | 539 |
): Unit = { |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
540 |
progress.expose_interrupt() |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
541 |
|
75902 | 542 |
val session_name = session_context.session_name |
543 |
val session_info = session_context.sessions_structure(session_name) |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
544 |
|
75961 | 545 |
val session_dir = context.session_dir(session_name).expand |
546 |
progress.echo("Presenting " + session_name + " in " + session_dir + " ...") |
|
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
547 |
|
75981 | 548 |
Meta_Data.init_directory(context.chapter_dir(session_name)) |
75982
2fff9ce6b460
more aggressive clean_directory(session_dir), while rm_tree is guarded by check_directory, i.e. it is presumably "owned" by Browser_Info.build_session();
wenzelm
parents:
75981
diff
changeset
|
549 |
Meta_Data.clean_directory(session_dir) |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
550 |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
551 |
val session = context.document_info.the_session(session_name) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
552 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
553 |
Bytes.write(session_dir + session_graph_path, |
75902 | 554 |
graphview.Graph_File.make_pdf(session_info.options, |
555 |
session_context.session_base.session_graph_display)) |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
556 |
|
75925 | 557 |
val document_variants = |
72683 | 558 |
for { |
75902 | 559 |
doc <- session_info.document_variants |
75780
f49c4f160b84
clarified signature: find session_database within Session_Context.db_hierarchy;
wenzelm
parents:
75778
diff
changeset
|
560 |
db <- session_context.session_db() |
75902 | 561 |
document <- Document_Build.read_document(db, session_name, doc.name) |
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
562 |
} |
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
563 |
yield { |
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
564 |
val doc_path = session_dir + doc.path.pdf |
75926
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
565 |
if (Path.eq_case_insensitive(doc.path.pdf, session_graph_path)) { |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
566 |
error("Illegal document variant " + quote(doc.name) + |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
567 |
" (conflict with " + session_graph_path + ")") |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
568 |
} |
75902 | 569 |
if (verbose) progress.echo("Presenting document " + session_name + "/" + doc.name) |
570 |
if (session_info.document_echo) progress.echo("Document at " + doc_path) |
|
74732
015282fb3e31
clarified messages, depending on option "document_echo";
wenzelm
parents:
74731
diff
changeset
|
571 |
Bytes.write(doc_path, document.pdf) |
73022
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
572 |
doc |
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
573 |
} |
72673
8ff7a0e394f9
clarified PDF/HTML presentation, based on pdf blobs from session database (e.g. from earlier builds);
wenzelm
parents:
72670
diff
changeset
|
574 |
|
75925 | 575 |
val document_links = { |
576 |
val link1 = HTML.link(session_graph_path, HTML.text("theory dependencies")) |
|
577 |
val links2 = document_variants.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
|
578 |
Library.separate(HTML.break ::: HTML.nl, |
75925 | 579 |
(link1 :: links2).map(link => HTML.text("View ") ::: List(link))).flatten |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
580 |
} |
62971
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
581 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
582 |
def present_theory(theory_name: String): XML.Body = { |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
583 |
progress.expose_interrupt() |
73215 | 584 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
585 |
def err(): Nothing = |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
586 |
error("Missing document information for theory: " + quote(theory_name)) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
587 |
|
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
588 |
val command = Build_Job.read_theory(session_context.theory(theory_name)) getOrElse err() |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
589 |
val theory = context.theory_by_name(session_name, theory_name) getOrElse err() |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
590 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
591 |
if (verbose) progress.echo("Presenting theory " + quote(theory_name)) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
592 |
val snapshot = Document.State.init.snippet(command) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
593 |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
594 |
val thy_elements = theory.elements(context.elements) |
73215 | 595 |
|
75929
811092261546
proper node_dir within presentation_dir, not source file directory;
wenzelm
parents:
75928
diff
changeset
|
596 |
def node_context(file_name: String, node_dir: Path): Node_Context = |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
597 |
Node_Context.make(context, session_name, theory_name, file_name, node_dir) |
75928 | 598 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
599 |
val thy_html = |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
600 |
context.source( |
75929
811092261546
proper node_dir within presentation_dir, not source file directory;
wenzelm
parents:
75928
diff
changeset
|
601 |
node_context(theory.thy_file, session_dir). |
75928 | 602 |
make_html(thy_elements, snapshot.xml_markup(elements = thy_elements.html))) |
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
603 |
|
75931 | 604 |
val files = |
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
605 |
for { |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
606 |
(blob, xml) <- snapshot.xml_markup_blobs(elements = thy_elements.html) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
607 |
if xml.nonEmpty |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
608 |
} |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
609 |
yield { |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
610 |
progress.expose_interrupt() |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
611 |
|
75931 | 612 |
val file_name = blob.name.node |
613 |
if (verbose) progress.echo("Presenting file " + quote(file_name)) |
|
74715
129fb11b357f
use all entity kinds from theory export, e.g. "method", "attribute";
wenzelm
parents:
74714
diff
changeset
|
614 |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
615 |
val file_html = session_dir + context.file_html(file_name) |
75932 | 616 |
val file_dir = file_html.dir |
75933 | 617 |
val html_link = HTML.relative_href(file_html, base = Some(session_dir)) |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
618 |
val html = context.source(node_context(file_name, file_dir).make_html(thy_elements, xml)) |
75931 | 619 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
620 |
val file_title = "File " + Symbol.cartouche_decoded(blob.src_path.implode_short) |
75932 | 621 |
HTML.write_document(file_dir, file_html.file_name, |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
622 |
List(HTML.title(file_title)), List(context.head(file_title), html), |
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
623 |
root = Some(context.root_dir)) |
75931 | 624 |
List(HTML.link(html_link, HTML.text(file_title))) |
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
625 |
} |
73215 | 626 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
627 |
val thy_title = "Theory " + theory.print_short |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
628 |
HTML.write_document(session_dir, context.theory_html(theory).implode, |
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
629 |
List(HTML.title(thy_title)), List(context.head(thy_title), thy_html), |
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
630 |
root = Some(context.root_dir)) |
73215 | 631 |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
632 |
List(HTML.link(context.theory_html(theory), |
75925 | 633 |
HTML.text(theory.print_short) ::: |
634 |
(if (files.isEmpty) Nil else List(HTML.itemize(files))))) |
|
72989 | 635 |
} |
61500 | 636 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
637 |
val theories = session.used_theories.map(present_theory) |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
638 |
|
75902 | 639 |
val title = "Session " + session_name |
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
640 |
HTML.write_document(session_dir, "index.html", |
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
641 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
642 |
context.head(title, List(HTML.par(document_links))) :: |
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
643 |
context.contents("Theories", theories), |
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
644 |
root = Some(context.root_dir)) |
75961 | 645 |
|
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
646 |
Meta_Data.set_build_uuid(session_dir, session.build_uuid) |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
647 |
|
75980 | 648 |
context.update_chapter(session_name, session_info.description) |
61372 | 649 |
} |
75947 | 650 |
|
651 |
def build( |
|
652 |
browser_info: Config, |
|
653 |
store: Sessions.Store, |
|
654 |
deps: Sessions.Deps, |
|
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
655 |
sessions: List[String], |
75947 | 656 |
progress: Progress = new Progress, |
657 |
verbose: Boolean = false |
|
658 |
): Unit = { |
|
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
659 |
val root_dir = browser_info.presentation_dir(store).absolute |
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
660 |
progress.echo("Presentation in " + root_dir) |
75947 | 661 |
|
662 |
using(Export.open_database_context(store)) { database_context => |
|
75979 | 663 |
val context0 = context(deps.sessions_structure, root_dir = root_dir) |
75947 | 664 |
|
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
665 |
val sessions1 = |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
666 |
deps.sessions_structure.build_requirements(sessions).filter { session_name => |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
667 |
using(database_context.open_database(session_name)) { session_database => |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
668 |
database_context.store.read_build(session_database.db, session_name) match { |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
669 |
case None => false |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
670 |
case Some(build) => |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
671 |
val session_dir = context0.session_dir(session_name) |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
672 |
!Meta_Data.check_build_uuid(session_dir, build.uuid) |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
673 |
} |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
674 |
} |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
675 |
} |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
676 |
|
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
677 |
val context1 = |
75979 | 678 |
context(deps.sessions_structure, root_dir = root_dir, |
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
679 |
document_info = Document_Info.read(database_context, deps, sessions1)) |
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
680 |
|
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
681 |
context1.update_root() |
75952
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
682 |
|
864b10457a7d
more robust concurrency: use shared Browser_Info.Context with synchronized file-system operations;
wenzelm
parents:
75949
diff
changeset
|
683 |
Par_List.map({ (session: String) => |
75947 | 684 |
using(database_context.open_session(deps.base_info(session))) { session_context => |
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
685 |
build_session(context1, session_context, progress = progress, verbose = verbose) |
75947 | 686 |
} |
75971
cec22f403c25
more accurate management of dependencies: change of build_uuid causes output of HTML, but already existing/current HTML is not produced again;
wenzelm
parents:
75969
diff
changeset
|
687 |
}, sessions1) |
75947 | 688 |
} |
689 |
} |
|
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
690 |
} |