Fix whitespace handling for SVG 1.2 flowed text
See 718748ff22
Fixes https://github.com/scour-project/scour/issues/235
This commit is contained in:
parent
f65ca60809
commit
40753af88a
1 changed files with 6 additions and 2 deletions
|
|
@ -3354,6 +3354,10 @@ def chooseQuoteCharacter(str):
|
||||||
return (quote, hasEmbeddedQuote)
|
return (quote, hasEmbeddedQuote)
|
||||||
|
|
||||||
|
|
||||||
|
TEXT_CONTENT_ELEMENTS = ['text', 'tspan', 'tref', 'textPath', 'altGlyph',
|
||||||
|
'flowDiv', 'flowPara', 'flowSpan', 'flowTref', 'flowLine']
|
||||||
|
|
||||||
|
|
||||||
# hand-rolled serialization function that has the following benefits:
|
# hand-rolled serialization function that has the following benefits:
|
||||||
# - pretty printing
|
# - pretty printing
|
||||||
# - somewhat judicious use of whitespace
|
# - somewhat judicious use of whitespace
|
||||||
|
|
@ -3437,7 +3441,7 @@ def serializeXML(element, options, indent_depth=0, preserveWhitespace=False):
|
||||||
# "text1\ntext2" and
|
# "text1\ntext2" and
|
||||||
# "text1\n text2"
|
# "text1\n text2"
|
||||||
# see https://www.w3.org/TR/SVG/text.html#WhiteSpace
|
# see https://www.w3.org/TR/SVG/text.html#WhiteSpace
|
||||||
if preserveWhitespace or element.nodeName in ['text', 'tspan', 'tref', 'textPath', 'altGlyph']:
|
if preserveWhitespace or element.nodeName in TEXT_CONTENT_ELEMENTS:
|
||||||
outParts.append(serializeXML(child, options, 0, preserveWhitespace))
|
outParts.append(serializeXML(child, options, 0, preserveWhitespace))
|
||||||
else:
|
else:
|
||||||
outParts.extend([newline, serializeXML(child, options, indent_depth + 1, preserveWhitespace)])
|
outParts.extend([newline, serializeXML(child, options, indent_depth + 1, preserveWhitespace)])
|
||||||
|
|
@ -3448,7 +3452,7 @@ 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
|
||||||
if element.nodeName in ['text', 'tspan', 'tref', 'textPath', 'altGlyph']:
|
if element.nodeName in TEXT_CONTENT_ELEMENTS:
|
||||||
text_content = text_content.replace('\n', '')
|
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:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue