TobiasNickel / tXml

:zap:very small and fast xml-parser in pure javascript:zap:
MIT License
217 stars 28 forks source link

Also parse comments #15

Closed strarsis closed 3 years ago

strarsis commented 4 years ago

It would be nice to have an option to parse comments, too. Sometimes comments in the AST can be useful. As an optional option, this wouldn't unnecessarily impede performance.

TobiasNickel commented 4 years ago

sounds good, I will have some test.

we can keep the content as text in the children array, but it would not be identifyable as comment. it could be an object like {comment: 'content'}, but it might break some other code in simplify transformations as the object is not a node.

Not sure now, what the best solution is, maybe it would require a breaking change. what can be ok to make a version 4.

TobiasNickel commented 3 years ago

you can now pass an option into the parser o txml.parse(text, {keepComments: true}).

then comments are returned as string. It is possible to see if a string was a comment with s.startsWith('<!--') && s.endsWith('-->).