dart-lang / tools

This repository is home to tooling related Dart packages.
BSD 3-Clause "New" or "Revised" License
31 stars 24 forks source link

always include a \n in outerHtml #1092

Open sigmundch opened 9 years ago

sigmundch commented 9 years ago

seems to be commonly the case that you want it when dumping code to a file.

jakemac53 commented 9 years ago

It would be nice to have proper indentation as well

jmesserly commented 9 years ago

It would be nice to have proper indentation as well

that's a bit more tricky. outerHTML currently follows spec for all nodes. Document does not actually have outerHTML (in spec), so it seemed okay to add a newline as part of how document prints itself, and it wouldn't have any effect when you parse it back (text after document doesn't count). But indentation would actually change tree structure, resulting in extra text nodes.

If you want a pretty printer, it's not hard to do, CodeMarkupVisitor probably serves as a good example: https://github.com/dart-lang/html5lib/blob/master/lib/dom_parsing.dart#L56

It's just worth noting that changing indentation could in theory break the application.

jmesserly commented 9 years ago

and perhaps we should remove outerHTML from document, and add a different printer API, so we don't have non-standard APIs on the DOM nodes.

jakemac53 commented 9 years ago

sounds good, +1 for a separate printer api