author | wenzelm |
Tue, 02 Aug 2022 19:25:37 +0200 | |
changeset 75738 | 9cc5ee625adb |
parent 75737 | 288c4d4042cc |
child 75746 | 3513fdfeb4d8 |
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 |
||
75393 | 15 |
object Presentation { |
72957 | 16 |
/** HTML documents **/ |
17 |
||
73718 | 18 |
/* HTML context */ |
19 |
||
72957 | 20 |
sealed case class HTML_Document(title: String, content: String) |
21 |
||
75393 | 22 |
abstract class HTML_Context { |
74818
3064e165c660
clarified HTML_Context.theory_exports: prefer value-oriented parallelism;
wenzelm
parents:
74816
diff
changeset
|
23 |
/* directory structure and resources */ |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
24 |
|
75728 | 25 |
def nodes: Nodes |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
26 |
def root_dir: Path |
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
27 |
def theory_session(name: Document.Node.Name): Sessions.Info |
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
28 |
|
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
29 |
def session_dir(info: Sessions.Info): Path = |
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
30 |
root_dir + Path.explode(info.chapter_session) |
75722 | 31 |
def theory_dir(name: Document.Node.Name): Path = |
32 |
session_dir(theory_session(name)) |
|
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
33 |
def files_path(name: Document.Node.Name, path: Path): Path = |
75722 | 34 |
theory_dir(name) + Path.explode("files") + path.squash.html |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
35 |
|
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
36 |
|
74769 | 37 |
/* HTML content */ |
38 |
||
72962 | 39 |
def head(title: String, rest: XML.Body = Nil): XML.Tree = |
40 |
HTML.div("head", HTML.chapter(title) :: rest) |
|
41 |
||
42 |
def source(body: XML.Body): XML.Tree = HTML.pre("source", body) |
|
43 |
||
75393 | 44 |
def contents( |
45 |
heading: String, |
|
46 |
items: List[XML.Body], |
|
47 |
css_class: String = "contents" |
|
48 |
) : List[XML.Elem] = { |
|
72962 | 49 |
if (items.isEmpty) Nil |
50 |
else List(HTML.div(css_class, List(HTML.section(heading), HTML.itemize(items)))) |
|
51 |
} |
|
52 |
||
74768 | 53 |
val isabelle_css: String = File.read(HTML.isabelle_css) |
54 |
||
75393 | 55 |
def html_document(title: String, body: XML.Body, fonts_css: String): HTML_Document = { |
74709 | 56 |
val content = |
57 |
HTML.output_document( |
|
58 |
List( |
|
74768 | 59 |
HTML.style(fonts_css + "\n\n" + isabelle_css), |
74709 | 60 |
HTML.title(title)), |
61 |
List(HTML.source(body)), css = "", structural = false) |
|
62 |
HTML_Document(title, content) |
|
63 |
} |
|
72959 | 64 |
} |
65 |
||
72957 | 66 |
|
73055 | 67 |
/* presentation elements */ |
68 |
||
69 |
sealed case class Elements( |
|
70 |
html: Markup.Elements = Markup.Elements.empty, |
|
73056 | 71 |
entity: Markup.Elements = Markup.Elements.empty, |
73055 | 72 |
language: Markup.Elements = Markup.Elements.empty) |
72957 | 73 |
|
73055 | 74 |
val elements1: Elements = |
75 |
Elements( |
|
74677 | 76 |
html = Rendering.foreground_elements ++ Rendering.text_color_elements + |
73056 | 77 |
Markup.NUMERAL + Markup.COMMENT + Markup.ENTITY + Markup.LANGUAGE, |
74718
925b46043b84
cover all possible kinds, notably for references outside of this theory (amending 129fb11b357f);
wenzelm
parents:
74717
diff
changeset
|
78 |
entity = Markup.Elements(Markup.THEORY, Markup.TYPE_NAME, Markup.CONSTANT, Markup.FACT, |
925b46043b84
cover all possible kinds, notably for references outside of this theory (amending 129fb11b357f);
wenzelm
parents:
74717
diff
changeset
|
79 |
Markup.CLASS, Markup.LOCALE, Markup.FREE)) |
73036 | 80 |
|
73055 | 81 |
val elements2: Elements = |
82 |
Elements( |
|
83 |
html = elements1.html ++ Rendering.markdown_elements, |
|
73056 | 84 |
language = Markup.Elements(Markup.Language.DOCUMENT)) |
73055 | 85 |
|
74678 | 86 |
|
75727 | 87 |
/* per-session node info */ |
75725 | 88 |
|
75727 | 89 |
object Node_Info { |
90 |
val empty: Node_Info = new Node_Info(Map.empty, Map.empty, Nil) |
|
91 |
def make(theory: Export_Theory.Theory): Node_Info = { |
|
75726 | 92 |
val by_range = theory.entity_iterator.toList.groupBy(_.range) |
93 |
val by_kind_name = |
|
94 |
theory.entity_iterator.map(entity => ((entity.kind, entity.name), entity)).toMap |
|
95 |
val others = theory.others.keySet.toList |
|
75727 | 96 |
new Node_Info(by_range, by_kind_name, others) |
75726 | 97 |
} |
75725 | 98 |
} |
75731 | 99 |
|
75727 | 100 |
class Node_Info private( |
75726 | 101 |
by_range: Map[Symbol.Range, List[Export_Theory.Entity0]], |
102 |
by_kind_name: Map[(String, String), Export_Theory.Entity0], |
|
103 |
val others: List[String]) { |
|
104 |
def for_range(range: Symbol.Range): List[Export_Theory.Entity0] = |
|
105 |
by_range.getOrElse(range, Nil) |
|
106 |
def get_kind_name(kind: String, name: String): Option[String] = |
|
107 |
by_kind_name.get((kind, name)).map(_.kname) |
|
108 |
} |
|
75725 | 109 |
|
75727 | 110 |
object Nodes { |
75730 | 111 |
val empty: Nodes = new Nodes(Map.empty) |
75731 | 112 |
|
75730 | 113 |
def read( |
75731 | 114 |
presentation_sessions: List[String], |
75730 | 115 |
deps: Sessions.Deps, |
116 |
db_context: Sessions.Database_Context |
|
117 |
): Nodes = { |
|
118 |
type Batch = (String, List[String]) |
|
119 |
val batches = |
|
75731 | 120 |
presentation_sessions.foldLeft((Set.empty[String], List.empty[Batch]))( |
75730 | 121 |
{ case ((seen, batches), session) => |
122 |
val thys = deps(session).loaded_theories.keys.filterNot(seen) |
|
123 |
(seen ++ thys, (session, thys) :: batches) |
|
124 |
})._2 |
|
125 |
val theory_node_info = |
|
126 |
Par_List.map[Batch, List[(String, Node_Info)]]( |
|
127 |
{ case (session, thys) => |
|
75738 | 128 |
db_context.database(session) { db => |
75736
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
129 |
val provider0 = Export.Provider.database(db, db_context.cache, session, "") |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
130 |
val result = |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
131 |
for (thy_name <- thys) yield { |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
132 |
val theory = |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
133 |
if (thy_name == Thy_Header.PURE) Export_Theory.no_theory |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
134 |
else { |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
135 |
val provider = provider0.focus(thy_name) |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
136 |
if (Export_Theory.read_theory_parents(provider, thy_name).isDefined) { |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
137 |
Export_Theory.read_theory(provider, session, thy_name, cache = db_context.cache) |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
138 |
} |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
139 |
else Export_Theory.no_theory |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
140 |
} |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
141 |
thy_name -> Node_Info.make(theory) |
75730 | 142 |
} |
75736
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
143 |
Some(result) |
6b319113b3a4
clarified signature: avoid repeated db_context.input_database;
wenzelm
parents:
75731
diff
changeset
|
144 |
} getOrElse Nil |
75730 | 145 |
}, batches).flatten.toMap |
146 |
new Nodes(theory_node_info) |
|
147 |
} |
|
75725 | 148 |
} |
75731 | 149 |
|
75729 | 150 |
class Nodes private(theory_node_info: Map[String, Node_Info]) { |
151 |
def apply(name: String): Node_Info = theory_node_info.getOrElse(name, Node_Info.empty) |
|
152 |
def get(name: String): Option[Node_Info] = theory_node_info.get(name) |
|
75725 | 153 |
} |
154 |
||
155 |
||
74678 | 156 |
/* formal entities */ |
74677 | 157 |
|
158 |
type Entity = Export_Theory.Entity[Export_Theory.No_Content] |
|
159 |
||
75393 | 160 |
object Entity_Context { |
161 |
object Theory_Ref { |
|
74765 | 162 |
def unapply(props: Properties.T): Option[Document.Node.Name] = |
163 |
(props, props, props) match { |
|
164 |
case (Markup.Kind(Markup.THEORY), Markup.Name(theory), Position.Def_File(thy_file)) => |
|
165 |
Some(Resources.file_node(Path.explode(thy_file), theory = theory)) |
|
166 |
case _ => None |
|
167 |
} |
|
168 |
} |
|
169 |
||
75393 | 170 |
object Entity_Ref { |
74766 | 171 |
def unapply(props: Properties.T): Option[(Path, Option[String], String, String)] = |
172 |
(props, props, props, props) match { |
|
74782 | 173 |
case (Markup.Entity.Ref.Prop(_), Position.Def_File(def_file), |
174 |
Markup.Kind(kind), Markup.Name(name)) => |
|
74766 | 175 |
val def_theory = Position.Def_Theory.unapply(props) |
74765 | 176 |
Some((Path.explode(def_file), def_theory, kind, name)) |
177 |
case _ => None |
|
178 |
} |
|
179 |
} |
|
180 |
||
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
181 |
val empty: Entity_Context = new Entity_Context |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
182 |
|
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
183 |
def make( |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
184 |
session: String, |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
185 |
deps: Sessions.Deps, |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
186 |
node: Document.Node.Name, |
74818
3064e165c660
clarified HTML_Context.theory_exports: prefer value-oriented parallelism;
wenzelm
parents:
74816
diff
changeset
|
187 |
html_context: HTML_Context): Entity_Context = |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
188 |
new Entity_Context { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
189 |
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
|
190 |
|
75393 | 191 |
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
|
192 |
body match { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
193 |
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
|
194 |
case _ => |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
195 |
Some { |
75727 | 196 |
val entities = html_context.nodes(node.theory).for_range(range) |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
197 |
val body1 = |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
198 |
if (seen_ranges.contains(range)) { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
199 |
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
|
200 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
201 |
else HTML.span(body) |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
202 |
entities.map(_.kname).foldLeft(body1) { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
203 |
case (elem, id) => HTML.entity_def(HTML.span(HTML.id(id), List(elem))) |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
204 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
205 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
206 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
207 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
208 |
|
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
209 |
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
|
210 |
"offset_" + range.start + ".." + range.stop |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
211 |
|
75393 | 212 |
private def physical_ref(thy_name: String, props: Properties.T): Option[String] = { |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
213 |
for { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
214 |
range <- Position.Def_Range.unapply(props) |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
215 |
if thy_name == node.theory |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
216 |
} yield { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
217 |
seen_ranges += range |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
218 |
offset_id(range) |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
219 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
220 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
221 |
|
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
222 |
private def logical_ref(thy_name: String, kind: String, name: String): Option[String] = |
75727 | 223 |
html_context.nodes.get(thy_name).flatMap(_.get_kind_name(kind, name)) |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
224 |
|
75393 | 225 |
override def make_ref(props: Properties.T, body: XML.Body): Option[XML.Elem] = { |
74765 | 226 |
props match { |
227 |
case Theory_Ref(node_name) => |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
228 |
node_relative(deps, session, node_name).map(html_dir => |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
229 |
HTML.link(html_dir + html_name(node_name), body)) |
74841
9ad3fa47c83e
avoid broken links: auxiliary files are not yet supported;
wenzelm
parents:
74828
diff
changeset
|
230 |
case Entity_Ref(file_path, def_theory, kind, name) if file_path.get_ext == "thy" => |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
231 |
for { |
74766 | 232 |
thy_name <- |
233 |
def_theory orElse (if (File.eq(node.path, file_path)) Some(node.theory) else None) |
|
74755
510296c0d8d1
clarified signature: avoid potential misunderstanding of Resources.empty as proper Resources;
wenzelm
parents:
74753
diff
changeset
|
234 |
node_name = Resources.file_node(file_path, theory = thy_name) |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
235 |
html_dir <- node_relative(deps, session, node_name) |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
236 |
html_file = node_file(node_name) |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
237 |
html_ref <- |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
238 |
logical_ref(thy_name, kind, name) orElse physical_ref(thy_name, props) |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
239 |
} yield { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
240 |
HTML.entity_ref(HTML.link(html_dir + html_file + "#" + html_ref, body)) |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
241 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
242 |
case _ => None |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
243 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
244 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
245 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
246 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
247 |
|
75393 | 248 |
class Entity_Context { |
74753 | 249 |
def make_def(range: Symbol.Range, body: XML.Body): Option[XML.Elem] = None |
250 |
def make_ref(props: Properties.T, body: XML.Body): Option[XML.Elem] = None |
|
74677 | 251 |
} |
73055 | 252 |
|
74678 | 253 |
|
73718 | 254 |
/* HTML output */ |
73036 | 255 |
|
72957 | 256 |
private val div_elements = |
75379 | 257 |
Set(HTML.div.name, HTML.pre.name, HTML.par.name, HTML.list.name, HTML.`enum`.name, |
72957 | 258 |
HTML.descr.name) |
259 |
||
73056 | 260 |
def make_html( |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
261 |
entity_context: Entity_Context, |
73056 | 262 |
elements: Elements, |
75393 | 263 |
xml: XML.Body |
264 |
): XML.Body = { |
|
73054 | 265 |
def html_div(html: XML.Body): Boolean = |
266 |
html exists { |
|
267 |
case XML.Elem(markup, body) => div_elements.contains(markup.name) || html_div(body) |
|
268 |
case XML.Text(_) => false |
|
269 |
} |
|
72957 | 270 |
|
73055 | 271 |
def html_class(c: String, html: XML.Body): XML.Body = |
272 |
if (c == "") html |
|
273 |
else if (html_div(html)) List(HTML.div(c, html)) |
|
274 |
else List(HTML.span(c, html)) |
|
72957 | 275 |
|
74677 | 276 |
def html_body(xml_body: XML.Body, end_offset: Symbol.Offset): (XML.Body, Symbol.Offset) = |
277 |
xml_body.foldRight((List.empty[XML.Tree], end_offset)) { case (tree, (res, end_offset1)) => |
|
278 |
val (res1, offset) = html_body_single(tree, end_offset1) |
|
279 |
(res1 ++ res, offset) |
|
280 |
} |
|
281 |
||
282 |
@tailrec |
|
283 |
def html_body_single(xml_tree: XML.Tree, end_offset: Symbol.Offset): (XML.Body, Symbol.Offset) = |
|
284 |
xml_tree match { |
|
285 |
case XML.Wrapped_Elem(markup, _, body) => html_body_single(XML.Elem(markup, body), end_offset) |
|
73056 | 286 |
case XML.Elem(Markup(Markup.ENTITY, props @ Markup.Kind(kind)), body) => |
74677 | 287 |
val (body1, offset) = html_body(body, end_offset) |
73056 | 288 |
if (elements.entity(kind)) { |
74753 | 289 |
entity_context.make_ref(props, body1) match { |
74677 | 290 |
case Some(link) => (List(link), offset) |
291 |
case None => (body1, offset) |
|
73056 | 292 |
} |
293 |
} |
|
74677 | 294 |
else (body1, offset) |
73055 | 295 |
case XML.Elem(Markup(Markup.LANGUAGE, Markup.Name(name)), body) => |
74677 | 296 |
val (body1, offset) = html_body(body, end_offset) |
297 |
(html_class(if (elements.language(name)) name else "", body1), offset) |
|
73055 | 298 |
case XML.Elem(Markup(Markup.MARKDOWN_PARAGRAPH, _), body) => |
74677 | 299 |
val (body1, offset) = html_body(body, end_offset) |
300 |
(List(HTML.par(body1)), offset) |
|
73055 | 301 |
case XML.Elem(Markup(Markup.MARKDOWN_ITEM, _), body) => |
74677 | 302 |
val (body1, offset) = html_body(body, end_offset) |
303 |
(List(HTML.item(body1)), offset) |
|
304 |
case XML.Elem(Markup(Markup.Markdown_Bullet.name, _), text) => |
|
74683
c8327efc7af1
clarified signature: more direct XML.symbol_length;
wenzelm
parents:
74682
diff
changeset
|
305 |
(Nil, end_offset - XML.symbol_length(text)) |
73054 | 306 |
case XML.Elem(Markup.Markdown_List(kind), body) => |
74677 | 307 |
val (body1, offset) = html_body(body, end_offset) |
75379 | 308 |
if (kind == Markup.ENUMERATE) (List(HTML.`enum`(body1)), offset) |
74677 | 309 |
else (List(HTML.list(body1)), offset) |
73054 | 310 |
case XML.Elem(markup, body) => |
311 |
val name = markup.name |
|
74677 | 312 |
val (body1, offset) = html_body(body, end_offset) |
73054 | 313 |
val html = |
314 |
markup.properties match { |
|
315 |
case Markup.Kind(kind) if kind == Markup.COMMAND || kind == Markup.KEYWORD => |
|
74677 | 316 |
html_class(kind, body1) |
73054 | 317 |
case _ => |
74677 | 318 |
body1 |
73054 | 319 |
} |
320 |
Rendering.foreground.get(name) orElse Rendering.text_color.get(name) match { |
|
74677 | 321 |
case Some(c) => (html_class(c.toString, html), offset) |
322 |
case None => (html_class(name, html), offset) |
|
72957 | 323 |
} |
73054 | 324 |
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
|
325 |
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
|
326 |
val body = HTML.text(Symbol.decode(text)) |
74753 | 327 |
entity_context.make_def(Text.Range(offset, end_offset), body) match { |
74677 | 328 |
case Some(body1) => (List(body1), offset) |
329 |
case None => (body, offset) |
|
330 |
} |
|
73054 | 331 |
} |
332 |
||
74683
c8327efc7af1
clarified signature: more direct XML.symbol_length;
wenzelm
parents:
74682
diff
changeset
|
333 |
html_body(xml, XML.symbol_length(xml) + 1)._1 |
73054 | 334 |
} |
72957 | 335 |
|
336 |
||
337 |
/* PIDE HTML document */ |
|
338 |
||
339 |
def html_document( |
|
340 |
snapshot: Document.Snapshot, |
|
72962 | 341 |
html_context: HTML_Context, |
73055 | 342 |
elements: Elements, |
74709 | 343 |
plain_text: Boolean = false, |
75393 | 344 |
fonts_css: String = HTML.fonts_css() |
345 |
): HTML_Document = { |
|
73120
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
wenzelm
parents:
73059
diff
changeset
|
346 |
require(!snapshot.is_outdated, "document snapshot outdated") |
72957 | 347 |
|
348 |
val name = snapshot.node_name |
|
349 |
if (plain_text) { |
|
72962 | 350 |
val title = "File " + Symbol.cartouche_decoded(name.path.file_name) |
72959 | 351 |
val body = HTML.text(snapshot.node.source) |
74709 | 352 |
html_context.html_document(title, body, fonts_css) |
72957 | 353 |
} |
354 |
else { |
|
74756 | 355 |
Resources.html_document(snapshot) getOrElse { |
72962 | 356 |
val title = |
357 |
if (name.is_theory) "Theory " + quote(name.theory_base_name) |
|
358 |
else "File " + Symbol.cartouche_decoded(name.path.file_name) |
|
74677 | 359 |
val xml = snapshot.xml_markup(elements = elements.html) |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
360 |
val body = make_html(Entity_Context.empty, elements, xml) |
74709 | 361 |
html_context.html_document(title, body, fonts_css) |
72957 | 362 |
} |
363 |
} |
|
364 |
} |
|
365 |
||
366 |
||
367 |
||
73718 | 368 |
/** HTML presentation **/ |
72649 | 369 |
|
72648 | 370 |
/* presentation context */ |
371 |
||
75393 | 372 |
object Context { |
72648 | 373 |
val none: Context = new Context { def enabled: Boolean = false } |
374 |
val standard: Context = new Context { def enabled: Boolean = true } |
|
375 |
||
376 |
def dir(path: Path): Context = |
|
377 |
new Context { |
|
378 |
def enabled: Boolean = true |
|
379 |
override def dir(store: Sessions.Store): Path = path |
|
380 |
} |
|
381 |
||
382 |
def make(s: String): Context = |
|
383 |
if (s == ":") standard else dir(Path.explode(s)) |
|
384 |
} |
|
385 |
||
75393 | 386 |
abstract class Context private { |
72648 | 387 |
def enabled: Boolean |
388 |
def enabled(info: Sessions.Info): Boolean = enabled || info.browser_info |
|
389 |
def dir(store: Sessions.Store): Path = store.presentation_dir |
|
390 |
def dir(store: Sessions.Store, info: Sessions.Info): Path = |
|
72670 | 391 |
dir(store) + Path.explode(info.chapter_session) |
72648 | 392 |
} |
393 |
||
394 |
||
72955
942bf91545fa
clarified comments: file-system access is always unsynchronized;
wenzelm
parents:
72882
diff
changeset
|
395 |
/* maintain chapter index */ |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
396 |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
397 |
private val sessions_path = Path.basic(".sessions") |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
398 |
|
75393 | 399 |
private def read_sessions(dir: Path): List[(String, String)] = { |
51416 | 400 |
val path = dir + sessions_path |
401 |
if (path.is_file) { |
|
402 |
import XML.Decode._ |
|
65344
b99283eed13c
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65089
diff
changeset
|
403 |
list(pair(string, string))(Symbol.decode_yxml(File.read(path))) |
51416 | 404 |
} |
405 |
else Nil |
|
51402 | 406 |
} |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
407 |
|
74709 | 408 |
def update_chapter( |
75393 | 409 |
presentation_dir: Path, |
410 |
chapter: String, |
|
411 |
new_sessions: List[(String, String)] |
|
412 |
): Unit = { |
|
74699 | 413 |
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
|
414 |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
415 |
val sessions0 = |
51406
950b897f95bb
proper path -- I/O was hidden due to permissiveness;
wenzelm
parents:
51402
diff
changeset
|
416 |
try { read_sessions(dir) } |
51987 | 417 |
catch { case _: XML.Error => Nil } |
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
418 |
|
51402 | 419 |
val sessions = (SortedMap.empty[String, String] ++ sessions0 ++ new_sessions).toList |
74699 | 420 |
File.write(dir + sessions_path, |
421 |
{ |
|
422 |
import XML.Encode._ |
|
423 |
YXML.string_of_body(list(pair(string, string))(sessions)) |
|
424 |
}) |
|
51402 | 425 |
|
65988 | 426 |
val title = "Isabelle/" + chapter + " sessions" |
427 |
HTML.write_document(dir, "index.html", |
|
73523
2cd23d587db9
further clarification of Isabelle distribution identification -- avoid odd patching of sources;
wenzelm
parents:
73474
diff
changeset
|
428 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
65988 | 429 |
HTML.chapter(title) :: |
430 |
(if (sessions.isEmpty) Nil |
|
431 |
else |
|
65992 | 432 |
List(HTML.div("sessions", |
433 |
List(HTML.description( |
|
65988 | 434 |
sessions.map({ case (name, description) => |
69318 | 435 |
val descr = Symbol.trim_blank_lines(description) |
65989 | 436 |
(List(HTML.link(name + "/index.html", HTML.text(name))), |
69318 | 437 |
if (descr == "") Nil |
74709 | 438 |
else HTML.break ::: List(HTML.pre(HTML.text(descr)))) })))))), |
439 |
base = Some(presentation_dir)) |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
440 |
} |
61372 | 441 |
|
75393 | 442 |
def update_root(presentation_dir: Path): Unit = { |
74700
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
443 |
Isabelle_System.make_directory(presentation_dir) |
74709 | 444 |
HTML.init_fonts(presentation_dir) |
74700
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
445 |
Isabelle_System.copy_file(Path.explode("~~/lib/logo/isabelle.gif"), |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
446 |
presentation_dir + Path.explode("isabelle.gif")) |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
447 |
val title = "The " + XML.text(Isabelle_System.isabelle_name()) + " Library" |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
448 |
File.write(presentation_dir + Path.explode("index.html"), |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
449 |
HTML.header + |
73529 | 450 |
""" |
73528
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
451 |
<head> |
73529 | 452 |
""" + HTML.head_meta + """ |
73528
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
453 |
<title>""" + title + """</title> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
454 |
</head> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
455 |
|
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
456 |
<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
|
457 |
<center> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
458 |
<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
|
459 |
<tr> |
74676 | 460 |
<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
|
461 |
|
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
462 |
<td width="80%" valign="middle" align="center"> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
463 |
<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
|
464 |
<tr> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
465 |
<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
|
466 |
</tr> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
467 |
</table> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
468 |
</td> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
469 |
</tr> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
470 |
</table> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
471 |
</center> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
472 |
<hr /> |
74670
b2604cd4d131
recover library_index_content.template from c337c798f64c: required for website/build/main;
wenzelm
parents:
73718
diff
changeset
|
473 |
""" + 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
|
474 |
""" |
73528
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
475 |
</body> |
73529 | 476 |
""" + HTML.footer) |
61372 | 477 |
} |
478 |
||
479 |
||
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
480 |
/* present session */ |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
481 |
|
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
482 |
val session_graph_path = Path.explode("session_graph.pdf") |
72959 | 483 |
val readme_path = Path.explode("README.html") |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
484 |
|
74677 | 485 |
def html_name(name: Document.Node.Name): String = Path.explode(name.theory_base_name).html.implode |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
486 |
def files_path(src_path: Path): String = (Path.explode("files") + src_path.squash.html).implode |
74677 | 487 |
|
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
488 |
private def node_file(name: Document.Node.Name): String = |
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
489 |
if (name.node.endsWith(".thy")) html_name(name) else files_path(name.path) |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
490 |
|
75393 | 491 |
private def session_relative( |
492 |
deps: Sessions.Deps, |
|
493 |
session0: String, |
|
494 |
session1: String |
|
495 |
): Option[String] = { |
|
74677 | 496 |
for { |
497 |
info0 <- deps.sessions_structure.get(session0) |
|
498 |
info1 <- deps.sessions_structure.get(session1) |
|
499 |
} yield info0.relative_path(info1) |
|
500 |
} |
|
501 |
||
502 |
def node_relative( |
|
503 |
deps: Sessions.Deps, |
|
504 |
session0: String, |
|
75393 | 505 |
node_name: Document.Node.Name |
506 |
): Option[String] = { |
|
74677 | 507 |
val session1 = deps(session0).theory_qualifier(node_name) |
508 |
session_relative(deps, session0, session1) |
|
509 |
} |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
510 |
|
72648 | 511 |
def session_html( |
512 |
session: String, |
|
513 |
deps: Sessions.Deps, |
|
72683 | 514 |
db_context: Sessions.Database_Context, |
72992 | 515 |
progress: Progress = new Progress, |
73022
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
516 |
verbose: Boolean = false, |
72962 | 517 |
html_context: HTML_Context, |
75393 | 518 |
session_elements: Elements |
519 |
): Unit = { |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
520 |
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
|
521 |
val options = info.options |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
522 |
val base = deps(session) |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
523 |
|
75721 | 524 |
val session_hierarchy = deps.sessions_structure.build_hierarchy(session) |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
525 |
val session_dir = Isabelle_System.make_directory(html_context.session_dir(info)) |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
526 |
|
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
527 |
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
|
528 |
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
|
529 |
|
72673
8ff7a0e394f9
clarified PDF/HTML presentation, based on pdf blobs from session database (e.g. from earlier builds);
wenzelm
parents:
72670
diff
changeset
|
530 |
val documents = |
72683 | 531 |
for { |
532 |
doc <- info.document_variants |
|
75738 | 533 |
document <- db_context.database(session)(db => |
75737 | 534 |
Document_Build.read_document(db, session, doc.name)) |
73022
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
535 |
} yield { |
74732
015282fb3e31
clarified messages, depending on option "document_echo";
wenzelm
parents:
74731
diff
changeset
|
536 |
val doc_path = (session_dir + doc.path.pdf).expand |
73022
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
537 |
if (verbose) progress.echo("Presenting document " + session + "/" + doc.name) |
74732
015282fb3e31
clarified messages, depending on option "document_echo";
wenzelm
parents:
74731
diff
changeset
|
538 |
if (options.bool("document_echo")) progress.echo("Document at " + doc_path) |
015282fb3e31
clarified messages, depending on option "document_echo";
wenzelm
parents:
74731
diff
changeset
|
539 |
Bytes.write(doc_path, document.pdf) |
73022
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
540 |
doc |
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
541 |
} |
72673
8ff7a0e394f9
clarified PDF/HTML presentation, based on pdf blobs from session database (e.g. from earlier builds);
wenzelm
parents:
72670
diff
changeset
|
542 |
|
75393 | 543 |
val view_links = { |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
544 |
val deps_link = |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
545 |
HTML.link(session_graph_path, HTML.text("theory dependencies")) |
61372 | 546 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
547 |
val readme_links = |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
548 |
if ((info.dir + readme_path).is_file) { |
73317 | 549 |
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
|
550 |
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
|
551 |
} |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
552 |
else Nil |
62971
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
553 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
554 |
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
|
555 |
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
|
556 |
|
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
557 |
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
|
558 |
(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
|
559 |
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
|
560 |
} |
62971
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
561 |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
562 |
def entity_context(name: Document.Node.Name): Entity_Context = |
74818
3064e165c660
clarified HTML_Context.theory_exports: prefer value-oriented parallelism;
wenzelm
parents:
74816
diff
changeset
|
563 |
Entity_Context.make(session, deps, name, html_context) |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
564 |
|
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
565 |
|
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
566 |
sealed case class Seen_File( |
75393 | 567 |
src_path: Path, |
568 |
thy_name: Document.Node.Name, |
|
569 |
thy_session: String |
|
570 |
) { |
|
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
571 |
val files_path: Path = html_context.files_path(thy_name, src_path) |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
572 |
|
75393 | 573 |
def check(src_path1: Path, thy_name1: Document.Node.Name, thy_session1: String): Boolean = { |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
574 |
val files_path1 = html_context.files_path(thy_name1, src_path1) |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
575 |
(src_path == src_path1 || files_path == files_path1) && thy_session == thy_session1 |
74710
2057c02d7795
present theories from imported sessions as required;
wenzelm
parents:
74709
diff
changeset
|
576 |
} |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
577 |
} |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
578 |
var seen_files = List.empty[Seen_File] |
73056 | 579 |
|
75393 | 580 |
def present_theory(name: Document.Node.Name): Option[XML.Body] = { |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
581 |
progress.expose_interrupt() |
73215 | 582 |
|
75721 | 583 |
Build_Job.read_theory(db_context, session_hierarchy, name.theory).flatMap { command => |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
584 |
if (verbose) progress.echo("Presenting theory " + name) |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
585 |
val snapshot = Document.State.init.snippet(command) |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
586 |
|
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
587 |
val thy_elements = |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
588 |
session_elements.copy(entity = |
75727 | 589 |
html_context.nodes(name.theory).others.foldLeft(session_elements.entity)(_ + _)) |
73215 | 590 |
|
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
591 |
val files_html = |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
592 |
for { |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
593 |
(src_path, xml) <- snapshot.xml_markup_blobs(elements = thy_elements.html) |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
594 |
if xml.nonEmpty |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
595 |
} |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
596 |
yield { |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
597 |
progress.expose_interrupt() |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
598 |
if (verbose) progress.echo("Presenting file " + src_path) |
73214 | 599 |
|
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
600 |
(src_path, html_context.source( |
74841
9ad3fa47c83e
avoid broken links: auxiliary files are not yet supported;
wenzelm
parents:
74828
diff
changeset
|
601 |
make_html(Entity_Context.empty, thy_elements, xml))) |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
602 |
} |
74715
129fb11b357f
use all entity kinds from theory export, e.g. "method", "attribute";
wenzelm
parents:
74714
diff
changeset
|
603 |
|
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
604 |
val thy_html = |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
605 |
html_context.source( |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
606 |
make_html(entity_context(name), thy_elements, |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
607 |
snapshot.xml_markup(elements = thy_elements.html))) |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
608 |
|
75723 | 609 |
val thy_session = html_context.theory_session(name).name |
75722 | 610 |
val thy_dir = Isabelle_System.make_directory(html_context.theory_dir(name)) |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
611 |
val files = |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
612 |
for { (src_path, file_html) <- files_html } |
73215 | 613 |
yield { |
75723 | 614 |
seen_files.find(_.check(src_path, name, thy_session)) match { |
615 |
case None => seen_files ::= Seen_File(src_path, name, thy_session) |
|
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
616 |
case Some(seen_file) => |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
617 |
error("Incoherent use of file name " + src_path + " as " + files_path(src_path) + |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
618 |
" in theory " + seen_file.thy_name + " vs. " + name) |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
619 |
} |
73216 | 620 |
|
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
621 |
val file_path = html_context.files_path(name, src_path) |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
622 |
val file_title = "File " + Symbol.cartouche_decoded(src_path.implode_short) |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
623 |
HTML.write_document(file_path.dir, file_path.file_name, |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
624 |
List(HTML.title(file_title)), List(html_context.head(file_title), file_html), |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
625 |
base = Some(html_context.root_dir)) |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
626 |
|
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
627 |
List(HTML.link(files_path(src_path), HTML.text(file_title))) |
73215 | 628 |
} |
629 |
||
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
630 |
val thy_title = "Theory " + name.theory_base_name |
73215 | 631 |
|
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
632 |
HTML.write_document(thy_dir, html_name(name), |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
633 |
List(HTML.title(thy_title)), List(html_context.head(thy_title), thy_html), |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
634 |
base = Some(html_context.root_dir)) |
73215 | 635 |
|
75723 | 636 |
if (thy_session == session) { |
74710
2057c02d7795
present theories from imported sessions as required;
wenzelm
parents:
74709
diff
changeset
|
637 |
Some( |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
638 |
List(HTML.link(html_name(name), |
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
639 |
HTML.text(name.theory_base_name) ::: |
74710
2057c02d7795
present theories from imported sessions as required;
wenzelm
parents:
74709
diff
changeset
|
640 |
(if (files.isEmpty) Nil else List(HTML.itemize(files)))))) |
2057c02d7795
present theories from imported sessions as required;
wenzelm
parents:
74709
diff
changeset
|
641 |
} |
2057c02d7795
present theories from imported sessions as required;
wenzelm
parents:
74709
diff
changeset
|
642 |
else None |
75394 | 643 |
} |
72989 | 644 |
} |
61500 | 645 |
|
74813
2ad892ac749a
present only selected session theories (as in Isabelle2021), in contrast to 2bc24136bdeb, eb89b3a37826;
wenzelm
parents:
74809
diff
changeset
|
646 |
val theories = base.session_theories.flatMap(present_theory) |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
647 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
648 |
val title = "Session " + session |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
649 |
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
|
650 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
73041 | 651 |
html_context.head(title, List(HTML.par(view_links))) :: |
74709 | 652 |
html_context.contents("Theories", theories), |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
653 |
base = Some(html_context.root_dir)) |
61372 | 654 |
} |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
655 |
} |