author | wenzelm |
Sat, 20 Aug 2022 16:32:18 +0200 | |
changeset 75926 | b8ee1ef948c2 |
parent 75925 | 8fb3b3a10667 |
child 75927 | 040a59abe196 |
permissions | -rw-r--r-- |
73718 | 1 |
/* Title: Pure/Thy/presentation.scala |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
3 |
|
73718 | 4 |
HTML presentation of PIDE document content. |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
6 |
|
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
8 |
|
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
9 |
|
74677 | 10 |
import scala.annotation.tailrec |
51402 | 11 |
import scala.collection.immutable.SortedMap |
74677 | 12 |
import scala.collection.mutable |
51402 | 13 |
|
14 |
||
75393 | 15 |
object Presentation { |
72957 | 16 |
/** HTML documents **/ |
17 |
||
73718 | 18 |
/* HTML context */ |
19 |
||
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
20 |
def html_context( |
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
21 |
sessions_structure: Sessions.Structure, |
75897 | 22 |
elements: Elements, |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
23 |
root_dir: Path = Path.current, |
75907 | 24 |
document_info: Document_Info = Document_Info.empty |
25 |
): HTML_Context = new HTML_Context(sessions_structure, elements, root_dir, document_info) |
|
72957 | 26 |
|
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
27 |
class HTML_Context private[Presentation]( |
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
28 |
sessions_structure: Sessions.Structure, |
75897 | 29 |
val elements: Elements, |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
30 |
val root_dir: Path, |
75907 | 31 |
val document_info: Document_Info |
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
32 |
) { |
74818
3064e165c660
clarified HTML_Context.theory_exports: prefer value-oriented parallelism;
wenzelm
parents:
74816
diff
changeset
|
33 |
/* directory structure and resources */ |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
34 |
|
75907 | 35 |
def theory_by_name(session: String, theory: String): Option[Document_Info.Theory] = |
36 |
document_info.theory_by_name(session, theory) |
|
75894 | 37 |
|
75907 | 38 |
def theory_by_file(session: String, file: String): Option[Document_Info.Theory] = |
39 |
document_info.theory_by_file(session, file) |
|
75897 | 40 |
|
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
41 |
def session_dir(session: String): Path = |
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
42 |
root_dir + Path.explode(sessions_structure(session).chapter_session) |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
43 |
|
75907 | 44 |
def theory_html(theory: Document_Info.Theory): Path = |
75917
20b918404aa3
evade clash with index.html (allow "Index.thy" even on case-insensitive file-systems);
wenzelm
parents:
75916
diff
changeset
|
45 |
{ |
75926
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
46 |
def check(name: String): Option[Path] = { |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
47 |
val path = Path.explode(name).html |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
48 |
if (Path.eq_case_insensitive(path, Path.index_html)) None |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
49 |
else Some(path) |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
50 |
} |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
51 |
check(theory.print_short) orElse check(theory.name) getOrElse |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
52 |
error("Illegal global theory name " + quote(theory.name) + |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
53 |
" (conflict with " + Path.index_html + ")") |
75917
20b918404aa3
evade clash with index.html (allow "Index.thy" even on case-insensitive file-systems);
wenzelm
parents:
75916
diff
changeset
|
54 |
} |
75900 | 55 |
|
75915
95d7459e5bc0
clarified directory layout (again): mimic original directory layout, notably ISABELLE_HOME;
wenzelm
parents:
75914
diff
changeset
|
56 |
def file_html(file: String): Path = |
95d7459e5bc0
clarified directory layout (again): mimic original directory layout, notably ISABELLE_HOME;
wenzelm
parents:
75914
diff
changeset
|
57 |
Path.explode(file).squash.html |
75900 | 58 |
|
75914
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75913
diff
changeset
|
59 |
def smart_html(theory: Document_Info.Theory, file: String): Path = |
75915
95d7459e5bc0
clarified directory layout (again): mimic original directory layout, notably ISABELLE_HOME;
wenzelm
parents:
75914
diff
changeset
|
60 |
if (File.is_thy(file)) theory_html(theory) else file_html(file) |
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
61 |
|
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
62 |
def relative_link(dir: Path, file: Path): String = |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
63 |
try { File.path(dir.java_path.relativize(file.java_path).toFile).implode } |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
64 |
catch { |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
65 |
case _: IllegalArgumentException => |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
66 |
error("Cannot relativize " + file + " wrt. " + dir) |
75890 | 67 |
} |
75887
e5c0116a5c9f
clarified signature: replaced Sessions.Deps by Sessions.Structure from HTML_Context;
wenzelm
parents:
75886
diff
changeset
|
68 |
|
74770
32c2587cda4f
clarified HTML_Context: more explicit directory structure;
wenzelm
parents:
74769
diff
changeset
|
69 |
|
74769 | 70 |
/* HTML content */ |
71 |
||
72962 | 72 |
def head(title: String, rest: XML.Body = Nil): XML.Tree = |
73 |
HTML.div("head", HTML.chapter(title) :: rest) |
|
74 |
||
75 |
def source(body: XML.Body): XML.Tree = HTML.pre("source", body) |
|
76 |
||
75393 | 77 |
def contents( |
78 |
heading: String, |
|
79 |
items: List[XML.Body], |
|
80 |
css_class: String = "contents" |
|
81 |
) : List[XML.Elem] = { |
|
72962 | 82 |
if (items.isEmpty) Nil |
83 |
else List(HTML.div(css_class, List(HTML.section(heading), HTML.itemize(items)))) |
|
84 |
} |
|
85 |
||
74768 | 86 |
val isabelle_css: String = File.read(HTML.isabelle_css) |
87 |
||
75393 | 88 |
def html_document(title: String, body: XML.Body, fonts_css: String): HTML_Document = { |
74709 | 89 |
val content = |
90 |
HTML.output_document( |
|
91 |
List( |
|
74768 | 92 |
HTML.style(fonts_css + "\n\n" + isabelle_css), |
74709 | 93 |
HTML.title(title)), |
94 |
List(HTML.source(body)), css = "", structural = false) |
|
95 |
HTML_Document(title, content) |
|
96 |
} |
|
72959 | 97 |
} |
98 |
||
75884
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
99 |
sealed case class HTML_Document(title: String, content: String) |
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
wenzelm
parents:
75792
diff
changeset
|
100 |
|
72957 | 101 |
|
73055 | 102 |
/* presentation elements */ |
103 |
||
104 |
sealed case class Elements( |
|
105 |
html: Markup.Elements = Markup.Elements.empty, |
|
73056 | 106 |
entity: Markup.Elements = Markup.Elements.empty, |
73055 | 107 |
language: Markup.Elements = Markup.Elements.empty) |
72957 | 108 |
|
73055 | 109 |
val elements1: Elements = |
110 |
Elements( |
|
74677 | 111 |
html = Rendering.foreground_elements ++ Rendering.text_color_elements + |
73056 | 112 |
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
|
113 |
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
|
114 |
Markup.CLASS, Markup.LOCALE, Markup.FREE)) |
73036 | 115 |
|
73055 | 116 |
val elements2: Elements = |
117 |
Elements( |
|
118 |
html = elements1.html ++ Rendering.markdown_elements, |
|
73056 | 119 |
language = Markup.Elements(Markup.Language.DOCUMENT)) |
73055 | 120 |
|
74678 | 121 |
|
122 |
/* formal entities */ |
|
74677 | 123 |
|
75891 | 124 |
object Theory_Ref { |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
125 |
def unapply(props: Properties.T): Option[String] = |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
126 |
(props, props) match { |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
127 |
case (Markup.Kind(Markup.THEORY), Markup.Name(theory)) => Some(theory) |
75891 | 128 |
case _ => None |
129 |
} |
|
130 |
} |
|
74765 | 131 |
|
75891 | 132 |
object Entity_Ref { |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
133 |
def unapply(props: Properties.T): Option[(String, String, String)] = |
75891 | 134 |
(props, props, props, props) match { |
75913 | 135 |
case (Markup.Entity.Ref.Prop(_), Position.Def_File(file), Markup.Kind(kind), Markup.Name(name)) |
136 |
if Path.is_wellformed(file) => Some((file, kind, name)) |
|
75891 | 137 |
case _ => None |
138 |
} |
|
139 |
} |
|
74765 | 140 |
|
75891 | 141 |
object Entity_Context { |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
142 |
val empty: Entity_Context = new Entity_Context |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
143 |
|
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
144 |
def make( |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
145 |
html_context: HTML_Context, |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
146 |
session_name: String, |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
147 |
theory_name: String, |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
148 |
file_name: String |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
149 |
): Entity_Context = |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
150 |
new Entity_Context { |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
151 |
private val session_dir = html_context.session_dir(session_name) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
152 |
private val file_dir = Path.explode(file_name).dir |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
153 |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
154 |
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
|
155 |
|
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
156 |
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
|
157 |
body match { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
158 |
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
|
159 |
case _ => |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
160 |
for (theory <- html_context.theory_by_name(session_name, theory_name)) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
161 |
yield { |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
162 |
val body1 = |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
163 |
if (seen_ranges.contains(range)) { |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
164 |
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
|
165 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
166 |
else HTML.span(body) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
167 |
theory.get_defs(file_name, range).foldLeft(body1) { |
75896 | 168 |
case (elem, entity) => |
169 |
HTML.entity_def(HTML.span(HTML.id(entity.kname), List(elem))) |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
170 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
171 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
172 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
173 |
|
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
174 |
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
|
175 |
"offset_" + range.start + ".." + range.stop |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
176 |
|
75393 | 177 |
override def make_ref(props: Properties.T, body: XML.Body): Option[XML.Elem] = { |
74765 | 178 |
props match { |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
179 |
case Theory_Ref(thy_name) => |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
180 |
for (theory <- html_context.theory_by_name(session_name, thy_name)) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
181 |
yield { |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
182 |
val html_path = session_dir + html_context.theory_html(theory) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
183 |
val html_link = html_context.relative_link(file_dir, html_path) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
184 |
HTML.link(html_link, body) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
185 |
} |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
186 |
case Entity_Ref(def_file, kind, name) => |
75907 | 187 |
def logical_ref(theory: Document_Info.Theory): Option[String] = |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
188 |
theory.get_def(def_file, kind, name).map(_.kname) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
189 |
|
75907 | 190 |
def physical_ref(theory: Document_Info.Theory): Option[String] = |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
191 |
props match { |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
192 |
case Position.Def_Range(range) if theory.name == theory_name => |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
193 |
seen_ranges += range |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
194 |
Some(offset_id(range)) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
195 |
case _ => None |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
196 |
} |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
197 |
|
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
198 |
for { |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
199 |
theory <- html_context.theory_by_file(session_name, def_file) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
200 |
html_ref <- logical_ref(theory) orElse physical_ref(theory) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
201 |
} |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
202 |
yield { |
75914
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75913
diff
changeset
|
203 |
val html_path = session_dir + html_context.smart_html(theory, def_file) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
204 |
val html_link = html_context.relative_link(file_dir, html_path) |
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
205 |
HTML.entity_ref(HTML.link(html_link + "#" + html_ref, body)) |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
206 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
207 |
case _ => None |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
208 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
209 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
210 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
211 |
} |
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
212 |
|
75393 | 213 |
class Entity_Context { |
74753 | 214 |
def make_def(range: Symbol.Range, body: XML.Body): Option[XML.Elem] = None |
215 |
def make_ref(props: Properties.T, body: XML.Body): Option[XML.Elem] = None |
|
74677 | 216 |
} |
73055 | 217 |
|
74678 | 218 |
|
73718 | 219 |
/* HTML output */ |
73036 | 220 |
|
72957 | 221 |
private val div_elements = |
75379 | 222 |
Set(HTML.div.name, HTML.pre.name, HTML.par.name, HTML.list.name, HTML.`enum`.name, |
72957 | 223 |
HTML.descr.name) |
224 |
||
73056 | 225 |
def make_html( |
74752
ebd3a685bfc9
clarified signature: more explicit class Entity_Context with private state + operations;
wenzelm
parents:
74751
diff
changeset
|
226 |
entity_context: Entity_Context, |
73056 | 227 |
elements: Elements, |
75393 | 228 |
xml: XML.Body |
229 |
): XML.Body = { |
|
73054 | 230 |
def html_div(html: XML.Body): Boolean = |
231 |
html exists { |
|
232 |
case XML.Elem(markup, body) => div_elements.contains(markup.name) || html_div(body) |
|
233 |
case XML.Text(_) => false |
|
234 |
} |
|
72957 | 235 |
|
73055 | 236 |
def html_class(c: String, html: XML.Body): XML.Body = |
237 |
if (c == "") html |
|
238 |
else if (html_div(html)) List(HTML.div(c, html)) |
|
239 |
else List(HTML.span(c, html)) |
|
72957 | 240 |
|
74677 | 241 |
def html_body(xml_body: XML.Body, end_offset: Symbol.Offset): (XML.Body, Symbol.Offset) = |
242 |
xml_body.foldRight((List.empty[XML.Tree], end_offset)) { case (tree, (res, end_offset1)) => |
|
243 |
val (res1, offset) = html_body_single(tree, end_offset1) |
|
244 |
(res1 ++ res, offset) |
|
245 |
} |
|
246 |
||
247 |
@tailrec |
|
248 |
def html_body_single(xml_tree: XML.Tree, end_offset: Symbol.Offset): (XML.Body, Symbol.Offset) = |
|
249 |
xml_tree match { |
|
250 |
case XML.Wrapped_Elem(markup, _, body) => html_body_single(XML.Elem(markup, body), end_offset) |
|
73056 | 251 |
case XML.Elem(Markup(Markup.ENTITY, props @ Markup.Kind(kind)), body) => |
74677 | 252 |
val (body1, offset) = html_body(body, end_offset) |
73056 | 253 |
if (elements.entity(kind)) { |
74753 | 254 |
entity_context.make_ref(props, body1) match { |
74677 | 255 |
case Some(link) => (List(link), offset) |
256 |
case None => (body1, offset) |
|
73056 | 257 |
} |
258 |
} |
|
74677 | 259 |
else (body1, offset) |
73055 | 260 |
case XML.Elem(Markup(Markup.LANGUAGE, Markup.Name(name)), body) => |
74677 | 261 |
val (body1, offset) = html_body(body, end_offset) |
262 |
(html_class(if (elements.language(name)) name else "", body1), offset) |
|
73055 | 263 |
case XML.Elem(Markup(Markup.MARKDOWN_PARAGRAPH, _), body) => |
74677 | 264 |
val (body1, offset) = html_body(body, end_offset) |
265 |
(List(HTML.par(body1)), offset) |
|
73055 | 266 |
case XML.Elem(Markup(Markup.MARKDOWN_ITEM, _), body) => |
74677 | 267 |
val (body1, offset) = html_body(body, end_offset) |
268 |
(List(HTML.item(body1)), offset) |
|
269 |
case XML.Elem(Markup(Markup.Markdown_Bullet.name, _), text) => |
|
74683
c8327efc7af1
clarified signature: more direct XML.symbol_length;
wenzelm
parents:
74682
diff
changeset
|
270 |
(Nil, end_offset - XML.symbol_length(text)) |
73054 | 271 |
case XML.Elem(Markup.Markdown_List(kind), body) => |
74677 | 272 |
val (body1, offset) = html_body(body, end_offset) |
75379 | 273 |
if (kind == Markup.ENUMERATE) (List(HTML.`enum`(body1)), offset) |
74677 | 274 |
else (List(HTML.list(body1)), offset) |
73054 | 275 |
case XML.Elem(markup, body) => |
276 |
val name = markup.name |
|
74677 | 277 |
val (body1, offset) = html_body(body, end_offset) |
73054 | 278 |
val html = |
279 |
markup.properties match { |
|
280 |
case Markup.Kind(kind) if kind == Markup.COMMAND || kind == Markup.KEYWORD => |
|
74677 | 281 |
html_class(kind, body1) |
73054 | 282 |
case _ => |
74677 | 283 |
body1 |
73054 | 284 |
} |
285 |
Rendering.foreground.get(name) orElse Rendering.text_color.get(name) match { |
|
74677 | 286 |
case Some(c) => (html_class(c.toString, html), offset) |
287 |
case None => (html_class(name, html), offset) |
|
72957 | 288 |
} |
73054 | 289 |
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
|
290 |
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
|
291 |
val body = HTML.text(Symbol.decode(text)) |
74753 | 292 |
entity_context.make_def(Text.Range(offset, end_offset), body) match { |
74677 | 293 |
case Some(body1) => (List(body1), offset) |
294 |
case None => (body, offset) |
|
295 |
} |
|
73054 | 296 |
} |
297 |
||
74683
c8327efc7af1
clarified signature: more direct XML.symbol_length;
wenzelm
parents:
74682
diff
changeset
|
298 |
html_body(xml, XML.symbol_length(xml) + 1)._1 |
73054 | 299 |
} |
72957 | 300 |
|
301 |
||
302 |
/* PIDE HTML document */ |
|
303 |
||
304 |
def html_document( |
|
305 |
snapshot: Document.Snapshot, |
|
72962 | 306 |
html_context: HTML_Context, |
74709 | 307 |
plain_text: Boolean = false, |
75393 | 308 |
fonts_css: String = HTML.fonts_css() |
309 |
): HTML_Document = { |
|
73120
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
wenzelm
parents:
73059
diff
changeset
|
310 |
require(!snapshot.is_outdated, "document snapshot outdated") |
72957 | 311 |
|
312 |
val name = snapshot.node_name |
|
313 |
if (plain_text) { |
|
72962 | 314 |
val title = "File " + Symbol.cartouche_decoded(name.path.file_name) |
72959 | 315 |
val body = HTML.text(snapshot.node.source) |
74709 | 316 |
html_context.html_document(title, body, fonts_css) |
72957 | 317 |
} |
318 |
else { |
|
74756 | 319 |
Resources.html_document(snapshot) getOrElse { |
72962 | 320 |
val title = |
321 |
if (name.is_theory) "Theory " + quote(name.theory_base_name) |
|
322 |
else "File " + Symbol.cartouche_decoded(name.path.file_name) |
|
75897 | 323 |
val xml = snapshot.xml_markup(elements = html_context.elements.html) |
324 |
val body = make_html(Entity_Context.empty, html_context.elements, xml) |
|
74709 | 325 |
html_context.html_document(title, body, fonts_css) |
72957 | 326 |
} |
327 |
} |
|
328 |
} |
|
329 |
||
330 |
||
331 |
||
73718 | 332 |
/** HTML presentation **/ |
72649 | 333 |
|
72648 | 334 |
/* presentation context */ |
335 |
||
75393 | 336 |
object Context { |
72648 | 337 |
val none: Context = new Context { def enabled: Boolean = false } |
338 |
val standard: Context = new Context { def enabled: Boolean = true } |
|
339 |
||
340 |
def dir(path: Path): Context = |
|
341 |
new Context { |
|
342 |
def enabled: Boolean = true |
|
343 |
override def dir(store: Sessions.Store): Path = path |
|
344 |
} |
|
345 |
||
346 |
def make(s: String): Context = |
|
347 |
if (s == ":") standard else dir(Path.explode(s)) |
|
348 |
} |
|
349 |
||
75393 | 350 |
abstract class Context private { |
72648 | 351 |
def enabled: Boolean |
352 |
def enabled(info: Sessions.Info): Boolean = enabled || info.browser_info |
|
353 |
def dir(store: Sessions.Store): Path = store.presentation_dir |
|
354 |
} |
|
355 |
||
356 |
||
72955
942bf91545fa
clarified comments: file-system access is always unsynchronized;
wenzelm
parents:
72882
diff
changeset
|
357 |
/* maintain chapter index */ |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
358 |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
359 |
private val sessions_path = Path.basic(".sessions") |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
360 |
|
75393 | 361 |
private def read_sessions(dir: Path): List[(String, String)] = { |
51416 | 362 |
val path = dir + sessions_path |
363 |
if (path.is_file) { |
|
364 |
import XML.Decode._ |
|
65344
b99283eed13c
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65089
diff
changeset
|
365 |
list(pair(string, string))(Symbol.decode_yxml(File.read(path))) |
51416 | 366 |
} |
367 |
else Nil |
|
51402 | 368 |
} |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
369 |
|
74709 | 370 |
def update_chapter( |
75393 | 371 |
presentation_dir: Path, |
372 |
chapter: String, |
|
373 |
new_sessions: List[(String, String)] |
|
374 |
): Unit = { |
|
74699 | 375 |
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
|
376 |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
377 |
val sessions0 = |
51406
950b897f95bb
proper path -- I/O was hidden due to permissiveness;
wenzelm
parents:
51402
diff
changeset
|
378 |
try { read_sessions(dir) } |
51987 | 379 |
catch { case _: XML.Error => Nil } |
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
380 |
|
51402 | 381 |
val sessions = (SortedMap.empty[String, String] ++ sessions0 ++ new_sessions).toList |
74699 | 382 |
File.write(dir + sessions_path, |
383 |
{ |
|
384 |
import XML.Encode._ |
|
385 |
YXML.string_of_body(list(pair(string, string))(sessions)) |
|
386 |
}) |
|
51402 | 387 |
|
65988 | 388 |
val title = "Isabelle/" + chapter + " sessions" |
389 |
HTML.write_document(dir, "index.html", |
|
73523
2cd23d587db9
further clarification of Isabelle distribution identification -- avoid odd patching of sources;
wenzelm
parents:
73474
diff
changeset
|
390 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
65988 | 391 |
HTML.chapter(title) :: |
392 |
(if (sessions.isEmpty) Nil |
|
393 |
else |
|
65992 | 394 |
List(HTML.div("sessions", |
395 |
List(HTML.description( |
|
65988 | 396 |
sessions.map({ case (name, description) => |
69318 | 397 |
val descr = Symbol.trim_blank_lines(description) |
65989 | 398 |
(List(HTML.link(name + "/index.html", HTML.text(name))), |
69318 | 399 |
if (descr == "") Nil |
74709 | 400 |
else HTML.break ::: List(HTML.pre(HTML.text(descr)))) })))))), |
401 |
base = Some(presentation_dir)) |
|
51399
6ac3c29a300e
discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents:
50707
diff
changeset
|
402 |
} |
61372 | 403 |
|
75393 | 404 |
def update_root(presentation_dir: Path): Unit = { |
74700
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
405 |
Isabelle_System.make_directory(presentation_dir) |
74709 | 406 |
HTML.init_fonts(presentation_dir) |
74700
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
407 |
Isabelle_System.copy_file(Path.explode("~~/lib/logo/isabelle.gif"), |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
408 |
presentation_dir + Path.explode("isabelle.gif")) |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
409 |
val title = "The " + XML.text(Isabelle_System.isabelle_name()) + " Library" |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
410 |
File.write(presentation_dir + Path.explode("index.html"), |
decf8b66e2fb
more thorough update_global_index: overwrite old content;
wenzelm
parents:
74699
diff
changeset
|
411 |
HTML.header + |
73529 | 412 |
""" |
73528
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
413 |
<head> |
73529 | 414 |
""" + HTML.head_meta + """ |
73528
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
415 |
<title>""" + title + """</title> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
416 |
</head> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
417 |
|
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
418 |
<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
|
419 |
<center> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
420 |
<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
|
421 |
<tr> |
74676 | 422 |
<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
|
423 |
|
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
424 |
<td width="80%" valign="middle" align="center"> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
425 |
<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
|
426 |
<tr> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
427 |
<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
|
428 |
</tr> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
429 |
</table> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
430 |
</td> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
431 |
</tr> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
432 |
</table> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
433 |
</center> |
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
434 |
<hr /> |
74670
b2604cd4d131
recover library_index_content.template from c337c798f64c: required for website/build/main;
wenzelm
parents:
73718
diff
changeset
|
435 |
""" + 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
|
436 |
""" |
73528
c337c798f64c
clarified HTML template (see also 04cb7e02ca38): avoid odd patching of sources;
wenzelm
parents:
73523
diff
changeset
|
437 |
</body> |
73529 | 438 |
""" + HTML.footer) |
61372 | 439 |
} |
440 |
||
441 |
||
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
442 |
/* present session */ |
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
443 |
|
75888 | 444 |
val session_graph_path: Path = Path.explode("session_graph.pdf") |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
445 |
|
72648 | 446 |
def session_html( |
75887
e5c0116a5c9f
clarified signature: replaced Sessions.Deps by Sessions.Structure from HTML_Context;
wenzelm
parents:
75886
diff
changeset
|
447 |
html_context: HTML_Context, |
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75774
diff
changeset
|
448 |
session_context: Export.Session_Context, |
72992 | 449 |
progress: Progress = new Progress, |
73022
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
450 |
verbose: Boolean = false, |
75393 | 451 |
): Unit = { |
75902 | 452 |
val session_name = session_context.session_name |
453 |
val session_info = session_context.sessions_structure(session_name) |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
454 |
|
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
455 |
val session_dir = |
75902 | 456 |
Isabelle_System.make_directory(html_context.session_dir(session_name)).expand |
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
457 |
|
75902 | 458 |
progress.echo("Presenting " + session_name + " in " + session_dir + " ...") |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
459 |
|
75907 | 460 |
val session = html_context.document_info.the_session(session_name) |
75905
2ee3ea69e8f1
clarified Presentation.Nodes, with explicit Nodes.Session and Nodes.Theory;
wenzelm
parents:
75902
diff
changeset
|
461 |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
462 |
Bytes.write(session_dir + session_graph_path, |
75902 | 463 |
graphview.Graph_File.make_pdf(session_info.options, |
464 |
session_context.session_base.session_graph_display)) |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
465 |
|
75925 | 466 |
val document_variants = |
72683 | 467 |
for { |
75902 | 468 |
doc <- session_info.document_variants |
75780
f49c4f160b84
clarified signature: find session_database within Session_Context.db_hierarchy;
wenzelm
parents:
75778
diff
changeset
|
469 |
db <- session_context.session_db() |
75902 | 470 |
document <- Document_Build.read_document(db, session_name, doc.name) |
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
471 |
} |
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
472 |
yield { |
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
473 |
val doc_path = session_dir + doc.path.pdf |
75926
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
474 |
if (Path.eq_case_insensitive(doc.path.pdf, session_graph_path)) { |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
475 |
error("Illegal document variant " + quote(doc.name) + |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
476 |
" (conflict with " + session_graph_path + ")") |
b8ee1ef948c2
more thorough checks of browser_info file conflicts;
wenzelm
parents:
75925
diff
changeset
|
477 |
} |
75902 | 478 |
if (verbose) progress.echo("Presenting document " + session_name + "/" + doc.name) |
479 |
if (session_info.document_echo) progress.echo("Document at " + doc_path) |
|
74732
015282fb3e31
clarified messages, depending on option "document_echo";
wenzelm
parents:
74731
diff
changeset
|
480 |
Bytes.write(doc_path, document.pdf) |
73022
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
481 |
doc |
38528017e4c8
more verbosity for potentially bulky presentation;
wenzelm
parents:
72992
diff
changeset
|
482 |
} |
72673
8ff7a0e394f9
clarified PDF/HTML presentation, based on pdf blobs from session database (e.g. from earlier builds);
wenzelm
parents:
72670
diff
changeset
|
483 |
|
75925 | 484 |
val document_links = { |
485 |
val link1 = HTML.link(session_graph_path, HTML.text("theory dependencies")) |
|
486 |
val links2 = document_variants.map(doc => HTML.link(doc.path.pdf, HTML.text(doc.name))) |
|
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
487 |
Library.separate(HTML.break ::: HTML.nl, |
75925 | 488 |
(link1 :: links2).map(link => HTML.text("View ") ::: List(link))).flatten |
72622
830222403681
HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents:
72600
diff
changeset
|
489 |
} |
62971
087e36ce0593
back to exact copy of non-text file (amending dcc8e1d34b18);
wenzelm
parents:
62631
diff
changeset
|
490 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
491 |
def present_theory(theory_name: String): XML.Body = { |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
492 |
progress.expose_interrupt() |
73215 | 493 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
494 |
def err(): Nothing = |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
495 |
error("Missing document information for theory: " + quote(theory_name)) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
496 |
|
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
497 |
val command = Build_Job.read_theory(session_context.theory(theory_name)) getOrElse err() |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
498 |
val theory = html_context.theory_by_name(session_name, theory_name) getOrElse err() |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
499 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
500 |
if (verbose) progress.echo("Presenting theory " + quote(theory_name)) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
501 |
val snapshot = Document.State.init.snippet(command) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
502 |
|
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
503 |
val thy_elements = theory.elements(html_context.elements) |
73215 | 504 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
505 |
val thy_html = |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
506 |
html_context.source( |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
507 |
make_html(Entity_Context.make(html_context, session_name, theory_name, theory.thy_file), |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
508 |
thy_elements, snapshot.xml_markup(elements = thy_elements.html))) |
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
509 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
510 |
val blobs_html = |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
511 |
for { |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
512 |
(blob, xml) <- snapshot.xml_markup_blobs(elements = thy_elements.html) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
513 |
if xml.nonEmpty |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
514 |
} |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
515 |
yield { |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
516 |
progress.expose_interrupt() |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
517 |
if (verbose) progress.echo("Presenting file " + quote(blob.name.node)) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
518 |
(blob, html_context.source(make_html(Entity_Context.empty, thy_elements, xml))) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
519 |
} |
74715
129fb11b357f
use all entity kinds from theory export, e.g. "method", "attribute";
wenzelm
parents:
74714
diff
changeset
|
520 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
521 |
val files = |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
522 |
for { |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
523 |
(blob, file_html) <- blobs_html |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
524 |
file_path = session_dir + html_context.file_html(blob.name.node) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
525 |
rel_path <- File.relative_path(session_dir, file_path) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
526 |
} |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
527 |
yield { |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
528 |
val file_title = "File " + Symbol.cartouche_decoded(blob.src_path.implode_short) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
529 |
HTML.write_document(file_path.dir, file_path.file_name, |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
530 |
List(HTML.title(file_title)), List(html_context.head(file_title), file_html), |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
531 |
base = Some(html_context.root_dir)) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
532 |
List(HTML.link(rel_path.implode, HTML.text(file_title))) |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
533 |
} |
73215 | 534 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
535 |
val thy_title = "Theory " + theory.print_short |
73215 | 536 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
537 |
HTML.write_document(session_dir, html_context.theory_html(theory).implode, |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
538 |
List(HTML.title(thy_title)), List(html_context.head(thy_title), thy_html), |
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
539 |
base = Some(html_context.root_dir)) |
73215 | 540 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
541 |
List(HTML.link(html_context.theory_html(theory), |
75925 | 542 |
HTML.text(theory.print_short) ::: |
543 |
(if (files.isEmpty) Nil else List(HTML.itemize(files))))) |
|
72989 | 544 |
} |
61500 | 545 |
|
75924
1402a1696dca
prefer strict operations with explicit errors (instead of missing HTML output);
wenzelm
parents:
75917
diff
changeset
|
546 |
val theories = session.used_theories.map(present_theory) |
74795
5eac4b13d1f1
less ambitious parallelism: more direct read/write saves overall heap space and GC time;
wenzelm
parents:
74782
diff
changeset
|
547 |
|
75902 | 548 |
val title = "Session " + session_name |
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
549 |
HTML.write_document(session_dir, "index.html", |
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
550 |
List(HTML.title(title + Isabelle_System.isabelle_heading())), |
75925 | 551 |
html_context.head(title, List(HTML.par(document_links))) :: |
75899
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
552 |
html_context.contents("Theories", theories), |
d50c2129e73a
more robust directory structure: always relative to session_dir;
wenzelm
parents:
75898
diff
changeset
|
553 |
base = Some(html_context.root_dir)) |
61372 | 554 |
} |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
diff
changeset
|
555 |
} |