support Pretty.unformatted, similar to ML version;
authorwenzelm
Thu, 08 Sep 2022 16:22:44 +0200
changeset 76086 338adf8d423c
parent 76085 3f5028b54419
child 76087 c8f5fec36b5c
support Pretty.unformatted, similar to ML version;
src/Pure/General/pretty.scala
--- a/src/Pure/General/pretty.scala	Thu Sep 08 13:16:46 2022 +0200
+++ b/src/Pure/General/pretty.scala	Thu Sep 08 16:22:44 2022 +0200
@@ -92,6 +92,23 @@
   }
 
 
+  /* unformatted output */
+
+  def unformatted(input: XML.Body): XML.Body = {
+    input flatMap {
+      case XML.Wrapped_Elem(markup, body1, body2) =>
+        List(XML.Wrapped_Elem(markup, body1, unformatted(body2)))
+      case XML.Elem(markup, body) =>
+        markup match {
+          case Markup.Block(_, _) => unformatted(body)
+          case Markup.Break(width, _) => XML.string(Symbol.spaces(width))
+          case _ => List(XML.Elem(markup, unformatted(body)))
+        }
+      case XML.Text(text) => XML.string(split_lines(text).mkString(Symbol.space))
+    }
+  }
+
+
   /* formatted output */
 
   private sealed case class Text(tx: XML.Body = Nil, pos: Double = 0.0, nl: Int = 0) {