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