3 |
3 |
4 Basic HTML output. |
4 Basic HTML output. |
5 */ |
5 */ |
6 |
6 |
7 package isabelle |
7 package isabelle |
|
8 |
|
9 import scala.collection.mutable.ListBuffer |
|
10 |
8 |
11 |
9 object HTML |
12 object HTML |
10 { |
13 { |
11 // common elements and attributes |
14 // common elements and attributes |
12 |
15 |
13 val BODY = "body" |
16 val BODY = "body" |
14 val DIV = "div" |
17 val DIV = "div" |
15 val SPAN = "span" |
18 val SPAN = "span" |
16 val BR = "br" |
19 val BR = "br" |
|
20 val PRE = "pre" |
17 val CLASS = "class" |
21 val CLASS = "class" |
18 |
22 |
19 |
23 |
20 // document markup |
24 // document markup |
21 |
25 |
22 def body(trees: List[XML.Tree]): XML.Tree = |
|
23 XML.Elem(BODY, Nil, trees) |
|
24 |
|
25 def div(trees: List[XML.Tree]): XML.Tree = |
|
26 XML.Elem(DIV, Nil, trees) |
|
27 |
|
28 val br: XML.Tree = XML.Elem(BR, Nil, Nil) |
|
29 |
|
30 def spans(tree: XML.Tree): List[XML.Tree] = |
26 def spans(tree: XML.Tree): List[XML.Tree] = |
31 tree match { |
27 tree match { |
32 case XML.Elem(name, _, ts) => |
28 case XML.Elem(name, _, ts) => |
33 List(XML.Elem(SPAN, List((CLASS, name)), ts.flatMap(spans))) |
29 List(XML.Elem(SPAN, List((CLASS, name)), ts.flatMap(spans))) |
34 case text @ XML.Text(txt) => |
30 case XML.Text(txt) => |
35 txt.split("\n").toList match { |
31 val ts = new ListBuffer[XML.Tree] |
36 case line :: lines if !lines.isEmpty => |
32 val t = new StringBuilder |
37 XML.Text(line) :: lines.flatMap(l => List(br, XML.Text(l))) |
33 def flush_text() { |
38 case _ => List(text) |
34 if (!t.isEmpty) { |
|
35 ts + XML.Text(t.toString) |
|
36 t.clear |
|
37 } |
39 } |
38 } |
|
39 for (sym <- Symbol.elements(txt)) { |
|
40 sym match { |
|
41 case "\n" => |
|
42 flush_text() |
|
43 ts + XML.elem(BR) |
|
44 case _ => |
|
45 t ++ sym.toString |
|
46 } |
|
47 } |
|
48 flush_text() |
|
49 ts.toList |
40 } |
50 } |
41 } |
51 } |