src/Pure/Thy/html.scala
author wenzelm
Sat, 30 Jan 2021 17:15:14 +0100
changeset 73203 9c10b4fa17b5
parent 73202 8a17c7bf530a
child 73204 aa3d4cf7825a
permissions -rw-r--r--
clarified signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33984
c54498f88a77 Basic HTML output.
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Thy/html.scala
c54498f88a77 Basic HTML output.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
c54498f88a77 Basic HTML output.
wenzelm
parents:
diff changeset
     3
50707
5b2bf7611662 maintain session index on Scala side, for more determistic results;
wenzelm
parents: 50201
diff changeset
     4
HTML presentation elements.
33984
c54498f88a77 Basic HTML output.
wenzelm
parents:
diff changeset
     5
*/
c54498f88a77 Basic HTML output.
wenzelm
parents:
diff changeset
     6
c54498f88a77 Basic HTML output.
wenzelm
parents:
diff changeset
     7
package isabelle
c54498f88a77 Basic HTML output.
wenzelm
parents:
diff changeset
     8
55618
995162143ef4 tuned imports;
wenzelm
parents: 54379
diff changeset
     9
33984
c54498f88a77 Basic HTML output.
wenzelm
parents:
diff changeset
    10
object HTML
c54498f88a77 Basic HTML output.
wenzelm
parents:
diff changeset
    11
{
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    12
  /* output text with control symbols */
59063
b3c45d0e4fe1 encode text with control symbols;
wenzelm
parents: 56748
diff changeset
    13
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    14
  private val control =
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    15
    Map(
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    16
      Symbol.sub -> "sub", Symbol.sub_decoded -> "sub",
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    17
      Symbol.sup -> "sup", Symbol.sup_decoded -> "sup",
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    18
      Symbol.bold -> "b", Symbol.bold_decoded -> "b")
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    19
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    20
  private val control_block =
62104
fb73c0d7bb37 clarified symbol insertion, depending on buffer encoding;
wenzelm
parents: 60215
diff changeset
    21
    Map(
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    22
      Symbol.bsub -> "<sub>", Symbol.bsub_decoded -> "<sub>",
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    23
      Symbol.esub -> "</sub>", Symbol.esub_decoded -> "</sub>",
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    24
      Symbol.bsup -> "<sup>", Symbol.bsup_decoded -> "<sup>",
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    25
      Symbol.esup -> "</sup>", Symbol.esup_decoded -> "</sup>")
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    26
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    27
  def is_control(sym: Symbol.Symbol): Boolean = control.isDefinedAt(sym)
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    28
73202
8a17c7bf530a tuned signature;
wenzelm
parents: 73129
diff changeset
    29
  def output(s: StringBuilder, text: String, hidden: Boolean, permissive: Boolean)
66018
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    30
  {
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    31
    def output_char(c: Char): Unit =
73203
9c10b4fa17b5 clarified signature;
wenzelm
parents: 73202
diff changeset
    32
      XML.output_char(s, c, permissive = permissive)
66018
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    33
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    34
    def output_string(str: String): Unit =
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    35
      str.iterator.foreach(output_char)
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    36
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    37
    def output_hidden(body: => Unit): Unit =
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    38
      if (hidden) { s ++= "<span class=\"hidden\">"; body; s ++= "</span>" }
37200
0f3edc64356a added HTML.encode (in Scala), similar to HTML.output in ML;
wenzelm
parents: 36016
diff changeset
    39
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    40
    def output_symbol(sym: Symbol.Symbol): Unit =
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    41
      if (sym != "") {
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    42
        control_block.get(sym) match {
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    43
          case Some(html) if html.startsWith("</") =>
66018
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    44
            s ++= html; output_hidden(output_string(sym))
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    45
          case Some(html) =>
66018
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    46
            output_hidden(output_string(sym)); s ++= html
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    47
          case None =>
67255
f1f983484878 HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents: 66212
diff changeset
    48
            if (hidden && Symbol.is_control_encoded(sym)) {
f1f983484878 HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents: 66212
diff changeset
    49
              output_hidden(output_string(Symbol.control_prefix))
f1f983484878 HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents: 66212
diff changeset
    50
              s ++= "<span class=\"control\">"
f1f983484878 HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents: 66212
diff changeset
    51
              output_string(Symbol.control_name(sym).get)
f1f983484878 HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents: 66212
diff changeset
    52
              s ++= "</span>"
f1f983484878 HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents: 66212
diff changeset
    53
              output_hidden(output_string(Symbol.control_suffix))
f1f983484878 HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents: 66212
diff changeset
    54
            }
f1f983484878 HTML rendering of \<^control> as in Isabelle/jEdit;
wenzelm
parents: 66212
diff changeset
    55
            else output_string(sym)
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    56
        }
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    57
      }
59063
b3c45d0e4fe1 encode text with control symbols;
wenzelm
parents: 56748
diff changeset
    58
62104
fb73c0d7bb37 clarified symbol insertion, depending on buffer encoding;
wenzelm
parents: 60215
diff changeset
    59
    var ctrl = ""
59063
b3c45d0e4fe1 encode text with control symbols;
wenzelm
parents: 56748
diff changeset
    60
    for (sym <- Symbol.iterator(text)) {
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    61
      if (is_control(sym)) { output_symbol(ctrl); ctrl = sym }
59063
b3c45d0e4fe1 encode text with control symbols;
wenzelm
parents: 56748
diff changeset
    62
      else {
62104
fb73c0d7bb37 clarified symbol insertion, depending on buffer encoding;
wenzelm
parents: 60215
diff changeset
    63
        control.get(ctrl) match {
66006
cec184536dfd uniform notion of Symbol.is_controllable (see also 265d9300d523);
wenzelm
parents: 66001
diff changeset
    64
          case Some(elem) if Symbol.is_controllable(sym) =>
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    65
            output_hidden(output_symbol(ctrl))
65991
wenzelm
parents: 65990
diff changeset
    66
            s += '<'; s ++= elem; s += '>'
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    67
            output_symbol(sym)
65991
wenzelm
parents: 65990
diff changeset
    68
            s ++= "</"; s ++= elem; s += '>'
59063
b3c45d0e4fe1 encode text with control symbols;
wenzelm
parents: 56748
diff changeset
    69
          case _ =>
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    70
            output_symbol(ctrl)
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    71
            output_symbol(sym)
59063
b3c45d0e4fe1 encode text with control symbols;
wenzelm
parents: 56748
diff changeset
    72
        }
62104
fb73c0d7bb37 clarified symbol insertion, depending on buffer encoding;
wenzelm
parents: 60215
diff changeset
    73
        ctrl = ""
59063
b3c45d0e4fe1 encode text with control symbols;
wenzelm
parents: 56748
diff changeset
    74
      }
37200
0f3edc64356a added HTML.encode (in Scala), similar to HTML.output in ML;
wenzelm
parents: 36016
diff changeset
    75
    }
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
    76
    output_symbol(ctrl)
64355
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
    77
  }
59063
b3c45d0e4fe1 encode text with control symbols;
wenzelm
parents: 56748
diff changeset
    78
66018
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    79
  def output(text: String): String =
73202
8a17c7bf530a tuned signature;
wenzelm
parents: 73129
diff changeset
    80
    Library.make_string(output(_, text, hidden = false, permissive = true))
64355
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
    81
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
    82
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
    83
  /* output XML as HTML */
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
    84
65834
67a6e0f166c2 extra space only for some structual elements, but not <a>, <b>, <em> etc. (amending 8a0fe5469ba0);
wenzelm
parents: 65773
diff changeset
    85
  private val structural_elements =
67a6e0f166c2 extra space only for some structual elements, but not <a>, <b>, <em> etc. (amending 8a0fe5469ba0);
wenzelm
parents: 65773
diff changeset
    86
    Set("head", "body", "meta", "div", "pre", "p", "title", "h1", "h2", "h3", "h4", "h5", "h6",
67a6e0f166c2 extra space only for some structual elements, but not <a>, <b>, <em> etc. (amending 8a0fe5469ba0);
wenzelm
parents: 65773
diff changeset
    87
      "ul", "ol", "dl", "li", "dt", "dd")
67a6e0f166c2 extra space only for some structual elements, but not <a>, <b>, <em> etc. (amending 8a0fe5469ba0);
wenzelm
parents: 65773
diff changeset
    88
73202
8a17c7bf530a tuned signature;
wenzelm
parents: 73129
diff changeset
    89
  def output(s: StringBuilder, body: XML.Body, hidden: Boolean, structural: Boolean)
64355
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
    90
  {
65991
wenzelm
parents: 65990
diff changeset
    91
    def elem(markup: Markup)
wenzelm
parents: 65990
diff changeset
    92
    {
wenzelm
parents: 65990
diff changeset
    93
      s ++= markup.name
wenzelm
parents: 65990
diff changeset
    94
      for ((a, b) <- markup.properties) {
66018
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    95
        s += ' '
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    96
        s ++= a
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    97
        s += '='
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
    98
        s += '"'
73202
8a17c7bf530a tuned signature;
wenzelm
parents: 73129
diff changeset
    99
        output(s, b, hidden = hidden, permissive = false)
66018
9ce3720976dc permissive output of XML.Text, e.g. relevant for embedded <style>;
wenzelm
parents: 66006
diff changeset
   100
        s += '"'
65991
wenzelm
parents: 65990
diff changeset
   101
      }
wenzelm
parents: 65990
diff changeset
   102
    }
64355
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
   103
    def tree(t: XML.Tree): Unit =
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
   104
      t match {
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
   105
        case XML.Elem(markup, Nil) =>
65991
wenzelm
parents: 65990
diff changeset
   106
          s += '<'; elem(markup); s ++= "/>"
64355
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
   107
        case XML.Elem(markup, ts) =>
67337
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   108
          if (structural && structural_elements(markup.name)) s += '\n'
65991
wenzelm
parents: 65990
diff changeset
   109
          s += '<'; elem(markup); s += '>'
64355
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
   110
          ts.foreach(tree)
65991
wenzelm
parents: 65990
diff changeset
   111
          s ++= "</"; s ++= markup.name; s += '>'
67337
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   112
          if (structural && structural_elements(markup.name)) s += '\n'
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
   113
        case XML.Text(txt) =>
73202
8a17c7bf530a tuned signature;
wenzelm
parents: 73129
diff changeset
   114
          output(s, txt, hidden = hidden, permissive = true)
64355
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
   115
      }
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
   116
    body.foreach(tree)
37200
0f3edc64356a added HTML.encode (in Scala), similar to HTML.output in ML;
wenzelm
parents: 36016
diff changeset
   117
  }
0f3edc64356a added HTML.encode (in Scala), similar to HTML.output in ML;
wenzelm
parents: 36016
diff changeset
   118
67337
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   119
  def output(body: XML.Body, hidden: Boolean, structural: Boolean): String =
73202
8a17c7bf530a tuned signature;
wenzelm
parents: 73129
diff changeset
   120
    Library.make_string(output(_, body, hidden, structural))
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
   121
67337
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   122
  def output(tree: XML.Tree, hidden: Boolean, structural: Boolean): String =
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   123
    output(List(tree), hidden, structural)
64355
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
   124
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
   125
65753
787e5ee6ef53 more operations;
wenzelm
parents: 64362
diff changeset
   126
  /* attributes */
787e5ee6ef53 more operations;
wenzelm
parents: 64362
diff changeset
   127
65992
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   128
  class Attribute(val name: String, value: String)
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   129
  {
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   130
    def xml: XML.Attribute = name -> value
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   131
    def apply(elem: XML.Elem): XML.Elem = elem + xml
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   132
  }
65942
864a4892e43c clarified signature;
wenzelm
parents: 65941
diff changeset
   133
65992
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   134
  def id(s: String): Attribute = new Attribute("id", s)
65993
75590c9a585f tuned signature;
wenzelm
parents: 65992
diff changeset
   135
  def class_(name: String): Attribute = new Attribute("class", name)
65946
5dd3974cf0bc tuned signature;
wenzelm
parents: 65944
diff changeset
   136
65992
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   137
  def width(w: Int): Attribute = new Attribute("width", w.toString)
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   138
  def height(h: Int): Attribute = new Attribute("height", h.toString)
65946
5dd3974cf0bc tuned signature;
wenzelm
parents: 65944
diff changeset
   139
  def size(w: Int, h: Int)(elem: XML.Elem): XML.Elem = width(w)(height(h)(elem))
65753
787e5ee6ef53 more operations;
wenzelm
parents: 64362
diff changeset
   140
787e5ee6ef53 more operations;
wenzelm
parents: 64362
diff changeset
   141
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   142
  /* structured markup operators */
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   143
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   144
  def text(txt: String): XML.Body = if (txt.isEmpty) Nil else List(XML.Text(txt))
65753
787e5ee6ef53 more operations;
wenzelm
parents: 64362
diff changeset
   145
  val break: XML.Body = List(XML.elem("br"))
72622
830222403681 HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents: 72376
diff changeset
   146
  val nl: XML.Body = List(XML.Text("\n"))
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   147
65992
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   148
  class Operator(val name: String)
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   149
  {
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   150
    def apply(body: XML.Body): XML.Elem = XML.elem(name, body)
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   151
    def apply(att: Attribute, body: XML.Body): XML.Elem = att(apply(body))
65993
75590c9a585f tuned signature;
wenzelm
parents: 65992
diff changeset
   152
    def apply(c: String, body: XML.Body): XML.Elem = apply(class_(c), body)
65992
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   153
  }
64356
wenzelm
parents: 64355
diff changeset
   154
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   155
  class Heading(name: String) extends Operator(name)
65992
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   156
  {
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   157
    def apply(txt: String): XML.Elem = super.apply(text(txt))
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   158
    def apply(att: Attribute, txt: String): XML.Elem = super.apply(att, text(txt))
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   159
    def apply(c: String, txt: String): XML.Elem = super.apply(c, text(txt))
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   160
  }
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   161
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   162
  val div = new Operator("div")
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   163
  val span = new Operator("span")
65753
787e5ee6ef53 more operations;
wenzelm
parents: 64362
diff changeset
   164
  val pre = new Operator("pre")
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   165
  val par = new Operator("p")
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   166
  val emph = new Operator("em")
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   167
  val bold = new Operator("b")
65771
688a7dd22cbb make index formally within Isabelle/Scala;
wenzelm
parents: 65753
diff changeset
   168
  val code = new Operator("code")
67336
3ee6da378183 HTML output for Markdown elements;
wenzelm
parents: 67255
diff changeset
   169
  val item = new Operator("li")
3ee6da378183 HTML output for Markdown elements;
wenzelm
parents: 67255
diff changeset
   170
  val list = new Operator("ul")
3ee6da378183 HTML output for Markdown elements;
wenzelm
parents: 67255
diff changeset
   171
  val enum = new Operator("ol")
3ee6da378183 HTML output for Markdown elements;
wenzelm
parents: 67255
diff changeset
   172
  val descr = new Operator("dl")
3ee6da378183 HTML output for Markdown elements;
wenzelm
parents: 67255
diff changeset
   173
  val dt = new Operator("dt")
3ee6da378183 HTML output for Markdown elements;
wenzelm
parents: 67255
diff changeset
   174
  val dd = new Operator("dd")
64355
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
   175
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   176
  val title = new Heading("title")
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   177
  val chapter = new Heading("h1")
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   178
  val section = new Heading("h2")
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   179
  val subsection = new Heading("h3")
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   180
  val subsubsection = new Heading("h4")
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   181
  val paragraph = new Heading("h5")
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   182
  val subparagraph = new Heading("h6")
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   183
67336
3ee6da378183 HTML output for Markdown elements;
wenzelm
parents: 67255
diff changeset
   184
  def itemize(items: List[XML.Body]): XML.Elem = list(items.map(item(_)))
3ee6da378183 HTML output for Markdown elements;
wenzelm
parents: 67255
diff changeset
   185
  def enumerate(items: List[XML.Body]): XML.Elem = enum(items.map(item(_)))
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   186
  def description(items: List[(XML.Body, XML.Body)]): XML.Elem =
67336
3ee6da378183 HTML output for Markdown elements;
wenzelm
parents: 67255
diff changeset
   187
    descr(items.flatMap({ case (x, y) => List(dt(x), dd(y)) }))
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   188
72622
830222403681 HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents: 72376
diff changeset
   189
  def link(href: String, body: XML.Body): XML.Elem =
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   190
    XML.Elem(Markup("a", List("href" -> href)), if (body.isEmpty) text(href) else body)
64355
c6a1031cf925 support for XML as HTML;
wenzelm
parents: 62113
diff changeset
   191
72622
830222403681 HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents: 72376
diff changeset
   192
  def link(path: Path, body: XML.Body): XML.Elem = link(path.implode, body)
830222403681 HTML presentation in Isabelle/Scala, based on theory html exports from Isabelle/ML;
wenzelm
parents: 72376
diff changeset
   193
65753
787e5ee6ef53 more operations;
wenzelm
parents: 64362
diff changeset
   194
  def image(src: String, alt: String = ""): XML.Elem =
787e5ee6ef53 more operations;
wenzelm
parents: 64362
diff changeset
   195
    XML.Elem(Markup("img", List("src" -> src) ::: proper_string(alt).map("alt" -> _).toList), Nil)
787e5ee6ef53 more operations;
wenzelm
parents: 64362
diff changeset
   196
66040
f826ba18fe08 HTML preview based on PIDE markup;
wenzelm
parents: 66018
diff changeset
   197
  def source(body: XML.Body): XML.Elem = pre("source", body)
f826ba18fe08 HTML preview based on PIDE markup;
wenzelm
parents: 66018
diff changeset
   198
  def source(src: String): XML.Elem = source(text(src))
65988
8040d2563593 modernized generated HTML;
wenzelm
parents: 65946
diff changeset
   199
65941
316c30b60ebc tuned layout;
wenzelm
parents: 65939
diff changeset
   200
  def style(s: String): XML.Elem = XML.elem("style", text(s))
66000
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   201
  def style_file(href: String): XML.Elem =
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   202
    XML.Elem(Markup("link", List("rel" -> "stylesheet", "type" -> "text/css", "href" -> href)), Nil)
66212
f41396c15bb1 tuned signature;
wenzelm
parents: 66210
diff changeset
   203
  def style_file(path: Path): XML.Elem = style_file(Url.print_file(path.file))
66000
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   204
66210
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   205
  def script(s: String): XML.Elem = XML.elem("script", text(s))
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   206
  def script_file(href: String): XML.Elem = XML.Elem(Markup("script", List("src" -> href)), Nil)
66212
f41396c15bb1 tuned signature;
wenzelm
parents: 66210
diff changeset
   207
  def script_file(path: Path): XML.Elem = script_file(Url.print_file(path.file))
f41396c15bb1 tuned signature;
wenzelm
parents: 66210
diff changeset
   208
37200
0f3edc64356a added HTML.encode (in Scala), similar to HTML.output in ML;
wenzelm
parents: 36016
diff changeset
   209
65892
bbad8162d678 clarified signature;
wenzelm
parents: 65891
diff changeset
   210
  /* messages */
bbad8162d678 clarified signature;
wenzelm
parents: 65891
diff changeset
   211
65939
9fb044904a4d support for message underline and tooltips;
wenzelm
parents: 65892
diff changeset
   212
  // background
65993
75590c9a585f tuned signature;
wenzelm
parents: 65992
diff changeset
   213
  val writeln_message: Attribute = class_("writeln_message")
75590c9a585f tuned signature;
wenzelm
parents: 65992
diff changeset
   214
  val warning_message: Attribute = class_("warning_message")
75590c9a585f tuned signature;
wenzelm
parents: 65992
diff changeset
   215
  val error_message: Attribute = class_("error_message")
65892
bbad8162d678 clarified signature;
wenzelm
parents: 65891
diff changeset
   216
65939
9fb044904a4d support for message underline and tooltips;
wenzelm
parents: 65892
diff changeset
   217
  // underline
65993
75590c9a585f tuned signature;
wenzelm
parents: 65992
diff changeset
   218
  val writeln: Attribute = class_("writeln")
75590c9a585f tuned signature;
wenzelm
parents: 65992
diff changeset
   219
  val warning: Attribute = class_("warning")
75590c9a585f tuned signature;
wenzelm
parents: 65992
diff changeset
   220
  val error: Attribute = class_("error")
65892
bbad8162d678 clarified signature;
wenzelm
parents: 65891
diff changeset
   221
65944
79e4d94aa9ad tuned signature;
wenzelm
parents: 65943
diff changeset
   222
79e4d94aa9ad tuned signature;
wenzelm
parents: 65943
diff changeset
   223
  /* tooltips */
79e4d94aa9ad tuned signature;
wenzelm
parents: 65943
diff changeset
   224
79e4d94aa9ad tuned signature;
wenzelm
parents: 65943
diff changeset
   225
  def tooltip(item: XML.Body, tip: XML.Body): XML.Elem =
65992
50daca61efd6 tuned signature;
wenzelm
parents: 65991
diff changeset
   226
    span(item ::: List(div("tooltip", tip)))
65944
79e4d94aa9ad tuned signature;
wenzelm
parents: 65943
diff changeset
   227
79e4d94aa9ad tuned signature;
wenzelm
parents: 65943
diff changeset
   228
  def tooltip_errors(item: XML.Body, msgs: List[XML.Body]): XML.Elem =
79e4d94aa9ad tuned signature;
wenzelm
parents: 65943
diff changeset
   229
    HTML.error(tooltip(item, msgs.map(msg => error_message(pre(msg)))))
65892
bbad8162d678 clarified signature;
wenzelm
parents: 65891
diff changeset
   230
bbad8162d678 clarified signature;
wenzelm
parents: 65891
diff changeset
   231
66196
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   232
  /* GUI elements */
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   233
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   234
  object GUI
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   235
  {
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   236
    private def optional_value(text: String): XML.Attributes =
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   237
      proper_string(text).map(a => "value" -> a).toList
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   238
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   239
    private def optional_name(name: String): XML.Attributes =
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   240
      proper_string(name).map(a => "name" -> a).toList
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   241
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   242
    private def optional_title(tooltip: String): XML.Attributes =
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   243
      proper_string(tooltip).map(a => "title" -> a).toList
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   244
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   245
    private def optional_submit(submit: Boolean): XML.Attributes =
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   246
      if (submit) List("onChange" -> "this.form.submit()") else Nil
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   247
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   248
    private def optional_checked(selected: Boolean): XML.Attributes =
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   249
      if (selected) List("checked" -> "") else Nil
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   250
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   251
    private def optional_action(action: String): XML.Attributes =
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   252
      proper_string(action).map(a => "action" -> a).toList
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   253
66210
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   254
    private def optional_onclick(script: String): XML.Attributes =
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   255
      proper_string(script).map(a => "onclick" -> a).toList
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   256
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   257
    private def optional_onchange(script: String): XML.Attributes =
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   258
      proper_string(script).map(a => "onchange" -> a).toList
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   259
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   260
    def button(body: XML.Body, name: String = "", tooltip: String = "", submit: Boolean = false,
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   261
        script: String = ""): XML.Elem =
66196
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   262
      XML.Elem(
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   263
        Markup("button",
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   264
          List("type" -> (if (submit) "submit" else "button"), "value" -> "true") :::
66210
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   265
          optional_name(name) ::: optional_title(tooltip) ::: optional_onclick(script)), body)
66196
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   266
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   267
    def checkbox(body: XML.Body, name: String = "", tooltip: String = "", submit: Boolean = false,
66210
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   268
        selected: Boolean = false, script: String = ""): XML.Elem =
66196
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   269
      XML.elem("label",
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   270
        XML.elem(
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   271
          Markup("input",
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   272
            List("type" -> "checkbox", "value" -> "true") ::: optional_name(name) :::
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   273
              optional_title(tooltip) ::: optional_submit(submit) :::
66210
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   274
              optional_checked(selected) ::: optional_onchange(script))) :: body)
66196
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   275
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   276
    def text_field(columns: Int = 0, text: String = "", name: String = "", tooltip: String = "",
66210
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   277
        submit: Boolean = false, script: String = ""): XML.Elem =
66196
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   278
      XML.elem(Markup("input",
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   279
        List("type" -> "text") :::
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   280
          (if (columns > 0) List("size" -> columns.toString) else Nil) :::
66210
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   281
          optional_value(text) ::: optional_name(name) ::: optional_title(tooltip) :::
a8b936749300 more operations/options;
wenzelm
parents: 66209
diff changeset
   282
          optional_submit(submit) ::: optional_onchange(script)))
66196
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   283
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   284
    def parameter(text: String = "", name: String = ""): XML.Elem =
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   285
      XML.elem(
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   286
        Markup("input", List("type" -> "hidden") ::: optional_value(text) ::: optional_name(name)))
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   287
66209
3a4dfe10ab1a clarified signature;
wenzelm
parents: 66206
diff changeset
   288
    def form(body: XML.Body, name: String = "", action: String = "", http_post: Boolean = false)
3a4dfe10ab1a clarified signature;
wenzelm
parents: 66206
diff changeset
   289
        : XML.Elem =
3a4dfe10ab1a clarified signature;
wenzelm
parents: 66206
diff changeset
   290
      XML.Elem(
3a4dfe10ab1a clarified signature;
wenzelm
parents: 66206
diff changeset
   291
        Markup("form", optional_name(name) ::: optional_action(action) :::
3a4dfe10ab1a clarified signature;
wenzelm
parents: 66206
diff changeset
   292
          (if (http_post) List("method" -> "post") else Nil)), body)
66196
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   293
  }
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   294
31c9b09cc1d4 some HTML GUI elements;
wenzelm
parents: 66040
diff changeset
   295
66200
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   296
  /* GUI layout */
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   297
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   298
  object Wrap_Panel
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   299
  {
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   300
    object Alignment extends Enumeration
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   301
    {
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   302
      val left, right, center = Value
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   303
    }
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   304
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   305
    def apply(contents: List[XML.Elem], name: String = "", action: String = "",
66206
2d2082db735a clarified defaults;
wenzelm
parents: 66200
diff changeset
   306
      alignment: Alignment.Value = Alignment.right): XML.Elem =
66200
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   307
    {
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   308
      val body = Library.separate(XML.Text(" "), contents)
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   309
      GUI.form(List(div(body) + ("style" -> ("text-align: " + alignment))),
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   310
        name = name, action = action)
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   311
    }
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   312
  }
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   313
02c66b71c013 GUI layout similar to Pure/GUI/wrap_panel.scala;
wenzelm
parents: 66196
diff changeset
   314
51399
6ac3c29a300e discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents: 50707
diff changeset
   315
  /* document */
6ac3c29a300e discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents: 50707
diff changeset
   316
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   317
  val header: String =
69804
9efccbad7d42 uniform XML header;
wenzelm
parents: 69374
diff changeset
   318
    XML.header +
9efccbad7d42 uniform XML header;
wenzelm
parents: 69374
diff changeset
   319
    """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   320
<html xmlns="http://www.w3.org/1999/xhtml">"""
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   321
73129
ff9cd62d2d20 proper </html>;
wenzelm
parents: 73028
diff changeset
   322
  val footer: String = """</html>"""
ff9cd62d2d20 proper </html>;
wenzelm
parents: 73028
diff changeset
   323
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   324
  val head_meta: XML.Elem =
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   325
    XML.Elem(Markup("meta",
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   326
      List("http-equiv" -> "Content-Type", "content" -> "text/html; charset=utf-8")), Nil)
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   327
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
   328
  def output_document(head: XML.Body, body: XML.Body,
67337
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   329
    css: String = "isabelle.css",
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   330
    hidden: Boolean = true,
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   331
    structural: Boolean = true): String =
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
   332
  {
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   333
    cat_lines(
73129
ff9cd62d2d20 proper </html>;
wenzelm
parents: 73028
diff changeset
   334
      List(
ff9cd62d2d20 proper </html>;
wenzelm
parents: 73028
diff changeset
   335
        header,
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
   336
        output(
66000
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   337
          XML.elem("head", head_meta :: (if (css == "") Nil else List(style_file(css))) ::: head),
67337
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   338
          hidden = hidden, structural = structural),
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   339
        output(XML.elem("body", body),
73129
ff9cd62d2d20 proper </html>;
wenzelm
parents: 73028
diff changeset
   340
          hidden = hidden, structural = structural),
ff9cd62d2d20 proper </html>;
wenzelm
parents: 73028
diff changeset
   341
        footer))
65997
e3dc9ea67a62 output control symbols like ML version, with optionally hidden source;
wenzelm
parents: 65993
diff changeset
   342
  }
64359
27739e1d7978 more operations;
wenzelm
parents: 64356
diff changeset
   343
65838
30c2d78b5d38 tuned signature;
wenzelm
parents: 65836
diff changeset
   344
66000
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   345
  /* fonts */
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   346
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   347
  def fonts_url(): String => String =
69374
ab66951166f3 clarified "hidden" terminology;
wenzelm
parents: 69366
diff changeset
   348
    (for (entry <- Isabelle_Fonts.fonts(hidden = true))
70743
342b0a1fc86d proper file name instead of font name (amending dc9a39c3f75d);
wenzelm
parents: 69804
diff changeset
   349
     yield (entry.path.file_name -> Url.print_file(entry.path.file))).toMap
66000
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   350
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   351
  def fonts_dir(prefix: String)(ttf_name: String): String =
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   352
    prefix + "/" + ttf_name
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   353
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   354
  def fonts_css(make_url: String => String = fonts_url()): String =
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   355
  {
69360
dc9a39c3f75d more explicit Isabelle_Fonts.Entry;
wenzelm
parents: 69356
diff changeset
   356
    def font_face(entry: Isabelle_Fonts.Entry): String =
66000
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   357
      cat_lines(
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   358
        List(
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   359
          "@font-face {",
69360
dc9a39c3f75d more explicit Isabelle_Fonts.Entry;
wenzelm
parents: 69356
diff changeset
   360
          "  font-family: '" + entry.family + "';",
69366
b6dacf6eabe3 clarified signature;
wenzelm
parents: 69362
diff changeset
   361
          "  src: url('" + make_url(entry.path.file_name) + "') format('truetype');") :::
69360
dc9a39c3f75d more explicit Isabelle_Fonts.Entry;
wenzelm
parents: 69356
diff changeset
   362
        (if (entry.is_bold) List("  font-weight: bold;") else Nil) :::
dc9a39c3f75d more explicit Isabelle_Fonts.Entry;
wenzelm
parents: 69356
diff changeset
   363
        (if (entry.is_italic) List("  font-style: italic;") else Nil) :::
66000
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   364
        List("}"))
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   365
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 70743
diff changeset
   366
    ("/* Isabelle fonts */" :: Isabelle_Fonts.fonts(hidden = true).map(font_face))
69362
77c93eaf6cb7 tuned whitespace;
wenzelm
parents: 69360
diff changeset
   367
      .mkString("", "\n\n", "\n")
66000
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   368
  }
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   369
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   370
65838
30c2d78b5d38 tuned signature;
wenzelm
parents: 65836
diff changeset
   371
  /* document directory */
30c2d78b5d38 tuned signature;
wenzelm
parents: 65836
diff changeset
   372
65998
d07300e8a14d tuned signature;
wenzelm
parents: 65997
diff changeset
   373
  def isabelle_css: Path = Path.explode("~~/etc/isabelle.css")
d07300e8a14d tuned signature;
wenzelm
parents: 65997
diff changeset
   374
66000
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   375
  def write_isabelle_css(dir: Path, make_url: String => String = fonts_dir("fonts"))
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   376
  {
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   377
    File.write(dir + isabelle_css.base,
69362
77c93eaf6cb7 tuned whitespace;
wenzelm
parents: 69360
diff changeset
   378
      fonts_css(make_url) + "\n\n" + File.read(isabelle_css))
66000
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   379
  }
58aa6749ff36 generate CSS for Isabelle fonts;
wenzelm
parents: 65999
diff changeset
   380
72376
04bce3478688 clarified signature;
wenzelm
parents: 72375
diff changeset
   381
  def init_dir(dir: Path): Unit =
04bce3478688 clarified signature;
wenzelm
parents: 72375
diff changeset
   382
    write_isabelle_css(Isabelle_System.make_directory(dir))
65836
3b4877fbd9cb more systematic HTML.init_dir with css;
wenzelm
parents: 65834
diff changeset
   383
65838
30c2d78b5d38 tuned signature;
wenzelm
parents: 65836
diff changeset
   384
  def write_document(dir: Path, name: String, head: XML.Body, body: XML.Body,
69366
b6dacf6eabe3 clarified signature;
wenzelm
parents: 69362
diff changeset
   385
    css: String = isabelle_css.file_name,
67337
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   386
    hidden: Boolean = true,
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   387
    structural: Boolean = true)
65838
30c2d78b5d38 tuned signature;
wenzelm
parents: 65836
diff changeset
   388
  {
30c2d78b5d38 tuned signature;
wenzelm
parents: 65836
diff changeset
   389
    init_dir(dir)
67337
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   390
    File.write(dir + Path.basic(name),
4254cfd15b00 more tight HTML output: avoid extra lines within <pre>;
wenzelm
parents: 67336
diff changeset
   391
      output_document(head, body, css = css, hidden = hidden, structural = structural))
65838
30c2d78b5d38 tuned signature;
wenzelm
parents: 65836
diff changeset
   392
  }
33984
c54498f88a77 Basic HTML output.
wenzelm
parents:
diff changeset
   393
}