@@ -71,6 +71,87 @@ def new(cls, ilvl):
7171 return OxmlElement ('w:lvlOverride' , {qn ('w:ilvl' ): str (ilvl )})
7272
7373
74+ class CT_NumPr (OxmlBaseElement ):
75+ """
76+ A ``<w:numPr>`` element, a container for numbering properties applied to
77+ a paragraph.
78+ """
79+ def get_or_add_ilvl (self ):
80+ """
81+ Return the ilvl child element, newly added if not present.
82+ """
83+ ilvl = self .ilvl
84+ if ilvl is None :
85+ ilvl = self ._add_ilvl ()
86+ return ilvl
87+
88+ def get_or_add_numId (self ):
89+ """
90+ Return the numId child element, newly added if not present.
91+ """
92+ numId = self .numId
93+ if numId is None :
94+ numId = self ._add_numId ()
95+ return numId
96+
97+ @property
98+ def ilvl (self ):
99+ return self .find (qn ('w:ilvl' ))
100+
101+ @ilvl .setter
102+ def ilvl (self , val ):
103+ """
104+ Get or add a <w:ilvl> child and set its ``w:val`` attribute to *val*.
105+ """
106+ ilvl = self .get_or_add_ilvl ()
107+ ilvl .val = val
108+
109+ @classmethod
110+ def new (cls ):
111+ """
112+ Return a new ``<w:numPr>`` element
113+ """
114+ return OxmlElement ('w:numPr' )
115+
116+ @property
117+ def numId (self ):
118+ return self .find (qn ('w:numId' ))
119+
120+ @numId .setter
121+ def numId (self , val ):
122+ """
123+ Get or add a <w:numId> child and set its ``w:val`` attribute to *val*.
124+ """
125+ numId = self .get_or_add_numId ()
126+ numId .val = val
127+
128+ def _add_ilvl (self , val = 0 ):
129+ """
130+ Return a newly added CT_DecimalNumber element having tagname 'w:ilvl'
131+ and ``val`` attribute set to *val*.
132+ """
133+ ilvl = CT_DecimalNumber .new ('w:ilvl' , val )
134+ return self ._insert_ilvl (ilvl )
135+
136+ def _add_numId (self , val = 0 ):
137+ """
138+ Return a newly added CT_DecimalNumber element having tagname
139+ 'w:numId' and ``val`` attribute set to *val*.
140+ """
141+ numId = CT_DecimalNumber .new ('w:numId' , val )
142+ return self ._insert_numId (numId )
143+
144+ def _insert_ilvl (self , ilvl ):
145+ return self .insert_element_before (
146+ ilvl , 'w:numId' , 'w:numberingChange' , 'w:ins'
147+ )
148+
149+ def _insert_numId (self , numId ):
150+ return self .insert_element_before (
151+ numId , 'w:numberingChange' , 'w:ins'
152+ )
153+
154+
74155class CT_Numbering (OxmlBaseElement ):
75156 """
76157 ``<w:numbering>`` element, the root element of a numbering part, i.e.
@@ -83,13 +164,7 @@ def add_num(self, abstractNum_id):
83164 """
84165 next_num_id = self ._next_numId
85166 num = CT_Num .new (next_num_id , abstractNum_id )
86- # insert in proper sequence among children ---------
87- successor = self .first_child_found_in ('w:numIdMacAtCleanup' )
88- if successor is not None :
89- successor .addprevious (num )
90- else :
91- self .append (num )
92- return num
167+ return self ._insert_num (num )
93168
94169 @property
95170 def num_lst (self ):
@@ -109,6 +184,9 @@ def num_having_numId(self, numId):
109184 except IndexError :
110185 raise KeyError ('no <w:num> element with numId %d' % numId )
111186
187+ def _insert_num (self , num ):
188+ return self .insert_element_before (num , 'w:numIdMacAtCleanup' )
189+
112190 @property
113191 def _next_numId (self ):
114192 """
0 commit comments