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