77from __future__ import absolute_import , print_function , unicode_literals
88
99from . import OxmlElement
10- from .ns import qn
11- from . text import CT_P
12- from . xmlchemy import BaseOxmlElement , OneAndOnlyOne , ZeroOrOne , ZeroOrMore
10+ from .xmlchemy import (
11+ BaseOxmlElement , OneAndOnlyOne , OneOrMore , ZeroOrOne , ZeroOrMore
12+ )
1313
1414
1515class CT_Row (BaseOxmlElement ):
@@ -92,19 +92,25 @@ class CT_Tc(BaseOxmlElement):
9292 """
9393 ``<w:tc>`` table cell element
9494 """
95- def add_p (self ):
95+ tcPr = ZeroOrOne ('w:tcPr' ) # bunches of successors, overriding insert
96+ p = OneOrMore ('w:p' )
97+
98+ def _insert_tcPr (self , tcPr ):
9699 """
97- Return a new <w:p> element that has been added at the end of any
98- existing cell content.
100+ ``tcPr`` has a bunch of successors, but it comes first if it appears,
101+ so just overriding and using insert(0, ...) rather than spelling out
102+ successors.
99103 """
100- p = CT_P .new ()
101- self .append (p )
102- return p
104+ self .insert (0 , tcPr )
105+ return tcPr
103106
104107 def clear_content (self ):
105108 """
106109 Remove all content child elements, preserving the ``<w:tcPr>``
107- element if present.
110+ element if present. Note that this leaves the ``<w:tc>`` element in
111+ an invalid state because it doesn't contain at least one block-level
112+ element. It's up to the caller to add a ``<w:p>`` or ``<w:tbl>``
113+ child element.
108114 """
109115 new_children = []
110116 tcPr = self .tcPr
@@ -119,20 +125,5 @@ def new(cls):
119125 required EG_BlockLevelElt.
120126 """
121127 tc = OxmlElement ('w:tc' )
122- p = CT_P .new ()
123- tc .append (p )
128+ tc ._add_p ()
124129 return tc
125-
126- @property
127- def p_lst (self ):
128- """
129- List of <w:p> child elements.
130- """
131- return self .findall (qn ('w:p' ))
132-
133- @property
134- def tcPr (self ):
135- """
136- <w:tcPr> child element or |None| if not present.
137- """
138- return self .find (qn ('w:tcPr' ))
0 commit comments