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