All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Thy.html.scala Maven / Gradle / Ivy

There is a newer version: 0.5
Show newest version
/*  Title:      Pure/Thy/html.scala
    Author:     Makarius

HTML presentation elements.
*/

package isabelle


object HTML
{
  /* encode text with control symbols */

  val control_decoded =
    Map(Symbol.sub_decoded -> "sub",
      Symbol.sup_decoded -> "sup",
      Symbol.bold_decoded -> "b")

  def encode(text: String): String =
  {
    val result = new StringBuilder

    def encode_char(c: Char) =
      c match {
        case '<' => result ++= "<"
        case '>' => result ++= ">"
        case '&' => result ++= "&"
        case '"' => result ++= """
        case '\'' => result ++= "'"
        case '\n' => result ++= "
" case _ => result += c } def encode_chars(s: String) = s.iterator.foreach(encode_char(_)) var control = "" for (sym <- Symbol.iterator(text)) { if (control_decoded.isDefinedAt(sym)) control = sym else { control_decoded.get(control) match { case Some(elem) if Symbol.is_controllable(sym) && sym != "\"" => result ++= ("<" + elem + ">") encode_chars(sym) result ++= ("") case _ => encode_chars(control) encode_chars(sym) } control = "" } } encode_chars(control) result.toString } /* document */ val end_document = "\n
\n\n\n" def begin_document(title: String): String = "\n" + "\n" + "\n" + "\n" + "\n" + "" + encode(title) + "\n" + "\n" + "\n" + "\n" + "\n" + "
" + "

" + encode(title) + "

\n" /* common markup elements */ 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)))) XML.string_of_tree( XML.elem("li", List(XML.Elem(Markup("a", List(("href", name + "/index.html"))), List(XML.Text(name)))) ::: descr)) + "\n" } def chapter_index(chapter: String, sessions: List[(String, String)]): String = { begin_document("Isabelle/" + chapter + " sessions") + (if (sessions.isEmpty) "" else "
    \n" + sessions.map(session_entry(_)).mkString + "
") + end_document } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy