oozcitak / xmlbuilder2

An XML builder for node.js
366 stars 36 forks source link

Adjustment to spaceBeforeSlash to add a spaceBeforeSlash only if the tag has attributes? #132

Open jasonkhanlar opened 2 years ago

jasonkhanlar commented 2 years ago

Is your feature request related to a problem? Please describe. Adjustment to spaceBeforeSlash to add a spaceBeforeSlash only if the tag has attributes

Describe the solution you'd like

<namespace key="0" case="first-letter" /> // space before slash here (okay)
<text bytes="0" sha1="phoiac9h4m842xq45sp7s6u21eteeq1" xml:space="preserve" /> // space before slash here (okay)
<minor/> // do not add a space before slash here (not possible yet)

Describe alternatives you've considered I can write my own post processing code to handle this, but I thought I'd mention it as a feature suggestion also.

Additional context

jasonkhanlar commented 2 years ago

Note that rather than this ""feature"" idea being built in to the library, I whipped up this code to match what appears to be hard-coded inconsistency in MediaWiki Special:Export XML dumps (and as far as this point in time, I haven't found any further inconsistency than these two instances: "minor/sha1" tags):

xmlbuilder2.convert(
  { keepEntityCharRefs: true },
  xmlobj,
  { format: 'xml', prettyPrint: true, spaceBeforeSlash: true })
.replace(/<(minor|sha1) \/>/g, '<$1/>');