@@ -113,9 +113,7 @@ def __init__(
113113 @staticmethod
114114 def get_implicit_role_mapping () -> ImplicitRoleMapping :
115115 return {
116- "a" : lambda node : (
117- "link" if "href" in node .attributes else "generic"
118- ),
116+ "a" : RoleResolver .get_a_role ,
119117 "article" : "article" ,
120118 "aside" : "complementary" ,
121119 "address" : "group" ,
@@ -133,7 +131,7 @@ def get_implicit_role_mapping() -> ImplicitRoleMapping:
133131 "password" : "textbox" ,
134132 },
135133 "textarea" : "textbox" ,
136- "select" : "combobox" ,
134+ "select" : RoleResolver . get_select_role ,
137135 "nav" : "navigation" ,
138136 "main" : "main" ,
139137 "meter" : "meter" ,
@@ -195,14 +193,14 @@ def get_implicit_role(node: LexborNode):
195193 return handler if isinstance (handler , str ) else None
196194
197195 @staticmethod
198- def get_td_role (node : LexborNode ) -> Optional [ str ] :
196+ def get_td_role (node : LexborNode ) -> str :
199197 """Determine the role of a td element."""
200198 ancestor = node .parent
201199 while ancestor and ancestor .tag != "table" :
202200 ancestor = ancestor .parent
203201
204202 if not ancestor :
205- return None
203+ return ""
206204
207205 table_role = ancestor .attributes .get ("role" )
208206
@@ -215,10 +213,10 @@ def get_td_role(node: LexborNode) -> Optional[str]:
215213 elif table_role in ["grid" , "treegrid" ]:
216214 return "gridcell"
217215
218- return None
216+ return ""
219217
220218 @staticmethod
221- def get_img_role (node : LexborNode ) -> Optional [ str ] :
219+ def get_img_role (node : LexborNode ) -> str :
222220 """Determine the role of an img element."""
223221 if "alt" in node .attributes :
224222 alt = node .attributes .get ("alt" )
@@ -231,3 +229,23 @@ def get_img_role(node: LexborNode) -> Optional[str]:
231229 ):
232230 return "presentation"
233231 return "img"
232+
233+ @staticmethod
234+ def get_select_role (node : LexborNode ) -> str :
235+ """Determine the role of a select element."""
236+ if "multiple" in node .attributes :
237+ return "listbox"
238+ if (
239+ "size" in node .attributes
240+ and node .attributes .get ("size" , None ) is not None
241+ ):
242+ if int (node .attributes .get ("size" )) > 1 : # type: ignore
243+ return "listbox"
244+ return "combobox"
245+
246+ @staticmethod
247+ def get_a_role (node : LexborNode ) -> str :
248+ """Determine the role of an element"""
249+ if "href" in node .attributes :
250+ return "link"
251+ return "generic"
0 commit comments