Remove the whitespace which pretty-printing put between an element's tags.
XML written by hand (or via the stx template literal) is usually indented,
and parsing it turns each run of indentation into a text node. Those
whitespace-only text nodes are formatting, not content, so they're removed.
Whitespace which is content is kept:
An element whose only child is a text node keeps it, so <body> </body>
survives intact.
A subtree marked xml:space="preserve" is left alone, per XML 1.0 ยง 2.10,
until a descendant sets xml:space="default" again.
An XHTML-IM <body>, the one in the XHTML namespace, is left alone, since
the whitespace between its inline elements separates words rather than
laying them out, unless it sets xml:space="default".
Anything keep claims, which is how a caller which knows more than this
function does says so.
Kept out of utils because everything utils exports is spread onto the
Strophe object, and keep and preserve are internal rather than public
API. stripWhitespace is the public entry point.
Parameters
el: Element
keep: (node:Node)=>boolean
Whether a whitespace-only text node is content after all.
preserve: boolean = false
Whether an ancestor asked for whitespace to be preserved.
Only the recursion passes this.
Remove the whitespace which pretty-printing put between an element's tags.
XML written by hand (or via the
stxtemplate literal) is usually indented, and parsing it turns each run of indentation into a text node. Those whitespace-only text nodes are formatting, not content, so they're removed. Whitespace which is content is kept:<body> </body>survives intact.xml:space="preserve"is left alone, per XML 1.0 ยง 2.10, until a descendant setsxml:space="default"again.<body>, the one in the XHTML namespace, is left alone, since the whitespace between its inline elements separates words rather than laying them out, unless it setsxml:space="default".keepclaims, which is how a caller which knows more than this function does says so.Kept out of
utilsbecause everythingutilsexports is spread onto theStropheobject, andkeepandpreserveare internal rather than public API. stripWhitespace is the public entry point.