Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
4 changes: 4 additions & 0 deletions pydocx/DocxParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions pydocx/tests/templates/t.xml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{% if text %}
<w:t>{{ text }}</w:t>
{% else %}
<w:t />
{% endif %}
22 changes: 22 additions & 0 deletions pydocx/tests/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')