@@ -360,12 +360,15 @@ def extrae_Tabla(element, rels_map, namespaces):
360360 obj ['formula' ] = etree .tostring (mathml_root , pretty_print = True , encoding = 'unicode' )
361361
362362
363- if not obj_image :
364- paragraph = element
365- text_paragraph = []
366-
367- # Determina si es parte de una lista
368- is_numPr = paragraph .find ('.//w:numPr' , namespaces = paragraph .nsmap ) is not None
363+ # obtiene id y nivel
364+ if is_numPr :
365+ numPr = paragraph .find ('.//w:numPr' , namespaces = paragraph .nsmap )
366+ numId = numPr .find ('.//w:numId' , namespaces = paragraph .nsmap ).get (namespaces_p + 'val' )
367+ type_matches = [
368+ (key , objt )
369+ for key , objt in list_types .items ()
370+ if objt .get ('numId' ) == numId
371+ ]
369372
370373 # obtiene id y nivel
371374 if is_numPr :
@@ -397,6 +400,76 @@ def extrae_Tabla(element, rels_map, namespaces):
397400 objl ['list' ] = '\n ' .join (current_list )
398401 current_list = []
399402 content .append (objl )
403+ list_type = 'bullet'
404+ if type_matches and type_matches [0 ][1 ].get (str (0 )) == 'decimal' :
405+ list_type = 'order'
406+
407+ current_list .append (f'[list list-type="{ list_type } "]' )
408+ else :
409+ #Se terminaron de agregar elementos a la lista
410+ if len (current_list ) > 0 :
411+ current_list .append ('[/list]' )
412+ objl = {}
413+ objl ['type' ] = 'list'
414+ objl ['list' ] = '\n ' .join (current_list )
415+ current_list = []
416+ content .append (objl )
417+
418+ for child in paragraph :
419+ if child .tag == '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}hyperlink' :
420+ for r in child .findall ('w:r' , namespaces = child .nsmap ):
421+ t_elem = r .find ('w:t' , namespaces = child .nsmap )
422+ if t_elem is not None and t_elem .text :
423+ text_paragraph .append (t_elem .text )
424+
425+ elif child .tag == '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}r' :
426+ namespaces = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}'
427+ sz_element = child .find ('.//w:sz' , namespaces = child .nsmap )
428+ obj ['font_size' ] = 0
429+
430+ if sz_element is None :
431+ p_pr = paragraph .find ('.//w:rPr/w:sz' , namespaces = child .nsmap )
432+ if p_pr is not None :
433+ sz_element = p_pr .find ('.//w:pPr' , namespaces = child .nsmap )
434+
435+ if sz_element is not None :
436+ xml_string = etree .tostring (sz_element , pretty_print = True , encoding = 'unicode' )
437+ size_element = objectify .fromstring (xml_string )
438+ font_size_value = size_element .get (namespaces + 'val' )
439+ obj ['font_size' ] = int (font_size_value )/ 2
440+
441+ color_element = child .find ('.//w:color' , namespaces = child .nsmap )
442+
443+ if color_element is None :
444+ p_pr = paragraph .find ('.//w:pPr' , namespaces = child .nsmap )
445+ if p_pr is not None :
446+ color_element = p_pr .find ('.//w:rPr/w:color' , namespaces = child .nsmap )
447+
448+ if color_element is not None :
449+ xml_string_color = etree .tostring (color_element , pretty_print = True , encoding = 'unicode' )
450+ object_element = objectify .fromstring (xml_string_color )
451+ color_value = object_element .get (namespaces + 'val' )
452+ obj ['color' ] = color_value
453+
454+ b_tag = child .find ('.//w:b' , namespaces = child .nsmap )
455+
456+ if b_tag is None :
457+ p_pr = paragraph .find ('.//w:rPr/w:b' , namespaces = child .nsmap )
458+ if p_pr is not None :
459+ b_tag = p_pr .find ('.//w:pPr' , namespaces = child .nsmap )
460+
461+ if b_tag is not None :
462+ val = b_tag .get ('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val' )
463+ obj ['bold' ] = (val is None or val in ['1' , 'true' , 'True' ])
464+ else :
465+ obj ['bold' ] = False
466+
467+ i_tag = child .find ('.//w:i' , namespaces = child .nsmap )
468+
469+ if i_tag is None :
470+ p_pr = paragraph .find ('.//w:rPr/w:i' , namespaces = child .nsmap )
471+ if p_pr is not None :
472+ i_tag = p_pr .find ('.//w:pPr' , namespaces = child .nsmap )
400473
401474 for child in paragraph :
402475 if child .tag == '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}hyperlink' :
@@ -575,13 +648,17 @@ def extrae_Tabla(element, rels_map, namespaces):
575648 'r' : 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'
576649 }
577650
578- table = element
579- table_data = extrae_Tabla (element , hiperlinks_info , namespaces )
580- obj = {}
581- obj ['type' ] = 'table'
582- obj ['table' ] = table_data
583-
584- if not is_numPr :
585- content .append (obj )
651+ if is_numPr :
652+ if 'font_size' in obj :
653+ del obj ['font_size' ]
654+ current_list .append (f'[list-item]{ obj ["text" ]} [/list-item]' )
655+ if isinstance (obj ['text' ], list ) and len (text_paragraph ) > 0 :
656+ obj2 = {}
657+ obj2 ['type' ] = 'text'
658+ obj2 ['value' ] = ' ' .join (text_paragraph )
659+ obj ['text' ].append (obj2 )
660+ text_paragraph = []
661+ if not is_numPr :
662+ content .append (obj )
586663 sections .sort (key = section_priority )
587664 return sections , content
0 commit comments