98 } |
98 } |
99 |
99 |
100 |
100 |
101 /* no formatting */ |
101 /* no formatting */ |
102 |
102 |
|
103 def output_content(pure: Boolean, output: XML.Body): String = |
|
104 XML.content(if (pure) Protocol_Message.clean_output(output) else output) |
|
105 |
103 def unbreakable(input: XML.Body): XML.Body = |
106 def unbreakable(input: XML.Body): XML.Body = |
104 input flatMap { |
107 input flatMap { |
105 case XML.Wrapped_Elem(markup, body1, body2) => |
108 case XML.Wrapped_Elem(markup, body1, body2) => |
106 List(XML.Wrapped_Elem(markup, body1, unbreakable(body2))) |
109 List(XML.Wrapped_Elem(markup, body1, unbreakable(body2))) |
107 case XML.Elem(Markup.Break(width, _), _) => spaces(width) |
110 case XML.Elem(Markup.Break(width, _), _) => spaces(width) |
108 case XML.Elem(markup, body) => List(XML.Elem(markup, unbreakable(body))) |
111 case XML.Elem(markup, body) => List(XML.Elem(markup, unbreakable(body))) |
109 case XML.Text(text) => XML.string(split_lines(text).mkString(Symbol.space)) |
112 case XML.Text(text) => XML.string(split_lines(text).mkString(Symbol.space)) |
110 } |
113 } |
111 |
114 |
112 def unformatted_string_of(input: XML.Body): String = |
115 def unformatted_string_of(input: XML.Body, pure: Boolean = false): String = |
113 XML.content(unbreakable(input)) |
116 output_content(pure, unbreakable(input)) |
114 |
117 |
115 |
118 |
116 /* formatting */ |
119 /* formatting */ |
117 |
120 |
118 private sealed case class Text(tx: XML.Body = Nil, pos: Double = 0.0, nl: Int = 0) { |
121 private sealed case class Text(tx: XML.Body = Nil, pos: Double = 0.0, nl: Int = 0) { |
205 } |
208 } |
206 format(make_tree(input), 0, 0.0, Text()).content |
209 format(make_tree(input), 0, 0.0, Text()).content |
207 } |
210 } |
208 |
211 |
209 def string_of(input: XML.Body, |
212 def string_of(input: XML.Body, |
210 margin: Double = default_margin, |
213 margin: Double = default_margin, |
211 breakgain: Double = default_breakgain, |
214 breakgain: Double = default_breakgain, |
212 metric: Metric = Default_Metric): String = |
215 metric: Metric = Default_Metric, |
213 XML.content(formatted(input, margin = margin, breakgain = breakgain, metric = metric)) |
216 pure: Boolean = false |
|
217 ): String = { |
|
218 output_content(pure, formatted(input, margin = margin, breakgain = breakgain, metric = metric)) |
|
219 } |
214 } |
220 } |