src/Pure/Thy/html.scala
changeset 65753 787e5ee6ef53
parent 64362 8a0fe5469ba0
child 65771 688a7dd22cbb
equal deleted inserted replaced
65752:ed7b5cd3a7f2 65753:787e5ee6ef53
    79 
    79 
    80   def output(body: XML.Body): String = Library.make_string(output(body, _))
    80   def output(body: XML.Body): String = Library.make_string(output(body, _))
    81   def output(tree: XML.Tree): String = output(List(tree))
    81   def output(tree: XML.Tree): String = output(List(tree))
    82 
    82 
    83 
    83 
       
    84   /* attributes */
       
    85 
       
    86   def id(s: String): Properties.Entry = ("id" -> s)
       
    87 
       
    88 
    84   /* structured markup operators */
    89   /* structured markup operators */
    85 
    90 
    86   def text(txt: String): XML.Body = if (txt.isEmpty) Nil else List(XML.Text(txt))
    91   def text(txt: String): XML.Body = if (txt.isEmpty) Nil else List(XML.Text(txt))
       
    92   val break: XML.Body = List(XML.elem("br"))
    87 
    93 
    88   class Operator(name: String)
    94   class Operator(name: String)
    89   { def apply(body: XML.Body): XML.Elem = XML.elem(name, body) }
    95   { def apply(body: XML.Body): XML.Elem = XML.elem(name, body) }
    90 
    96 
    91   class Heading(name: String) extends Operator(name)
    97   class Heading(name: String) extends Operator(name)
    92   { def apply(txt: String): XML.Elem = super.apply(text(txt)) }
    98   { def apply(txt: String): XML.Elem = super.apply(text(txt)) }
    93 
    99 
    94   val div = new Operator("div")
   100   val div = new Operator("div")
    95   val span = new Operator("span")
   101   val span = new Operator("span")
       
   102   val pre = new Operator("pre")
    96   val par = new Operator("p")
   103   val par = new Operator("p")
    97   val emph = new Operator("em")
   104   val emph = new Operator("em")
    98   val bold = new Operator("b")
   105   val bold = new Operator("b")
    99 
   106 
   100   val title = new Heading("title")
   107   val title = new Heading("title")
   114   def description(items: List[(XML.Body, XML.Body)]): XML.Elem =
   121   def description(items: List[(XML.Body, XML.Body)]): XML.Elem =
   115     XML.elem("dl", items.flatMap({ case (x, y) => List(XML.elem("dt", x), XML.elem("dd", y)) }))
   122     XML.elem("dl", items.flatMap({ case (x, y) => List(XML.elem("dt", x), XML.elem("dd", y)) }))
   116 
   123 
   117   def link(href: String, body: XML.Body = Nil): XML.Elem =
   124   def link(href: String, body: XML.Body = Nil): XML.Elem =
   118     XML.Elem(Markup("a", List("href" -> href)), if (body.isEmpty) text(href) else body)
   125     XML.Elem(Markup("a", List("href" -> href)), if (body.isEmpty) text(href) else body)
       
   126 
       
   127   def image(src: String, alt: String = ""): XML.Elem =
       
   128     XML.Elem(Markup("img", List("src" -> src) ::: proper_string(alt).map("alt" -> _).toList), Nil)
   119 
   129 
   120 
   130 
   121   /* document */
   131   /* document */
   122 
   132 
   123   val header: String =
   133   val header: String =
   155   /* common markup elements */
   165   /* common markup elements */
   156 
   166 
   157   private def session_entry(entry: (String, String)): String =
   167   private def session_entry(entry: (String, String)): String =
   158   {
   168   {
   159     val (name, description) = entry
   169     val (name, description) = entry
   160     val descr =
   170     val descr = if (description == "") Nil else break ::: List(pre(text(description)))
   161       if (description == "") Nil
       
   162       else List(XML.elem("br"), XML.elem("pre", List(XML.Text(description))))
       
   163     XML.string_of_tree(
   171     XML.string_of_tree(
   164       XML.elem("li",
   172       XML.elem("li",
   165         List(XML.Elem(Markup("a", List(("href", name + "/index.html"))),
   173         List(XML.Elem(Markup("a", List(("href", name + "/index.html"))),
   166           List(XML.Text(name)))) ::: descr)) + "\n"
   174           List(XML.Text(name)))) ::: descr)) + "\n"
   167   }
   175   }