Skip to content

Commit a3658b5

Browse files
author
Steve Canny
committed
oxml: add CT_R.t_elms
1 parent bd828c2 commit a3658b5

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

docx/oxml/text.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ def add_t(self, text):
6666
self.append(t)
6767
return t
6868

69+
@property
70+
def t_elms(self):
71+
"""
72+
Sequence of the <w:t> elements in this paragraph.
73+
"""
74+
if not hasattr(self, 't'):
75+
return ()
76+
return tuple([t for t in self.t])
77+
6978

7079
class CT_Text(OxmlBaseElement):
7180
"""

tests/oxml/test_text.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ def it_can_add_a_t_to_itself(self):
5151
assert r.xml == an_r().with_nsdecls().with_t(text).xml
5252
assert isinstance(t, CT_Text)
5353

54+
def it_has_a_sequence_of_the_t_elms_it_contains(self):
55+
cases = (
56+
(an_r().with_nsdecls(), 0),
57+
(an_r().with_nsdecls().with_t('foo'), 1),
58+
(an_r().with_nsdecls().with_t('foo').with_t('bar'), 2),
59+
)
60+
for builder, expected_len in cases:
61+
r = builder.element
62+
assert len(r.t_elms) == expected_len
63+
for t in r.t_elms:
64+
assert isinstance(t, CT_Text)
65+
5466

5567
class DescribeCT_Text(object):
5668

0 commit comments

Comments
 (0)