Comment 2 for bug 1697296

Revision history for this message
Akkana Peck (akkzilla) wrote : Re: Putting two NavigableStrings next to each other doesn't merge them

Thanks for the thoughtful response. I understand your concern about unintended consequences -- you're right, there could be some -- and in writing this response, I keep switching sides and convincing myself one way or the other.

In the end, though, I keep coming back to this: if you have a page showing on your browser, and you read in the source with BS, print it with prettify() and view the result in another browser tab, shouldn't the tabs look identical? If they don't, then prettify becomes merely a debugging tool, but you can't trust it as a prettyprinter for final HTML output since it might change the document.

One other, slightly more technical argument: whitespace nodes, even if they're not tags, are part of the structure of a document as far as browsers are concerned -- at least, in the gecko layout/DOM engine, the only browser code I'm familiar with, whitespace nodes are nodes inline with text nodes and treated similarly to them. Of course, the whole point of prettify() is to add whitespace, so it will necessarily change that aspect of the document's structure which maybe makes that argument moot.

I do understand your reservations, though. And probably what I should do in the long run is take the quickie prettyprinter I hacked up when I first encountered this bug, clean it up and use it as a module so I don't need to worry about prettify(). I prefer not to have newlines around inline nodes like <b> anyway, so it probably makes the most sense to have my own customizable version.