html icon indicating copy to clipboard operation
html copied to clipboard

always include a \n in outerHtml

Open sigmundch opened this issue 10 years ago • 4 comments

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

sigmundch avatar Feb 19 '15 00:02 sigmundch

It would be nice to have proper indentation as well

jakemac53 avatar Feb 19 '15 01:02 jakemac53

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 avatar Mar 05 '15 17:03 jmesserly

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.

jmesserly avatar Mar 05 '15 17:03 jmesserly

sounds good, +1 for a separate printer api

jakemac53 avatar Mar 05 '15 18:03 jakemac53