more operations;
authorwenzelm
Sun, 07 May 2017 16:04:19 +0200
changeset 65753 787e5ee6ef53
parent 65752 ed7b5cd3a7f2
child 65754 05c6a29c9132
more operations; tuned;
src/Pure/PIDE/markup.scala
src/Pure/PIDE/xml.scala
src/Pure/Thy/html.scala
--- a/src/Pure/PIDE/markup.scala	Sun May 07 13:42:20 2017 +0200
+++ b/src/Pure/PIDE/markup.scala	Sun May 07 16:04:19 2017 +0200
@@ -634,4 +634,7 @@
   def update_properties(more_props: Properties.T): Markup =
     if (more_props.isEmpty) this
     else Markup(name, (more_props :\ properties) { case (p, ps) => Properties.put(ps, p) })
+
+  def + (entry: Properties.Entry): Markup =
+    Markup(name, Properties.put(properties, entry))
 }
--- a/src/Pure/PIDE/xml.scala	Sun May 07 13:42:20 2017 +0200
+++ b/src/Pure/PIDE/xml.scala	Sun May 07 16:04:19 2017 +0200
@@ -18,6 +18,7 @@
 
   /* datatype representation */
 
+  type Attribute = Properties.Entry
   type Attributes = Properties.T
 
   sealed abstract class Tree { override def toString: String = string_of_tree(this) }
@@ -25,9 +26,12 @@
   case class Elem(markup: Markup, body: Body) extends Tree
   {
     def name: String = markup.name
+
     def update_attributes(more_attributes: Attributes): Elem =
       if (more_attributes.isEmpty) this
       else Elem(markup.update_properties(more_attributes), body)
+
+    def + (att: Attribute): Tree = Elem(markup + att, body)
   }
   case class Text(content: String) extends Tree
 
--- a/src/Pure/Thy/html.scala	Sun May 07 13:42:20 2017 +0200
+++ b/src/Pure/Thy/html.scala	Sun May 07 16:04:19 2017 +0200
@@ -81,9 +81,15 @@
   def output(tree: XML.Tree): String = output(List(tree))
 
 
+  /* attributes */
+
+  def id(s: String): Properties.Entry = ("id" -> s)
+
+
   /* structured markup operators */
 
   def text(txt: String): XML.Body = if (txt.isEmpty) Nil else List(XML.Text(txt))
+  val break: XML.Body = List(XML.elem("br"))
 
   class Operator(name: String)
   { def apply(body: XML.Body): XML.Elem = XML.elem(name, body) }
@@ -93,6 +99,7 @@
 
   val div = new Operator("div")
   val span = new Operator("span")
+  val pre = new Operator("pre")
   val par = new Operator("p")
   val emph = new Operator("em")
   val bold = new Operator("b")
@@ -117,6 +124,9 @@
   def link(href: String, body: XML.Body = Nil): XML.Elem =
     XML.Elem(Markup("a", List("href" -> href)), if (body.isEmpty) text(href) else body)
 
+  def image(src: String, alt: String = ""): XML.Elem =
+    XML.Elem(Markup("img", List("src" -> src) ::: proper_string(alt).map("alt" -> _).toList), Nil)
+
 
   /* document */
 
@@ -157,9 +167,7 @@
   private def session_entry(entry: (String, String)): String =
   {
     val (name, description) = entry
-    val descr =
-      if (description == "") Nil
-      else List(XML.elem("br"), XML.elem("pre", List(XML.Text(description))))
+    val descr = if (description == "") Nil else break ::: List(pre(text(description)))
     XML.string_of_tree(
       XML.elem("li",
         List(XML.Elem(Markup("a", List(("href", name + "/index.html"))),