src/Pure/Thy/html.scala
author wenzelm
Mon, 11 Feb 2013 14:39:04 +0100
changeset 51085 d90218288d51
parent 50707 5b2bf7611662
child 51399 6ac3c29a300e
permissions -rw-r--r--
make WWW_Find work again, now that its ML modules reside within a theory context (cf. bf5b45870110) -- patch by Rafal Kolanski;

/*  Title:      Pure/Thy/html.scala
    Author:     Makarius

HTML presentation elements.
*/

package isabelle

import scala.collection.mutable.ListBuffer


object HTML
{
  // encode text

  def encode(text: String): String =
  {
    val s = new StringBuilder
    for (c <- text.iterator) c match {
      case '<' => s ++= "&lt;"
      case '>' => s ++= "&gt;"
      case '&' => s ++= "&amp;"
      case '"' => s ++= "&quot;"
      case '\'' => s ++= "&#39;"
      case '\n' => s ++= "<br/>"
      case _ => s += c
    }
    s.toString
  }


  // common markup elements

  def session_entry(name: String): String =
    XML.string_of_tree(
      XML.elem("li",
        List(XML.Elem(Markup("a", List(("href", name + "/index.html"))),
          List(XML.Text(name)))))) + "\n"

  def session_entries(names: List[String]): String =
    if (names.isEmpty) "</ul>"
    else
      "</ul>\n</div>\n<div class=\"sessions\">\n" +
      "<h2>Sessions</h2>\n<ul>\n" + names.map(session_entry).mkString + "</ul>";

  val end_document = "\n</div>\n</body>\n</html>\n"
}