diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/xml/Utility.scala | 25 | ||||
-rw-r--r-- | src/library/scala/xml/Xhtml.scala | 10 |
2 files changed, 20 insertions, 15 deletions
diff --git a/src/library/scala/xml/Utility.scala b/src/library/scala/xml/Utility.scala index 48a23dc389..8637148489 100644 --- a/src/library/scala/xml/Utility.scala +++ b/src/library/scala/xml/Utility.scala @@ -194,22 +194,24 @@ object Utility extends AnyRef with parsing.TokenTests minimizeTags: Boolean = false): StringBuilder = { x match { - case c: Comment if !stripComments => c buildString sb - case x: SpecialNode => x buildString sb - case g: Group => for (c <- g.nodes) toXML(c, x.scope, sb) ; sb + case c: Comment => if (!stripComments) c buildString sb else sb + case x: SpecialNode => x buildString sb + case g: Group => + g.nodes foreach {toXML(_, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)} + sb case _ => // print tag with namespace declarations sb.append('<') x.nameToString(sb) if (x.attributes ne null) x.attributes.buildString(sb) x.scope.buildString(sb, pscope) - if (x.child.isEmpty && minimizeTags) + if (x.child.isEmpty && minimizeTags) { // no children, so use short form: <xyz .../> sb.append(" />") - else { + } else { // children, so use long form: <xyz ...>...</xyz> sb.append('>') - sequenceToXML(x.child, x.scope, sb, stripComments) + sequenceToXML(x.child, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) sb.append("</") x.nameToString(sb) sb.append('>') @@ -221,20 +223,23 @@ object Utility extends AnyRef with parsing.TokenTests children: Seq[Node], pscope: NamespaceBinding = TopScope, sb: StringBuilder = new StringBuilder, - stripComments: Boolean = false): Unit = + stripComments: Boolean = false, + decodeEntities: Boolean = true, + preserveWhitespace: Boolean = false, + minimizeTags: Boolean = false): Unit = { if (children.isEmpty) return else if (children forall isAtomAndNotText) { // add space val it = children.iterator val f = it.next - toXML(f, pscope, sb) + toXML(f, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) while (it.hasNext) { val x = it.next sb.append(' ') - toXML(x, pscope, sb) + toXML(x, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) } } - else children foreach { toXML(_, pscope, sb) } + else children foreach { toXML(_, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) } } /** diff --git a/src/library/scala/xml/Xhtml.scala b/src/library/scala/xml/Xhtml.scala index 744fe260c2..162ea5696a 100644 --- a/src/library/scala/xml/Xhtml.scala +++ b/src/library/scala/xml/Xhtml.scala @@ -49,11 +49,11 @@ object Xhtml (minimizableElements contains x.label) x match { - case c: Comment if !stripComments => c buildString sb + case c: Comment => if (!stripComments) c buildString sb case er: EntityRef if decodeEntities => decode(er) case x: SpecialNode => x buildString sb case g: Group => - g.nodes foreach { toXhtml(_, x.scope, sb) } + g.nodes foreach { toXhtml(_, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) } case _ => sb.append('<') @@ -64,7 +64,7 @@ object Xhtml if (shortForm) sb.append(" />") else { sb.append('>') - sequenceToXML(x.child, x.scope, sb) + sequenceToXML(x.child, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) sb.append("</") x.nameToString(sb) sb.append('>') @@ -89,9 +89,9 @@ object Xhtml val doSpaces = children forall isAtomAndNotText // interleave spaces for (c <- children.take(children.length - 1)) { - toXhtml(c, pscope, sb) + toXhtml(c, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) if (doSpaces) sb append ' ' } - toXhtml(children.last, pscope, sb) + toXhtml(children.last, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) } } |