@@ -275,7 +275,7 @@ def _set_last_list_item(self, num_ids, list_elements):
275
275
last_el = filtered_list_elements [- 1 ]
276
276
last_el .is_last_list_item_in_root = True
277
277
278
- def _set_headers (self , list_elements ):
278
+ def _set_headers (self , elements ):
279
279
# These are the styles for headers and what the html tag should be if
280
280
# we have one.
281
281
headers = {
@@ -290,17 +290,21 @@ def _set_headers(self, list_elements):
290
290
'heading 9' : 'h6' ,
291
291
'heading 10' : 'h6' ,
292
292
}
293
- for list_item in list_elements :
294
- style = list_item .find_first ('pStyle' ).attrib ['val' ]
293
+ for element in elements :
294
+ # This element is using the default style which is not a heading.
295
+ if element .find_first ('pStyle' ) is None :
296
+ continue
297
+ style = element .find_first ('pStyle' ).attrib ['val' ]
295
298
style = self .styles_dict .get (style )
296
- # Check to see if this list item is actually a header.
299
+
300
+ # Check to see if this element is actually a header.
297
301
if style and style .lower () in headers :
298
- # Set all the list item variables back to false.
299
- list_item .is_list_item = False
300
- list_item .is_first_list_item = False
301
- list_item .is_last_list_item = False
302
+ # Set all the list item variables to false.
303
+ element .is_list_item = False
304
+ element .is_first_list_item = False
305
+ element .is_last_list_item = False
302
306
# Prime the heading_level
303
- list_item .heading_level = headers [style .lower ()]
307
+ element .heading_level = headers [style .lower ()]
304
308
305
309
def _set_next (self , body ):
306
310
def _get_children (el ):
@@ -355,7 +359,10 @@ def parse_begin(self, el):
355
359
356
360
self ._set_first_list_item (num_ids , ilvls , list_elements )
357
361
self ._set_last_list_item (num_ids , list_elements )
358
- self ._set_headers (list_elements )
362
+ p_elements = [
363
+ child for child in body .find_all ('p' )
364
+ ]
365
+ self ._set_headers (p_elements )
359
366
self ._set_next (body )
360
367
361
368
self ._parsed += self .parse (el )
0 commit comments