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