
Frederik Elwert schrieb am 18.07.19 um 11:01:
The issue here is that lxml uses some kind of heuristic to determine if the whitespace already present in a document is meaningful and should be preserved as is, or if it can be changed during prettyprinting.
Correct. Here is an example: … <x>hel</x><y>lo</y> … In this case, adding a newline between the "x" and "y" tags would cut the word "hello" in two, and that is something that the heuristic tries to avoid. But, if you set the tail text of the "x" tag above to some whitespace string (space, newline, etc.), then it can't hurt much to insert a newline and further indentation in this spot, so the pretty-printer would do that. This is pretty much what happens when new tags are inserted that do not have any tail text set, which is why the pretty-printer handles them more carefully. Stefan