@kinti/a11y-toolkit 5.31.0 → 5.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/a11y_toolkit/a11yannotate.py +39 -42
- package/a11y_toolkit/a11yaudit.py +251 -147
- package/a11y_toolkit/a11ycrit.py +6 -0
- package/a11y_toolkit/a11ydom.py +47 -2
- package/a11y_toolkit/a11ylocate.py +4 -4
- package/a11y_toolkit/a11ytrace.py +173 -24
- package/a11y_toolkit/locales/en.json +12 -0
- package/a11y_toolkit/locales/es.json +12 -0
- package/a11y_toolkit/server.py +1 -1
- package/package.json +1 -1
|
@@ -63,6 +63,76 @@ def path_segment(tag, nth):
|
|
|
63
63
|
pueden romper la identidad)."""
|
|
64
64
|
return f'{tag}:nth-of-type({nth})'
|
|
65
65
|
|
|
66
|
+
|
|
67
|
+
class _ElementPaths:
|
|
68
|
+
"""Store one segment and parent index per distinct route."""
|
|
69
|
+
|
|
70
|
+
def __init__(self, implicit_tbody=True):
|
|
71
|
+
self.stack = []
|
|
72
|
+
self._implicit_tbody = implicit_tbody
|
|
73
|
+
self._nodes = [None]
|
|
74
|
+
self._node_ids = {}
|
|
75
|
+
|
|
76
|
+
def _child(self, tag):
|
|
77
|
+
if self.stack:
|
|
78
|
+
_, parent, siblings = self.stack[-1]
|
|
79
|
+
nth = siblings[tag] = siblings.get(tag, 0) + 1
|
|
80
|
+
else:
|
|
81
|
+
parent, nth = 0, 1
|
|
82
|
+
key = (parent, path_segment(tag, nth))
|
|
83
|
+
index = self._node_ids.get(key)
|
|
84
|
+
if index is None:
|
|
85
|
+
index = self._node_ids[key] = len(self._nodes)
|
|
86
|
+
self._nodes.append(key)
|
|
87
|
+
return index
|
|
88
|
+
|
|
89
|
+
def start(self, tag):
|
|
90
|
+
# Browsers insert a tbody for a row directly inside a table.
|
|
91
|
+
if self._implicit_tbody and tag == 'tr' and self.stack and self.stack[-1][0] == 'table':
|
|
92
|
+
self.stack.append(('tbody', self._child('tbody'), {}))
|
|
93
|
+
index = self._child(tag)
|
|
94
|
+
if tag not in VOID_TAGS:
|
|
95
|
+
self.stack.append((tag, index, {}))
|
|
96
|
+
return index
|
|
97
|
+
|
|
98
|
+
def end(self, tag):
|
|
99
|
+
if tag in VOID_TAGS:
|
|
100
|
+
return
|
|
101
|
+
for index in range(len(self.stack) - 1, -1, -1):
|
|
102
|
+
if self.stack[index][0] == tag:
|
|
103
|
+
del self.stack[index:]
|
|
104
|
+
break
|
|
105
|
+
|
|
106
|
+
def format(self, index):
|
|
107
|
+
segments = []
|
|
108
|
+
while index:
|
|
109
|
+
index, segment = self._nodes[index]
|
|
110
|
+
segments.append(segment)
|
|
111
|
+
return '>'.join(reversed(segments))
|
|
112
|
+
|
|
113
|
+
def lookup(self, path):
|
|
114
|
+
index = 0
|
|
115
|
+
for segment in path.split('>'):
|
|
116
|
+
index = self._node_ids.get((index, segment))
|
|
117
|
+
if index is None:
|
|
118
|
+
break
|
|
119
|
+
return index
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class _Table:
|
|
123
|
+
def __init__(self, attrs, counted):
|
|
124
|
+
self.attrs = attrs
|
|
125
|
+
self.counted = counted
|
|
126
|
+
border = (attrs.get('border') or '0').strip()
|
|
127
|
+
bordered = counted and border.isdecimal() and any(int(digit) for digit in border)
|
|
128
|
+
self.suspect_layout = not bordered and bool(
|
|
129
|
+
{'cellpadding', 'cellspacing', 'width', 'border'} & attrs.keys())
|
|
130
|
+
self.data = bordered or 'summary' in attrs
|
|
131
|
+
self.has_th = False
|
|
132
|
+
self.header_ids = set()
|
|
133
|
+
self.references = []
|
|
134
|
+
|
|
135
|
+
|
|
66
136
|
# roles que convierten cualquier elemento en campo etiquetable (e086e5).
|
|
67
137
|
# OJO: 'search' NO está — es un LANDMARK (WAI-ARIA 1.2), no un widget: un
|
|
68
138
|
# <form role="search"> sin aria-label es un landmark sin etiqueta, no un
|
|
@@ -385,8 +455,8 @@ class _Auditor(HTMLParser):
|
|
|
385
455
|
# CSS (tag:nth-of-type(n) desde la raíz). id(attrs) es estable dentro
|
|
386
456
|
# del parseo (cada attrs es un dict nuevo) → los recolectores pueden
|
|
387
457
|
# resolver la ruta de LO QUE COGIERON sin cambiar sus tuplas.
|
|
388
|
-
self.
|
|
389
|
-
self._elem_paths = {} # id(attrs) →
|
|
458
|
+
self._paths = _ElementPaths()
|
|
459
|
+
self._elem_paths = {} # id(attrs) → índice de ruta
|
|
390
460
|
super().__init__(convert_charrefs=True)
|
|
391
461
|
self.imgs_no_alt = []
|
|
392
462
|
self.alt_quality_bad = [] # (razón, alt, attrs) — emitida en findings
|
|
@@ -495,9 +565,7 @@ class _Auditor(HTMLParser):
|
|
|
495
565
|
self.media_autoplay_elems = []
|
|
496
566
|
self.tables = 0
|
|
497
567
|
self.tables_with_th = 0
|
|
498
|
-
self.
|
|
499
|
-
self._th_in_table = False
|
|
500
|
-
self._table_stack = [] # (th_había, attrs) por <table> abierta
|
|
568
|
+
self._table_stack = []
|
|
501
569
|
self.tables_no_th_elems = []
|
|
502
570
|
self.blank_no_warning = 0
|
|
503
571
|
self.blank_total = 0
|
|
@@ -521,6 +589,14 @@ class _Auditor(HTMLParser):
|
|
|
521
589
|
self.autocomplete_mismatch = []
|
|
522
590
|
self.heading_role_removed = [] # h1-h6 con rol que sustituye al de heading
|
|
523
591
|
self.text_spacing_important = [] # 1.4.12: spacing !important inline (ACT 24afc2/78fd32/9e45ec)
|
|
592
|
+
self.a_no_href = [] # 2.1.1: <a> sin href usado como control (batida B1-a)
|
|
593
|
+
self.nested_main = [] # 1.3.1: main anidado en seccionante (B1-b)
|
|
594
|
+
self.fake_lists = [] # 1.3.1: lista falsa con viñetas y <br> (B1-c)
|
|
595
|
+
self.alert_polite = [] # 4.1.2: role=alert gritando en aria-live=polite (B1-d)
|
|
596
|
+
self.headers_bad = [] # 1.3.1: headers= apuntando fuera de tabla o a no-th (ACT d0f69e/a25f45)
|
|
597
|
+
self.lang_xml_mismatch = [] # 3.1.2: lang y xml:lang discrepando (ACT 5b7ae0)
|
|
598
|
+
self._p_bullets = None # contador de viñetas del <p> abierto
|
|
599
|
+
self._p_brs = 0
|
|
524
600
|
self.links = {} # nombre normalizado → set de hrefs
|
|
525
601
|
self.links_elems = {} # entry_key → primeros elems (marcas 2.4.4)
|
|
526
602
|
self.generics = 0
|
|
@@ -680,29 +756,7 @@ class _Auditor(HTMLParser):
|
|
|
680
756
|
or (_ti_mark.isdecimal() and int(_ti_mark) >= 0):
|
|
681
757
|
for _sp in self._stray_pend:
|
|
682
758
|
_sp[3] = True
|
|
683
|
-
|
|
684
|
-
# SIEMPRE (los id duplicados no pueden romper la ruta) y los void no
|
|
685
|
-
# abren pila (no tienen handle_endtag)
|
|
686
|
-
# tbody IMPLÍCITO bajo <table>: el navegador normaliza <table><tr>
|
|
687
|
-
# insertando <tbody>; sin reflejarlo, las rutas nth-of-type que
|
|
688
|
-
# cruzan la mesa no resuelven en el DOM real (Chromium: table>tr
|
|
689
|
-
# casa CERO elementos — revisión externa 2026-11-22). Se abre igual
|
|
690
|
-
# que un tag normal y </table> lo cierra con el resto de la pila.
|
|
691
|
-
if tag == 'tr' and self._path_stack and self._path_stack[-1][0] == 'table':
|
|
692
|
-
_parent_tb = self._path_stack[-1]
|
|
693
|
-
_parent_tb[2]['tbody'] = _parent_tb[2].get('tbody', 0) + 1
|
|
694
|
-
self._path_stack.append(
|
|
695
|
-
('tbody', _parent_tb[1] + '>' + path_segment('tbody', _parent_tb[2]['tbody']), {}))
|
|
696
|
-
if self._path_stack:
|
|
697
|
-
_parent = self._path_stack[-1]
|
|
698
|
-
_parent[2][tag] = _parent[2].get(tag, 0) + 1
|
|
699
|
-
_seg = path_segment(tag, _parent[2][tag])
|
|
700
|
-
_path = _parent[1] + '>' + _seg
|
|
701
|
-
else:
|
|
702
|
-
_path = path_segment(tag, 1)
|
|
703
|
-
self._elem_paths[id(a)] = _path
|
|
704
|
-
if tag not in VOID_TAGS:
|
|
705
|
-
self._path_stack.append((tag, _path, {}))
|
|
759
|
+
self._elem_paths[id(a)] = self._paths.start(tag)
|
|
706
760
|
# rasgos estructurales para el scope de aplicabilidad (a11yscope):
|
|
707
761
|
# evidencia POSITIVA — cero <video> habilita proponer 1.2.x como no
|
|
708
762
|
# aplicable; la ausencia de señal jamás cuenta como ausencia de
|
|
@@ -1002,37 +1056,31 @@ class _Auditor(HTMLParser):
|
|
|
1002
1056
|
self._list_depth += 1
|
|
1003
1057
|
elif tag == 'li':
|
|
1004
1058
|
self._li_depth += 1
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
elif tag == 'th':
|
|
1031
|
-
self._th_in_table = True
|
|
1032
|
-
elif tag == 'caption' and self._table_stack:
|
|
1033
|
-
self._table_stack[-1][3] = True # marcador de tabla de DATOS
|
|
1034
|
-
elif tag == 'td' and self._table_stack and ('scope' in a or 'headers' in a):
|
|
1035
|
-
self._table_stack[-1][3] = True # asociaciones explícitas = datos
|
|
1059
|
+
if tag == 'br' and self._p_bullets is not None and not self._in_template:
|
|
1060
|
+
self._p_brs += 1
|
|
1061
|
+
if tag == 'p' and not self._in_template:
|
|
1062
|
+
self._p_bullets = 0
|
|
1063
|
+
self._p_brs = 0
|
|
1064
|
+
if tag == 'table':
|
|
1065
|
+
counted = not self._in_template and (
|
|
1066
|
+
(a.get('role') or '').strip().lower() not in ('presentation', 'none'))
|
|
1067
|
+
self._table_stack.append(_Table(a, counted))
|
|
1068
|
+
self.tables += int(counted)
|
|
1069
|
+
elif tag in ('th', 'td', 'caption') and self._table_stack and not self._in_template:
|
|
1070
|
+
table = self._table_stack[-1]
|
|
1071
|
+
if table.counted:
|
|
1072
|
+
if tag == 'caption':
|
|
1073
|
+
table.data = True
|
|
1074
|
+
else:
|
|
1075
|
+
table.has_th |= tag == 'th'
|
|
1076
|
+
if tag == 'td' and ('scope' in a or 'headers' in a):
|
|
1077
|
+
table.data = True
|
|
1078
|
+
cell_id = a.get('id')
|
|
1079
|
+
role = (a.get('role') or '').strip().lower()
|
|
1080
|
+
if cell_id and (tag == 'th' or role in ('columnheader', 'rowheader')):
|
|
1081
|
+
table.header_ids.add(cell_id)
|
|
1082
|
+
if (a.get('headers') or '').strip(' \t\n\f\r'):
|
|
1083
|
+
table.references.append(a)
|
|
1036
1084
|
elif tag == 'main' or (a.get('role') or '').lower() == 'main':
|
|
1037
1085
|
self.hay_main = True
|
|
1038
1086
|
if a.get('id'):
|
|
@@ -1284,6 +1332,21 @@ class _Auditor(HTMLParser):
|
|
|
1284
1332
|
# <area> es void: sin pila de control — se registra directo (el
|
|
1285
1333
|
# nombre le llega del alt)
|
|
1286
1334
|
self.controls_raw.append(('area', a, '', [], _hidden))
|
|
1335
|
+
if tag == 'main' and not self._in_template:
|
|
1336
|
+
# B1-b (batida 18-nov): main es top-level por definición — anidado
|
|
1337
|
+
# en section/aside/nav/article/main/header/footer no es ni landmark
|
|
1338
|
+
# válido ni estructura honesta (1.3.1)
|
|
1339
|
+
# [-1] es el PROPIO main (ya apilado cuando corre este chequeo):
|
|
1340
|
+
# el ancestro a mirar empieza uno antes
|
|
1341
|
+
for index in range(len(self._paths.stack) - 2, -1, -1):
|
|
1342
|
+
_utag = self._paths.stack[index][0]
|
|
1343
|
+
if _utag in ('section', 'aside', 'nav', 'article', 'main',
|
|
1344
|
+
'header', 'footer'):
|
|
1345
|
+
if len(self.nested_main) < 8:
|
|
1346
|
+
self.nested_main.append(f'<{_utag}> … <main>')
|
|
1347
|
+
break
|
|
1348
|
+
if _utag == 'body':
|
|
1349
|
+
break
|
|
1287
1350
|
if tag in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6'):
|
|
1288
1351
|
# role=none/presentation APAGA la semántica del encabezado; un
|
|
1289
1352
|
# aria-level válido la SOBRESCRIBE (accname: h3[aria-level=4] ES 4)
|
|
@@ -1307,7 +1370,6 @@ class _Auditor(HTMLParser):
|
|
|
1307
1370
|
self._heading_level = int(_alv.group())
|
|
1308
1371
|
self._heading_text = []
|
|
1309
1372
|
self._heading_attrs = a
|
|
1310
|
-
self._heading_route = self._elem_paths.get(id(a))
|
|
1311
1373
|
self._heading_hidden = _hidden
|
|
1312
1374
|
self._heading_tag = tag
|
|
1313
1375
|
elif (a.get('role') or '').lower() == 'heading' and not self._in_template:
|
|
@@ -1318,27 +1380,44 @@ class _Auditor(HTMLParser):
|
|
|
1318
1380
|
self._heading_level = int(_alv.group()) if _alv else 2
|
|
1319
1381
|
self._heading_text = []
|
|
1320
1382
|
self._heading_attrs = a
|
|
1321
|
-
self._heading_route = self._elem_paths.get(id(a))
|
|
1322
1383
|
self._heading_hidden = _hidden
|
|
1323
1384
|
self._heading_tag = tag
|
|
1385
|
+
# ── batida 18-nov, día 2 ──
|
|
1386
|
+
if not self._in_template:
|
|
1387
|
+
# B1-a: <a> SIN href con vida de control (2.1.1): tabindex>=0,
|
|
1388
|
+
# onclick o rol interactivo. Sin href NO es enlace: el AT no lo
|
|
1389
|
+
# anuncia como tal aunque sea enfocable y le echen un click.
|
|
1390
|
+
# Exento: tabindex=-1 (ancla objetivo legítima) y <a> puro con id
|
|
1391
|
+
# (ancla con nombre de toda la vida).
|
|
1392
|
+
if tag == 'a' and not (a.get('href') or '').strip():
|
|
1393
|
+
_anchor_role = (a.get('role') or '').strip().lower()
|
|
1394
|
+
_viva = ((a.get('onclick') or '')
|
|
1395
|
+
or _anchor_role in ('button', 'link', 'tab', 'menuitem')
|
|
1396
|
+
or (a.get('tabindex') or '').strip() not in ('', '-1'))
|
|
1397
|
+
if _viva and len(self.a_no_href) < 12:
|
|
1398
|
+
_tx = ' '.join(self._ctrl[-1]['text']).strip()[:20] if self._ctrl else ''
|
|
1399
|
+
self.a_no_href.append('<a>' + (f' "{_tx}"' if _tx else ''))
|
|
1400
|
+
# B1-d: role=alert ES assertive en sí mismo (ARIA): un aria-live
|
|
1401
|
+
# polite encima lo contradice (4.1.2, estado que no es el que dice)
|
|
1402
|
+
_role_low = (a.get('role') or '').strip().lower()
|
|
1403
|
+
_live = (a.get('aria-live') or '').strip().lower()
|
|
1404
|
+
if _role_low == 'alert' and _live == 'polite' and len(self.alert_polite) < 8:
|
|
1405
|
+
self.alert_polite.append('role="alert" + aria-live="polite"')
|
|
1406
|
+
if _lang_v := (a.get('lang') or '').strip():
|
|
1407
|
+
_xml = (a.get('{http://www.w3.org/XML/1998/namespace}lang')
|
|
1408
|
+
or a.get('xml:lang') or '').strip()
|
|
1409
|
+
if _xml and _lang_v.lower() != _xml.lower() and len(self.lang_xml_mismatch) < 8:
|
|
1410
|
+
self.lang_xml_mismatch.append(f'{tag} lang="{_lang_v}" xml:lang="{_xml}"')
|
|
1411
|
+
|
|
1324
1412
|
ti = a.get('tabindex')
|
|
1325
1413
|
if ti and ti.isdecimal() and int(ti) > 0 and not self._in_template:
|
|
1326
1414
|
self.positive_tabindices.append((tag, int(ti)))
|
|
1327
1415
|
self.positive_tabindex_elems.append(a)
|
|
1328
1416
|
|
|
1329
1417
|
def handle_endtag(self, tag):
|
|
1330
|
-
|
|
1331
|
-
# malformado, se descarta hasta el que casa; suelto, se ignora
|
|
1332
|
-
if self._path_stack:
|
|
1333
|
-
if self._path_stack[-1][0] == tag:
|
|
1334
|
-
self._path_stack.pop()
|
|
1335
|
-
else:
|
|
1336
|
-
for _i in range(len(self._path_stack) - 1, -1, -1):
|
|
1337
|
-
if self._path_stack[_i][0] == tag:
|
|
1338
|
-
del self._path_stack[_i:]
|
|
1339
|
-
break
|
|
1418
|
+
self._paths.end(tag)
|
|
1340
1419
|
if tag not in _VOID:
|
|
1341
|
-
# LAS PILAS SE SINCRONIZAN
|
|
1420
|
+
# LAS PILAS SE SINCRONIZAN con las rutas: buscar el frame que
|
|
1342
1421
|
# casa y descartar hasta él (un </span> suelto ya no arrastra el
|
|
1343
1422
|
# elemento abierto de verdad — el texto no se malatribuye)
|
|
1344
1423
|
_idx = None
|
|
@@ -1354,12 +1433,12 @@ class _Auditor(HTMLParser):
|
|
|
1354
1433
|
self._close_control(tag)
|
|
1355
1434
|
return
|
|
1356
1435
|
_nframes = len(self._el_stack) - _idx
|
|
1357
|
-
_closed_attrs = None # attrs del frame que CASA (el último popeado)
|
|
1358
1436
|
for _ in range(_nframes):
|
|
1359
1437
|
if not self._el_stack:
|
|
1360
1438
|
break
|
|
1361
1439
|
_etag, _eattrs, _ebuf = self._el_stack.pop()
|
|
1362
|
-
|
|
1440
|
+
if _etag == 'table':
|
|
1441
|
+
self._finish_table(self._table_stack.pop())
|
|
1363
1442
|
if _etag == 'canvas':
|
|
1364
1443
|
self.canvases.append((_eattrs, ' '.join(_ebuf).strip(),
|
|
1365
1444
|
self.canvas_hidden.pop(id(_eattrs), False)))
|
|
@@ -1462,6 +1541,16 @@ class _Auditor(HTMLParser):
|
|
|
1462
1541
|
self._form_auth = False
|
|
1463
1542
|
elif tag == 'nav':
|
|
1464
1543
|
self._in_nav = max(0, self._in_nav - 1)
|
|
1544
|
+
elif tag == 'p':
|
|
1545
|
+
# B1-c: lista falsa = ≥2 viñetas tipográficas + separadores <br>
|
|
1546
|
+
# en un párrafo fuera de listas reales (batida 18-nov, htmhell 30)
|
|
1547
|
+
if self._p_bullets is not None and self._p_bullets >= 2 \
|
|
1548
|
+
and self._p_brs >= 1 and self._list_depth == 0 \
|
|
1549
|
+
and len(self.fake_lists) < 8:
|
|
1550
|
+
self.fake_lists.append(f'<p> • × {self._p_bullets}, '
|
|
1551
|
+
f'<br> × {self._p_brs}')
|
|
1552
|
+
self._p_bullets = None
|
|
1553
|
+
self._p_brs = 0
|
|
1465
1554
|
elif tag == 'li':
|
|
1466
1555
|
self._li_depth = max(0, self._li_depth - 1)
|
|
1467
1556
|
elif tag in ('ul', 'ol'):
|
|
@@ -1476,34 +1565,48 @@ class _Auditor(HTMLParser):
|
|
|
1476
1565
|
self.videos_no_caps_elems.append(_vattrs)
|
|
1477
1566
|
if not _vdesc:
|
|
1478
1567
|
self.videos_no_desc_elems.append(_vattrs)
|
|
1479
|
-
elif tag == 'table':
|
|
1480
|
-
if self._table_stack and _closed_attrs is not None:
|
|
1481
|
-
_th_saved, _tattrs, _suspect, _data = self._table_stack[-1]
|
|
1482
|
-
# IDENTIDAD: solo decide la entrada cuya tabla se CIERRA (el
|
|
1483
|
-
# </table> de una presentation/template NUNCA apilada resbala
|
|
1484
|
-
# sin tocar la pila — antes popeaba la entrada de la externa)
|
|
1485
|
-
if _closed_attrs is _tattrs:
|
|
1486
|
-
self._table_stack.pop()
|
|
1487
|
-
if self._th_in_table:
|
|
1488
|
-
self.tables_with_th += 1
|
|
1489
|
-
elif _data or not _suspect:
|
|
1490
|
-
self.tables_no_th_elems.append(_tattrs)
|
|
1491
|
-
else:
|
|
1492
|
-
# maquetación por heurística: fuera del cómputo
|
|
1493
|
-
self.tables -= 1
|
|
1494
|
-
self._th_in_table = _th_saved
|
|
1495
|
-
self._in_table = bool(self._table_stack)
|
|
1496
|
-
elif tag == 'th':
|
|
1497
|
-
pass
|
|
1498
1568
|
elif self._heading_level and tag == getattr(self, '_heading_tag', None):
|
|
1499
1569
|
# el veredicto de nombre vacío es POST-parse (labelledby resuelto,
|
|
1500
1570
|
# aria-label tras strip, nombres de imgs internas)
|
|
1501
|
-
self.headings_raw.append((self._heading_level,
|
|
1571
|
+
self.headings_raw.append((self._heading_level, self._heading_attrs,
|
|
1502
1572
|
' '.join(self._heading_text).strip(),
|
|
1503
|
-
getattr(self, '_heading_hidden', False)
|
|
1504
|
-
getattr(self, '_heading_route', None)))
|
|
1573
|
+
getattr(self, '_heading_hidden', False)))
|
|
1505
1574
|
self._heading_level = None
|
|
1506
1575
|
|
|
1576
|
+
def _finish_table(self, table):
|
|
1577
|
+
if not table.counted:
|
|
1578
|
+
return
|
|
1579
|
+
if table.has_th:
|
|
1580
|
+
self.tables_with_th += 1
|
|
1581
|
+
elif table.data or not table.suspect_layout:
|
|
1582
|
+
self.tables_no_th_elems.append(table.attrs)
|
|
1583
|
+
else:
|
|
1584
|
+
self.tables -= 1
|
|
1585
|
+
for cell in table.references:
|
|
1586
|
+
for token in re.split(r'[ \t\n\f\r]+', cell['headers'].strip(' \t\n\f\r')):
|
|
1587
|
+
if token not in table.header_ids or token == cell.get('id'):
|
|
1588
|
+
self.headers_bad.append((token, cell))
|
|
1589
|
+
break
|
|
1590
|
+
|
|
1591
|
+
def close(self):
|
|
1592
|
+
super().close()
|
|
1593
|
+
while self._table_stack:
|
|
1594
|
+
self._finish_table(self._table_stack.pop())
|
|
1595
|
+
|
|
1596
|
+
def _finding_paths(self, elements):
|
|
1597
|
+
paths = []
|
|
1598
|
+
for attrs in elements:
|
|
1599
|
+
path = self.element_path(attrs)
|
|
1600
|
+
if path:
|
|
1601
|
+
paths.append(path)
|
|
1602
|
+
if len(paths) == 5:
|
|
1603
|
+
break
|
|
1604
|
+
return paths
|
|
1605
|
+
|
|
1606
|
+
def element_path(self, attrs):
|
|
1607
|
+
index = self._elem_paths.get(id(attrs))
|
|
1608
|
+
return self._paths.format(index) if index is not None else None
|
|
1609
|
+
|
|
1507
1610
|
_RE_CHAR_KEY = re.compile(r'key(?:Code)?\s*===?\s*["\']([a-zA-Z0-9])["\']', re.S)
|
|
1508
1611
|
|
|
1509
1612
|
def handle_script_wait(self, data):
|
|
@@ -1638,6 +1741,11 @@ class _Auditor(HTMLParser):
|
|
|
1638
1741
|
m = _SENSORIAL.search(re.sub(r'«[^»]*»|“[^”]*”|"[^"]*"', ' ', data))
|
|
1639
1742
|
if m and len(self.sensory) < 6:
|
|
1640
1743
|
self.sensory.append(m.group(0).strip()[:60])
|
|
1744
|
+
# B1-c: viñetas tipográficas en prosa = lista falsa (umbral ≥2;
|
|
1745
|
+
# un solo guion de cita o de lista de definición NO es lista)
|
|
1746
|
+
if self._p_bullets is not None:
|
|
1747
|
+
self._p_bullets += len(re.findall(
|
|
1748
|
+
r'(?:^|\s)[•‣▪●◦∙]\s*\S', data))
|
|
1641
1749
|
|
|
1642
1750
|
|
|
1643
1751
|
|
|
@@ -1897,7 +2005,7 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
1897
2005
|
or ' '.join(x for x in _img_names if x).strip()
|
|
1898
2006
|
or (a.get('alt') or '').strip()):
|
|
1899
2007
|
p.controls_by_kind.setdefault(kind, []).append(a)
|
|
1900
|
-
for level, a, text, hidden
|
|
2008
|
+
for level, a, text, hidden in p.headings_raw:
|
|
1901
2009
|
if hidden:
|
|
1902
2010
|
continue
|
|
1903
2011
|
lb, al, _ti = _name_sources(a)
|
|
@@ -1980,52 +2088,43 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
1980
2088
|
findings[-1]['examples'] = examples[:5]
|
|
1981
2089
|
|
|
1982
2090
|
if p.alt_quality_bad:
|
|
1983
|
-
_p_q =
|
|
1984
|
-
if id(_a) in p._elem_paths][:5]
|
|
2091
|
+
_p_q = p._finding_paths(a for _, _, a in p.alt_quality_bad)
|
|
1985
2092
|
add_ej('medium', '1.1.1', 'alt_quality',
|
|
1986
2093
|
[_alt[:40] for _r, _alt, _a in p.alt_quality_bad],
|
|
1987
2094
|
n=len(p.alt_quality_bad), paths=_p_q)
|
|
1988
2095
|
if p.imgs_no_alt:
|
|
1989
|
-
_p_img =
|
|
1990
|
-
if id(_a) in p._elem_paths][:5]
|
|
2096
|
+
_p_img = p._finding_paths(p.imgs_no_alt_elems)
|
|
1991
2097
|
add_ej('high', '1.1.1', 'img_no_alt', p.imgs_no_alt,
|
|
1992
2098
|
n=len(p.imgs_no_alt), paths=_p_img)
|
|
1993
2099
|
if p.input_img_no_alt:
|
|
1994
2100
|
add('high', '1.1.1', 'input_img_alt', n=p.input_img_no_alt)
|
|
1995
2101
|
if p.canvas_no_layer:
|
|
1996
|
-
_p_canvas =
|
|
1997
|
-
if id(_a) in p._elem_paths][:5]
|
|
2102
|
+
_p_canvas = p._finding_paths(p.canvas_no_layer_elems)
|
|
1998
2103
|
add_ej('medium', '1.1.1', 'canvas_no_accessible_layer', p.canvas_no_layer,
|
|
1999
2104
|
n=len(p.canvas_no_layer), paths=_p_canvas)
|
|
2000
2105
|
for tag, controls in p.controls_by_kind.items():
|
|
2001
2106
|
add('high', '4.1.2', 'ctrl_name', n=len(controls), tag=tag,
|
|
2002
|
-
paths=
|
|
2003
|
-
if id(_a) in p._elem_paths][:5])
|
|
2107
|
+
paths=p._finding_paths(controls))
|
|
2004
2108
|
if p.aria_hidden_focusable:
|
|
2005
2109
|
add('high', '4.1.2', 'aria_hidden_focusable',
|
|
2006
2110
|
n=len(p.aria_hidden_focusable), tag=p.aria_hidden_focusable[0],
|
|
2007
|
-
paths=
|
|
2008
|
-
if id(_a) in p._elem_paths][:5])
|
|
2111
|
+
paths=p._finding_paths(p.aria_hidden_focusable_elems))
|
|
2009
2112
|
if p.fields_no_label:
|
|
2010
2113
|
add_ej('high', '3.3.2', 'field_label',
|
|
2011
2114
|
[f'{t} name={n or "(no name)"}' for t, n, _i in p.fields_no_label],
|
|
2012
2115
|
n=len(p.fields_no_label),
|
|
2013
|
-
paths=
|
|
2014
|
-
if id(_a) in p._elem_paths][:5])
|
|
2116
|
+
paths=p._finding_paths(p.fields_no_label_elems))
|
|
2015
2117
|
if p.stray_clicks:
|
|
2016
2118
|
add('high', '2.1.1', 'click_nonfocusable',
|
|
2017
2119
|
n=len(p.stray_clicks), tag=p.stray_clicks[0],
|
|
2018
|
-
paths=
|
|
2019
|
-
if id(_a) in p._elem_paths][:5])
|
|
2120
|
+
paths=p._finding_paths(p.stray_click_elems))
|
|
2020
2121
|
if p.role_no_tabindex:
|
|
2021
2122
|
add_ej('low', '2.1.1', 'role_no_tabindex', p.role_no_tabindex,
|
|
2022
2123
|
n=len(p.role_no_tabindex), example=', '.join(p.role_no_tabindex[:3]),
|
|
2023
|
-
paths=
|
|
2024
|
-
if id(_a) in p._elem_paths][:5])
|
|
2124
|
+
paths=p._finding_paths(p.role_no_tabindex_elems))
|
|
2025
2125
|
if p.orphan_labels:
|
|
2026
2126
|
add('low', '3.3.2', 'label_orphan', n=p.orphan_labels,
|
|
2027
|
-
paths=
|
|
2028
|
-
if id(_a) in p._elem_paths][:5])
|
|
2127
|
+
paths=p._finding_paths(p.orphan_label_elems))
|
|
2029
2128
|
if p._bad_list:
|
|
2030
2129
|
add('medium', '1.3.1', 'list_structure', n=p._bad_list)
|
|
2031
2130
|
if p.root_tag in ('svg', 'math'):
|
|
@@ -2051,12 +2150,10 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2051
2150
|
if p.iframes_no_title:
|
|
2052
2151
|
add_ej('medium', '4.1.2', 'iframe_title', p.iframes_no_title,
|
|
2053
2152
|
n=len(p.iframes_no_title),
|
|
2054
|
-
paths=
|
|
2055
|
-
if id(_a) in p._elem_paths][:5])
|
|
2153
|
+
paths=p._finding_paths(p.iframes_no_title_elems))
|
|
2056
2154
|
if p.videos and p.videos_no_caps_elems:
|
|
2057
2155
|
add('medium', '1.2.2', 'video_captions', n=len(p.videos_no_caps_elems),
|
|
2058
|
-
paths=
|
|
2059
|
-
if id(_a) in p._elem_paths][:5])
|
|
2156
|
+
paths=p._finding_paths(p.videos_no_caps_elems))
|
|
2060
2157
|
if p.viewport:
|
|
2061
2158
|
# valores inválidos también blocksn (ACT b4f0c3): user-scalable ha de
|
|
2062
2159
|
# ser yes/true o numérico ≥ 1; maximum-scale numérico — si no parsea,
|
|
@@ -2070,8 +2167,7 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2070
2167
|
allows = v in ('yes', 'true')
|
|
2071
2168
|
if not allows:
|
|
2072
2169
|
add('high', '1.4.4', 'zoom_no',
|
|
2073
|
-
paths=
|
|
2074
|
-
if p._viewport_elem and id(p._viewport_elem) in p._elem_paths else None))
|
|
2170
|
+
paths=p._finding_paths([p._viewport_elem]))
|
|
2075
2171
|
m_ms = re.search(r'maximum-scale\s*=\s*([\w.-]+)', p.viewport, re.I)
|
|
2076
2172
|
if m_ms:
|
|
2077
2173
|
_v_ms = m_ms.group(1)
|
|
@@ -2085,8 +2181,7 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2085
2181
|
# mismo daño que user-scalable=no (bloquea el zoom del usuario):
|
|
2086
2182
|
# misma severidad — ACT b4f0c3 no las distingue
|
|
2087
2183
|
add('high', '1.4.4', 'zoom_max', v=_v_ms,
|
|
2088
|
-
paths=
|
|
2089
|
-
if p._viewport_elem and id(p._viewport_elem) in p._elem_paths else None))
|
|
2184
|
+
paths=p._finding_paths([p._viewport_elem]))
|
|
2090
2185
|
# meta refresh (2.2.1/ACT bc659a): gana el PRIMER meta que parsea según
|
|
2091
2186
|
# los pasos del HTML (dígitos + ; o , o fin — un «0: url» con dos puntos
|
|
2092
2187
|
# NO parsea y se salta); 0 segundos = redirección inmediata y > 72000
|
|
@@ -2102,14 +2197,12 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2102
2197
|
break
|
|
2103
2198
|
if _mr is not None and 0 < _mr <= 72000:
|
|
2104
2199
|
add('medium', '2.2.1', 'meta_refresh', v=_mr,
|
|
2105
|
-
paths=
|
|
2106
|
-
if _mr_elem and id(_mr_elem) in p._elem_paths else None))
|
|
2200
|
+
paths=p._finding_paths([_mr_elem]))
|
|
2107
2201
|
if p.positive_tabindices:
|
|
2108
2202
|
add_ej('medium', '2.4.3', 'tabindex_pos',
|
|
2109
2203
|
[f'{t}[tabindex={i}]' for t, i in p.positive_tabindices],
|
|
2110
2204
|
n=len(p.positive_tabindices),
|
|
2111
|
-
paths=
|
|
2112
|
-
if id(_a) in p._elem_paths][:5])
|
|
2205
|
+
paths=p._finding_paths(p.positive_tabindex_elems))
|
|
2113
2206
|
# un toggle cuenta como mecanismo de abatido SOLO si la función que
|
|
2114
2207
|
# invoca colapsa de verdad (su cuerpo, en el script de la página, toca
|
|
2115
2208
|
# `display`): mover off-screen o aria-hidden no colapsa el bloque (3e12e1)
|
|
@@ -2161,17 +2254,36 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2161
2254
|
if p.heading_role_removed:
|
|
2162
2255
|
add_ej('medium', '1.3.1', 'heading_role_removed', p.heading_role_removed,
|
|
2163
2256
|
n=len(p.heading_role_removed), example=', '.join(p.heading_role_removed[:4]))
|
|
2257
|
+
if p.nested_main:
|
|
2258
|
+
add_ej('medium', '1.3.1', 'nested_main', p.nested_main,
|
|
2259
|
+
n=len(p.nested_main), example=', '.join(p.nested_main[:4]))
|
|
2260
|
+
if p.fake_lists:
|
|
2261
|
+
add_ej('low', '1.3.1', 'fake_list', p.fake_lists,
|
|
2262
|
+
n=len(p.fake_lists), example=', '.join(p.fake_lists[:3]))
|
|
2263
|
+
if p.a_no_href:
|
|
2264
|
+
add_ej('medium', '2.1.1', 'a_no_href', p.a_no_href,
|
|
2265
|
+
n=len(p.a_no_href), example=', '.join(p.a_no_href[:4]))
|
|
2266
|
+
if p.alert_polite:
|
|
2267
|
+
add_ej('low', '4.1.2', 'alert_polite', p.alert_polite,
|
|
2268
|
+
n=len(p.alert_polite), example=', '.join(p.alert_polite[:3]))
|
|
2269
|
+
if p.lang_xml_mismatch:
|
|
2270
|
+
add_ej('low', '3.1.2', 'lang_xml_mismatch', p.lang_xml_mismatch,
|
|
2271
|
+
n=len(p.lang_xml_mismatch), example=', '.join(p.lang_xml_mismatch[:4]))
|
|
2272
|
+
if p.headers_bad:
|
|
2273
|
+
examples = [f'headers="{token[:20]}"' for token, _ in p.headers_bad[:5]]
|
|
2274
|
+
add_ej('medium', '1.3.1', 'headers_attr_bad', examples,
|
|
2275
|
+
n=len(p.headers_bad), example=', '.join(examples[:4]),
|
|
2276
|
+
paths=p._finding_paths(cell for _, cell in p.headers_bad))
|
|
2277
|
+
|
|
2164
2278
|
if p.text_spacing_important:
|
|
2165
2279
|
add_ej('medium', '1.4.12', 'text_spacing_important', p.text_spacing_important,
|
|
2166
2280
|
n=len(p.text_spacing_important), example=', '.join(p.text_spacing_important[:4]))
|
|
2167
2281
|
if p.tables and p.tables_with_th < p.tables:
|
|
2168
2282
|
add('medium', '1.3.1', 'table_no_th', n=p.tables - p.tables_with_th,
|
|
2169
|
-
paths=
|
|
2170
|
-
if id(_a) in p._elem_paths][:5])
|
|
2283
|
+
paths=p._finding_paths(p.tables_no_th_elems))
|
|
2171
2284
|
if p.blank_no_warning:
|
|
2172
2285
|
add('low', '3.2.5', 'blank_no_warning', n=p.blank_no_warning,
|
|
2173
|
-
paths=
|
|
2174
|
-
if id(_a) in p._elem_paths][:5])
|
|
2286
|
+
paths=p._finding_paths(p.blank_no_warning_elems))
|
|
2175
2287
|
dups = sum(1 for _c, k in p.ids.items() if k > 1)
|
|
2176
2288
|
if dups:
|
|
2177
2289
|
add_ej('low', '4.1.2', 'dup_ids',
|
|
@@ -2200,8 +2312,7 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2200
2312
|
if p.missing_autocomplete:
|
|
2201
2313
|
add_ej('medium', '1.3.5', 'autocomplete', p.missing_autocomplete,
|
|
2202
2314
|
n=len(p.missing_autocomplete), example=', '.join(p.missing_autocomplete[:4]),
|
|
2203
|
-
paths=
|
|
2204
|
-
if id(_a) in p._elem_paths][:5])
|
|
2315
|
+
paths=p._finding_paths(p.autocomplete_elems))
|
|
2205
2316
|
if p.autocomplete_invalid:
|
|
2206
2317
|
add_ej('medium', '1.3.5', 'autocomplete_invalid', p.autocomplete_invalid,
|
|
2207
2318
|
n=len(p.autocomplete_invalid), example=', '.join(p.autocomplete_invalid[:4]))
|
|
@@ -2210,8 +2321,7 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2210
2321
|
n=len(p.autocomplete_mismatch), example=', '.join(p.autocomplete_mismatch[:4]))
|
|
2211
2322
|
if p.media_autoplay:
|
|
2212
2323
|
add('medium', '1.4.2', 'video_autoplay', n=p.media_autoplay,
|
|
2213
|
-
paths=
|
|
2214
|
-
if id(_a) in p._elem_paths][:5])
|
|
2324
|
+
paths=p._finding_paths(p.media_autoplay_elems))
|
|
2215
2325
|
# 2.5.3, veredicto POST-parse (4ª pasada): el nombre EFECTIVO por
|
|
2216
2326
|
# precedencia accname — labelledby (ids resueltos, unidos en orden) GANA
|
|
2217
2327
|
# a aria-label. El nombre del propio contenido cumple trivialmente.
|
|
@@ -2247,8 +2357,7 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2247
2357
|
add_ej('medium', '2.5.3', 'label_in_name',
|
|
2248
2358
|
[f'«{t}» vs name «{al}»' for t, al in p.label_no_name],
|
|
2249
2359
|
n=len(p.label_no_name), example=f'{_ln[0]} ≠ {_ln[1]}',
|
|
2250
|
-
paths=
|
|
2251
|
-
if id(_a) in p._elem_paths][:5])
|
|
2360
|
+
paths=p._finding_paths(p.label_no_name_elems))
|
|
2252
2361
|
if p.lang_parts_invalid:
|
|
2253
2362
|
add_ej('medium', '3.1.2', 'element_lang_invalid', p.lang_parts_invalid,
|
|
2254
2363
|
n=len(p.lang_parts_invalid), example=', '.join(p.lang_parts_invalid[:4]))
|
|
@@ -2259,8 +2368,7 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2259
2368
|
if p.placeholder_only:
|
|
2260
2369
|
add_ej('high', '3.3.2', 'placeholder_only', p.placeholder_only,
|
|
2261
2370
|
n=len(p.placeholder_only), example=', '.join(p.placeholder_only[:3]),
|
|
2262
|
-
paths=
|
|
2263
|
-
if id(_a) in p._elem_paths][:5])
|
|
2371
|
+
paths=p._finding_paths(p.placeholder_only_elems))
|
|
2264
2372
|
if p.required_no_indication:
|
|
2265
2373
|
add_ej('low', '3.3.2', 'required_no_indication', p.required_no_indication,
|
|
2266
2374
|
n=len(p.required_no_indication), example=', '.join(p.required_no_indication[:3]))
|
|
@@ -2303,8 +2411,7 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2303
2411
|
if p.focus_blur:
|
|
2304
2412
|
add_ej('high', '2.1.1', 'onfocus_blur', p.focus_blur,
|
|
2305
2413
|
n=len(p.focus_blur),
|
|
2306
|
-
paths=
|
|
2307
|
-
if id(_a) in p._elem_paths][:5])
|
|
2414
|
+
paths=p._finding_paths(p.focus_blur_elems))
|
|
2308
2415
|
if p.motions:
|
|
2309
2416
|
add_ej('low', '2.5.4', 'motion_actuation', p.motions,
|
|
2310
2417
|
n=len(p.motions), example=', '.join(p.motions[:3]))
|
|
@@ -2313,8 +2420,7 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2313
2420
|
n=len(p.orientation_locks), example=', '.join(p.orientation_locks[:2]))
|
|
2314
2421
|
if p.videos and p.videos_no_desc_elems:
|
|
2315
2422
|
add('low', '1.2.3', 'audio_desc_missing', n=len(p.videos_no_desc_elems),
|
|
2316
|
-
paths=
|
|
2317
|
-
if id(_a) in p._elem_paths][:5])
|
|
2423
|
+
paths=p._finding_paths(p.videos_no_desc_elems))
|
|
2318
2424
|
if p.sensory:
|
|
2319
2425
|
add('low', '1.3.3', 'sensory_text', example='; '.join(p.sensory[:2])[:70])
|
|
2320
2426
|
lm_dups = [f'{lm} ×{t[1]}' for lm, t in p.landmarks.items()
|
|
@@ -2324,15 +2430,13 @@ def audit_html(html_text, url='(html)', lang='en', standard=None, target=None):
|
|
|
2324
2430
|
if p.generics >= 2: # un enlace genérico único suele desambiguarse por contexto
|
|
2325
2431
|
gen = [f'«{k}»' for k in p.links if k in _GENERIC_TEXT][:4]
|
|
2326
2432
|
add('low', '2.4.4', 'generic_link', n=p.generics, example=', '.join(gen),
|
|
2327
|
-
paths=
|
|
2328
|
-
if id(_a) in p._elem_paths][:5])
|
|
2433
|
+
paths=p._finding_paths(p.generic_link_elems))
|
|
2329
2434
|
same = sum(1 for _k, hrefs in p.links.items() if len(hrefs) > 1)
|
|
2330
2435
|
if same:
|
|
2331
2436
|
_same_elems = [p.links_elems.get(_k, [None])[0]
|
|
2332
2437
|
for _k, _hs in p.links.items() if len(_hs) > 1]
|
|
2333
2438
|
add('low', '2.4.4', 'same_name_links', n=same,
|
|
2334
|
-
paths=
|
|
2335
|
-
if _a is not None and id(_a) in p._elem_paths][:5])
|
|
2439
|
+
paths=p._finding_paths(_same_elems))
|
|
2336
2440
|
ak_dups = [f'"{k}" ×{v}' for k, v in p.accesskeys.items() if v > 1]
|
|
2337
2441
|
if ak_dups:
|
|
2338
2442
|
add('low', '2.1.1', 'accesskey_dup', n=len(ak_dups), example=', '.join(ak_dups[:4]))
|