matthewmatician / xml-flow

An XML/HTML stream reader, now with less suck!
MIT License
55 stars 18 forks source link

`simplifyNodes = false` affects only the top-level node #42

Open DrMurx opened 11 months ago

DrMurx commented 11 months ago

With useArray = SOMETIMES and preserveMarkup = SOMETIMES, a setting of simplifyNodes = false doesn't behave as expected. It affects on the emitted top-level node, while all sub-nodes are still simplified.

For example:

<top class="x">
  <sub type="a" />
  <sub type="b" />
</top>

will result in

top: {
  $attrs: { class: "x" },
  sub: [
    { type: "a" },
    { type: "b"}
  ]
}

but I'd expect

top: {
  $attrs: { class: "x" },
  sub: [
    {
      $attrs: { type: "a" }
    },
    {
      $attrs: { type: "b" }
    }
  ]
}

(It's also debatable whether the entries in the sub array should be stripped of their $name key - even if it's redundant, it wouldn't hurt)