21 val CLASS = "class" |
21 val CLASS = "class" |
22 |
22 |
23 |
23 |
24 // document markup |
24 // document markup |
25 |
25 |
|
26 def span(cls: String, body: List[XML.Tree]): XML.Elem = |
|
27 XML.Elem(SPAN, List((CLASS, cls)), body) |
|
28 |
|
29 def hidden(txt: String): XML.Elem = |
|
30 span(Markup.HIDDEN, List(XML.Text(txt))) |
|
31 |
|
32 def sub(txt: String): XML.Elem = XML.elem("sub", List(XML.Text(txt))) |
|
33 def sup(txt: String): XML.Elem = XML.elem("sup", List(XML.Text(txt))) |
|
34 |
26 def spans(tree: XML.Tree): List[XML.Tree] = |
35 def spans(tree: XML.Tree): List[XML.Tree] = |
27 tree match { |
36 tree match { |
28 case XML.Elem(name, _, ts) => |
37 case XML.Elem(name, _, ts) => List(span(name, ts.flatMap(spans))) |
29 List(XML.Elem(SPAN, List((CLASS, name)), ts.flatMap(spans))) |
|
30 case XML.Text(txt) => |
38 case XML.Text(txt) => |
31 val ts = new ListBuffer[XML.Tree] |
39 val ts = new ListBuffer[XML.Tree] |
32 val t = new StringBuilder |
40 val t = new StringBuilder |
33 def flush_text() { |
41 def flush() { |
34 if (!t.isEmpty) { |
42 if (!t.isEmpty) { |
35 ts + XML.Text(t.toString) |
43 ts + XML.Text(t.toString) |
36 t.clear |
44 t.clear |
37 } |
45 } |
38 } |
46 } |
39 for (sym <- Symbol.elements(txt)) { |
47 def add(elem: XML.Tree) { |
40 sym match { |
48 flush() |
41 case "\n" => |
49 ts + elem |
42 flush_text() |
50 } |
43 ts + XML.elem(BR) |
51 val syms = Symbol.elements(txt) |
44 case _ => |
52 while (syms.hasNext) { |
45 t ++ sym.toString |
53 val s1 = syms.next |
|
54 lazy val s2 = if (syms.hasNext) syms.next else "" |
|
55 s1 match { |
|
56 case "\n" => add(XML.elem(BR)) |
|
57 case "\\<^bsub>" => t ++ s1 // FIXME |
|
58 case "\\<^esub>" => t ++ s1 // FIXME |
|
59 case "\\<^bsup>" => t ++ s1 // FIXME |
|
60 case "\\<^esup>" => t ++ s1 // FIXME |
|
61 case "\\<^sub>" | "\\<^isub>" => add(hidden(s1)); add(sub(s2)) |
|
62 case "\\<^sup>" | "\\<^isup>" => add(hidden(s1)); add(sup(s2)) |
|
63 case "\\<^bold>" => add(hidden(s1)); add(span("bold", List(XML.Text(s2)))) |
|
64 case "\\<^loc>" => add(hidden(s2)); add(span("loc", List(XML.Text(s2)))) |
|
65 case _ => t ++ s1 |
46 } |
66 } |
47 } |
67 } |
48 flush_text() |
68 flush() |
49 ts.toList |
69 ts.toList |
50 } |
70 } |
51 } |
71 } |