Skip to content

Commit fb77228

Browse files
authored
Merge pull request #70 from mitya57/python3.8
Sort element attrbutes
2 parents 012b308 + 0edfeda commit fb77228

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

textile/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ def generate_tag(tag, content, attributes=None):
4949
if not tag:
5050
return content
5151
element = ElementTree.Element(tag, attrib=attributes)
52+
# Sort attributes for Python 3.8+, as suggested in
53+
# https://docs.python.org/3/library/xml.etree.elementtree.html
54+
if len(element.attrib) > 1:
55+
# adjust attribute order, e.g. by sorting
56+
attribs = sorted(element.attrib.items())
57+
element.attrib.clear()
58+
element.attrib.update(attribs)
5259
# FIXME: Kind of an ugly hack. There *must* be a cleaner way. I tried
5360
# adding text by assigning it to element_tag.text. That results in
5461
# non-ascii text being html-entity encoded. Not bad, but not entirely

0 commit comments

Comments
 (0)