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