18 Symbol.sup -> "sup", |
18 Symbol.sup -> "sup", |
19 Symbol.sup_decoded -> "sup", |
19 Symbol.sup_decoded -> "sup", |
20 Symbol.bold -> "b", |
20 Symbol.bold -> "b", |
21 Symbol.bold_decoded -> "b") |
21 Symbol.bold_decoded -> "b") |
22 |
22 |
23 def output(text: String): String = |
23 def output(text: String, s: StringBuilder) |
24 { |
24 { |
25 val result = new StringBuilder |
|
26 |
|
27 def output_char(c: Char) = |
25 def output_char(c: Char) = |
28 c match { |
26 c match { |
29 case '<' => result ++= "<" |
27 case '<' => s ++= "<" |
30 case '>' => result ++= ">" |
28 case '>' => s ++= ">" |
31 case '&' => result ++= "&" |
29 case '&' => s ++= "&" |
32 case '"' => result ++= """ |
30 case '"' => s ++= """ |
33 case '\'' => result ++= "'" |
31 case '\'' => s ++= "'" |
34 case '\n' => result ++= "<br/>" |
32 case '\n' => s ++= "<br/>" |
35 case _ => result += c |
33 case _ => s += c |
36 } |
34 } |
37 def output_chars(s: String) = s.iterator.foreach(output_char(_)) |
35 def output_chars(str: String) = str.iterator.foreach(output_char(_)) |
38 |
36 |
39 var ctrl = "" |
37 var ctrl = "" |
40 for (sym <- Symbol.iterator(text)) { |
38 for (sym <- Symbol.iterator(text)) { |
41 if (control.isDefinedAt(sym)) ctrl = sym |
39 if (control.isDefinedAt(sym)) ctrl = sym |
42 else { |
40 else { |
43 control.get(ctrl) match { |
41 control.get(ctrl) match { |
44 case Some(elem) if Symbol.is_controllable(sym) && sym != "\"" => |
42 case Some(elem) if Symbol.is_controllable(sym) && sym != "\"" => |
45 result ++= ("<" + elem + ">") |
43 s ++= ("<" + elem + ">") |
46 output_chars(sym) |
44 output_chars(sym) |
47 result ++= ("</" + elem + ">") |
45 s ++= ("</" + elem + ">") |
48 case _ => |
46 case _ => |
49 output_chars(ctrl) |
47 output_chars(ctrl) |
50 output_chars(sym) |
48 output_chars(sym) |
51 } |
49 } |
52 ctrl = "" |
50 ctrl = "" |
53 } |
51 } |
54 } |
52 } |
55 output_chars(ctrl) |
53 output_chars(ctrl) |
|
54 } |
56 |
55 |
57 result.toString |
56 def output(text: String): String = Library.make_string(output(text, _)) |
|
57 |
|
58 |
|
59 /* output XML as HTML */ |
|
60 |
|
61 def output(body: XML.Body, s: StringBuilder) |
|
62 { |
|
63 def attrib(p: (String, String)): Unit = |
|
64 { s ++= " "; s ++= p._1; s ++= "=\""; output(p._2, s); s ++= "\"" } |
|
65 def elem(markup: Markup): Unit = |
|
66 { s ++= markup.name; markup.properties.foreach(attrib) } |
|
67 def tree(t: XML.Tree): Unit = |
|
68 t match { |
|
69 case XML.Elem(markup, Nil) => |
|
70 s ++= "<"; elem(markup); s ++= "/>" |
|
71 case XML.Elem(markup, ts) => |
|
72 s ++= "<"; elem(markup); s ++= ">" |
|
73 ts.foreach(tree) |
|
74 s ++= "</"; s ++= markup.name; s ++= ">" |
|
75 case XML.Text(txt) => output(txt, s) |
|
76 } |
|
77 body.foreach(tree) |
58 } |
78 } |
|
79 |
|
80 def output(body: XML.Body): String = Library.make_string(output(body, _)) |
|
81 def output(tree: XML.Tree): String = output(List(tree)) |
|
82 |
|
83 |
|
84 /* structured markup */ |
|
85 |
|
86 def chapter(body: XML.Body): XML.Elem = XML.elem("h1", body) |
|
87 def section(body: XML.Body): XML.Elem = XML.elem("h2", body) |
|
88 def subsection(body: XML.Body): XML.Elem = XML.elem("h3", body) |
|
89 def subsubsection(body: XML.Body): XML.Elem = XML.elem("h4", body) |
|
90 def paragraph(body: XML.Body): XML.Elem = XML.elem("h5", body) |
|
91 def subparagraph(body: XML.Body): XML.Elem = XML.elem("h6", body) |
59 |
92 |
60 |
93 |
61 /* document */ |
94 /* document */ |
62 |
95 |
63 def begin_document(title: String): String = |
96 def begin_document(title: String): String = |