aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--screenplain/export/fdx.py2
-rw-r--r--screenplain/richstring.py8
2 files changed, 7 insertions, 3 deletions
diff --git a/screenplain/export/fdx.py b/screenplain/export/fdx.py
index 0f92cf9..85cc0ab 100644
--- a/screenplain/export/fdx.py
+++ b/screenplain/export/fdx.py
@@ -30,7 +30,7 @@ def _write_text_element(out, styles, text):
def write_text(out, rich, trailing_linebreak):
"""Writes <Text Style="..."> elements."""
for seg_no, segment in enumerate(rich.segments):
- fdx_styles = set(style_names[n] for n in segment.styles)
+ fdx_styles = [style_names[n] for n in segment.get_ordered_styles()]
if trailing_linebreak and seg_no == len(rich.segments) - 1:
_write_text_element(out, fdx_styles, segment.text + '\n')
else:
diff --git a/screenplain/richstring.py b/screenplain/richstring.py
index c602966..43f5949 100644
--- a/screenplain/richstring.py
+++ b/screenplain/richstring.py
@@ -81,7 +81,7 @@ class Segment(object):
def __repr__(self):
return '(%s)(%r)' % (
'+'.join(
- style.name() for style in self.styles
+ style.name() for style in self.get_ordered_styles()
) or 'plain',
self.text
)
@@ -101,8 +101,12 @@ class Segment(object):
self.text != other.text or self.styles != other.styles
)
+ def get_ordered_styles(self):
+ """Get the styles in this segment in a deterministic order."""
+ return [style for style in all_styles if style in self.styles]
+
def to_html(self):
- ordered_styles = list(self.styles)
+ ordered_styles = self.get_ordered_styles()
return (
''.join(style.start_html for style in ordered_styles) +
cgi.escape(self.text).encode('ascii', 'xmlcharrefreplace') +