added ability to keep '<>' without formatting content unchanged

This commit is contained in:
Jakub Trllo 2022-08-03 18:28:40 +02:00
parent c4fce5fea9
commit 8f5360d9d5

View file

@ -211,15 +211,28 @@ class StringTemplate(object):
if counted_symb > -1:
parts = tmp_parts.pop(counted_symb)
counted_symb -= 1
# If part contains only single string keep value
# unchanged
if parts:
# Remove optional start char
parts.pop(0)
if counted_symb < 0:
out_parts = new_parts
else:
out_parts = tmp_parts[counted_symb]
# Store temp parts
out_parts.append(OptionalPart(parts))
if not parts:
value = "<>"
elif (
len(parts) == 1
and isinstance(parts[0], six.string_types)
):
value = "<{}>".format(parts[0])
else:
value = OptionalPart(parts)
if counted_symb < 0:
out_parts = new_parts
else:
out_parts = tmp_parts[counted_symb]
# Store value
out_parts.append(value)
continue
if counted_symb < 0:
@ -793,6 +806,7 @@ class OptionalPart:
parts(list): Parts of template. Can contain 'str', 'OptionalPart' or
'FormattingPart'.
"""
def __init__(self, parts):
self._parts = parts