Strip newlines from text nodes and be done with it

Follow the spec "blindly" as it turns out covering all the border
and getting reasonably styled output is just to cumbersome.
This way at least scour output is consistent and it also saves us
some bytes (a lot in some cases as we do not indent <tspan>s etc.
anymore)
This commit is contained in:
Eduard Braun 2018-07-02 22:14:14 +02:00
parent 2200f8dc81
commit 703122369e

View file

@ -3356,8 +3356,8 @@ def serializeXML(element, options, indent_depth=0, preserveWhitespace=False):
if not preserveWhitespace: if not preserveWhitespace:
# strip / consolidate whitespace according to spec, see # strip / consolidate whitespace according to spec, see
# https://www.w3.org/TR/SVG/text.html#WhiteSpace # https://www.w3.org/TR/SVG/text.html#WhiteSpace
# As a workaround for inconsistent handling of renderers keep newlines if they were in the original
if element.nodeName in ['text', 'tspan', 'tref', 'textPath', 'altGlyph']: if element.nodeName in ['text', 'tspan', 'tref', 'textPath', 'altGlyph']:
text_content = text_content.replace('\n', '')
text_content = text_content.replace('\t', ' ') text_content = text_content.replace('\t', ' ')
if child == element.firstChild: if child == element.firstChild:
text_content = text_content.lstrip() text_content = text_content.lstrip()