@@ -33,7 +33,7 @@ def sanitise_html(content: str, *, allow_links: bool = False) -> str:
3333 return sanitizer .clean (unescape (content )) # pylint: disable=no-member
3434
3535
36- STYLE_PROPS_PATTERN = re .compile (r"([^\s:;]+)\s*:\s*([^;]+)" )
36+ STYLE_PROPS_PATTERN : re . Pattern [ str ] = re .compile (r"([^\s:;]+)\s*:\s*([^;]+)" )
3737
3838
3939def clean_style_attributes (table : "Tag" ) -> None :
@@ -52,7 +52,12 @@ def clean_style_attributes(table: "Tag") -> None:
5252 if "style" not in tag .attrs :
5353 continue
5454
55- matches = STYLE_PROPS_PATTERN .findall (tag ["style" ])
55+ style : str = (
56+ "; " .join (tag ["style" ])
57+ if not isinstance (tag ["style" ], str )
58+ else tag ["style" ]
59+ )
60+ matches = STYLE_PROPS_PATTERN .findall (style )
5661 filtered_styles = []
5762 for prop , value in matches :
5863 prop = prop .strip ()
@@ -67,18 +72,20 @@ def clean_style_attributes(table: "Tag") -> None:
6772
6873def get_cell_data (cell : "Tag" , forced_type : Cell | None = None ) -> dict [str , str | int ]:
6974 value = "" .join (str (child ) for child in cell .children )
70- cell_data = {"value" : value , "type" : forced_type or cell .name }
75+ cell_data : dict [ str , str | int ] = {"value" : value , "type" : forced_type or cell .name }
7176
72- if (rowspan := int (cell .get ("rowspan" , 1 ))) > 1 :
77+ if (rowspan := int (str ( cell .get ("rowspan" , "1" ) ))) > 1 :
7378 cell_data ["rowspan" ] = rowspan
74- if (colspan := int (cell .get ("colspan" , 1 ))) > 1 :
79+ if (colspan := int (str ( cell .get ("colspan" , "1" ) ))) > 1 :
7580 cell_data ["colspan" ] = colspan
7681 if scope := cell .get ("scope" ):
77- cell_data ["scope" ] = scope
82+ cell_data ["scope" ] = str ( scope )
7883 if align := cell .get ("align" ):
79- cell_data ["align" ] = align
84+ cell_data ["align" ] = str ( align )
8085
8186 if style := cell .get ("style" ):
87+ if not isinstance (style , str ):
88+ style = "; " .join (style )
8289 matches = dict (STYLE_PROPS_PATTERN .findall (style ))
8390 if width := matches .get ("width" ):
8491 cell_data ["width" ] = width
0 commit comments