@@ -39,6 +39,18 @@ def get_table_styles(self) -> Dict:
3939 :return:
4040 """
4141
42+ @abstractmethod
43+ def version (self ) -> str :
44+ """
45+ :return: The version number
46+ """
47+
48+ @abstractmethod
49+ def get_list_styles (self ) -> Dict :
50+ """
51+ :return:
52+ """
53+
4254 def add_class_to_element (self , elem , css_class ):
4355 if not elem .get ('class' ):
4456 elem ['class' ] = css_class
@@ -80,7 +92,8 @@ def add_form_classes(self, tag_dict: dict) -> NoReturn:
8092 for form in self .soup .find_all ('form' ):
8193 for elem in form .children :
8294 if elem .name == 'label' :
83- self .add_class_to_element (elem , tag_dict ['label' ])
95+ if 'label' in tag_dict :
96+ self .add_class_to_element (elem , tag_dict ['label' ])
8497
8598 elif elem .name == 'input' :
8699 self .add_class_to_element (elem , tag_dict ['input' ])
@@ -92,8 +105,8 @@ def add_form_classes(self, tag_dict: dict) -> NoReturn:
92105 if 'checkbox' in tag_dict :
93106 self .add_class_to_element (elem , tag_dict ['checkbox' ])
94107
95- elif type (elem ) == Tag : # ignore NavigableStrings like /n
96- if ( tag_dict .get (elem .name ) ):
108+ elif type (elem ) == Tag : # ignore NavigableStrings like /n
109+ if tag_dict .get (elem .name ):
97110 self .add_class_to_element (elem , tag_dict [elem .name ])
98111
99112 def add_table_classes (self , table_tag_dict : dict ) -> NoReturn :
@@ -117,6 +130,24 @@ def add_table_classes(self, table_tag_dict: dict) -> NoReturn:
117130 for elem in all_table_elems :
118131 self .add_class_to_element (elem , table_tag_dict [tk ])
119132
133+ def add_list_classes (self , list_tags : dict ) -> NoReturn :
134+ """
135+ Supports the following tags:
136+ ('ul', 'ol', 'li')
137+ :param list_tags:
138+ :return:
139+ """
140+ for list in self .soup .find_all (['ol' , 'ul' ]):
141+ if list .name == 'ul' and list_tags .get ('ul' ):
142+ self .add_class_to_element (list , list_tags ['ul' ])
143+ elif list .name == 'ol' and list_tags .get ('ol' ):
144+ self .add_class_to_element (list , list_tags ['ol' ])
145+
146+ if list_tags .get ('li' ):
147+ for li in list .find_all ('li' , recursive = False ):
148+ # recursive=False to prevent double modifying for nested lists
149+ self .add_class_to_element (li , list_tags ['li' ])
150+
120151 def output (self ) -> NoReturn :
121152 """
122153 Outputs a new file.
@@ -137,13 +168,15 @@ def freshify(self) -> NoReturn:
137168 """
138169 starter_tags = self .get_starter_tags ()
139170 wrapper_tag = self .get_wrapper_tag ()
140- table_tags = self .get_table_styles ()
171+ table_styles = self .get_table_styles ()
172+ list_styles = self .get_list_styles ()
141173
142174 self .initialize_framework (self .soup .head , starter_tags )
143175 if wrapper_tag :
144176 self .add_wrapper_tag (wrapper_tag )
145177 self .add_form_classes (self .tag_styles )
146- self .add_table_classes (table_tags )
178+ self .add_list_classes (list_styles )
179+ self .add_table_classes (table_styles )
147180 self .output ()
148181
149182# print(btn.get('class', []))
0 commit comments