diff --git a/CHANGELOG b/CHANGELOG index 63e02ddf..d8aa3f16 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ Changelog ========= +* 0.3.4 + * It is possible for `w:t` tags to have `text` set to `None`. This no longer causes an error when escaping that text. * 0.3.3 * In the event that `cElementTree` has a problem parsing the document, a `MalformedDocxException` is raised instead of a `SyntaxError` diff --git a/pydocx/DocxParser.py b/pydocx/DocxParser.py index 465d2786..82b48cc3 100644 --- a/pydocx/DocxParser.py +++ b/pydocx/DocxParser.py @@ -577,12 +577,16 @@ def _is_style_on(self, el): return val.lower() not in DISABLED_VALUES def parse_t(self, el, parsed): + if el.text is None: + return '' return self.escape(el.text) def parse_break_tag(self, el, parsed): return self.break_tag() def parse_deletion(self, el, parsed): + if el.text is None: + return '' return self.deletion(el.text, '', '') def parse_insertion(self, el, parsed): diff --git a/pydocx/tests/templates/t.xml b/pydocx/tests/templates/t.xml index 92412f72..81d562b7 100644 --- a/pydocx/tests/templates/t.xml +++ b/pydocx/tests/templates/t.xml @@ -1 +1,5 @@ +{% if text %} {{ text }} +{% else %} + +{% endif %} diff --git a/pydocx/tests/test_xml.py b/pydocx/tests/test_xml.py index 7e80b323..8142ef2b 100644 --- a/pydocx/tests/test_xml.py +++ b/pydocx/tests/test_xml.py @@ -1231,3 +1231,25 @@ def get_xml(self): body += tag xml = DXB.xml(body) return xml.encode('utf-8') + + +class NoTextInTTagTestCase(_TranslationTestCase): + expected_output = u""" + """ + + def get_xml(self): + tags = [ + DXB.p_tag( + [ + DXB.r_tag( + [DXB.t_tag(None)], + ), + ], + ), + ] + + body = '' + for tag in tags: + body += tag + xml = DXB.xml(body) + return xml.encode('utf-8')