wx.richtext xml to/from plain text conversions

17 views
Skip to first unread message

Mark Summerfield

unread,
Nov 9, 2017, 11:01:47 AM11/9/17
to wxPython-users

I am trying to write two functions, one to convert plain text to wx's rich text XML format; and the other to convert the other way. I don't need these functions to round-trip. I have a wxml_for_text(text) -> wxml function that works fine (although it seems verbose to me). But I cannot get the complementary text_for_wxml(wxml) -> text function to work.

Could anyone show me how to get text_for_wxml working? And ideally, show me how to shorten & simplify both functions if that's possible?

Thanks.

I've attached t.py which runs with Python 3 and wxPython 4b2. For me the output is:

wxml_for_text

<?xml version="1.0" encoding="UTF-8"?>
<richtext version="1.0.0.0" xmlns="http://www.wxwidgets.org">
  <paragraphlayout margin-left="4,4098" margin-right="4,4098" margin-top="4,4098" margin-bottom="4,4098">
    <paragraph>
      <text>This and that.
And there's more.</text>
    </paragraph>
    <paragraph>
      <text>And more.</text>
    </paragraph>
    <paragraph>
      <text>And &lt;extra&gt; &amp;etc.
</text>
    </paragraph>
  </paragraphlayout>
</richtext>


text_for_wxml

('A', b'<?xml version="1.0" encoding="UTF-8"?>\n<richtext version="1.0.0.0" xmlns="http://www.wxwidgets.org">\n  <paragraphlayout margin-left="4,4098" margin-right="4,4098" margin-top="4,4098" margin-bottom="4,4098">\n    <paragraph>\n      <text>This and that.\nAnd there\'s more.</text>\n    </paragraph>\n    <paragraph>\n      <text>And more.</text>\n    </paragraph>\n    <paragraph>\n      <text>And &lt;extra&gt; &amp;etc.\n</text>\n    </paragraph>\n  </paragraphlayout>\n</richtext>\n')
('B', '')
('C', '')

I would have expected 'B' and 'C' to have plain text not empty strings.
t.py
Reply all
Reply to author
Forward
0 new messages