You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Validates and recommends MathML when only TeX math is present for accessibility.
299
+
300
+
Returns:
301
+
dict: A validation result dictionary.
302
+
"""
303
+
has_mml_math=bool(self.data.get("mml_math"))
304
+
has_tex_math=bool(self.data.get("tex_math"))
305
+
item_id=self.data.get("id")
306
+
307
+
# No codification found - return OK response reflecting this condition
308
+
ifnothas_mml_mathandnothas_tex_math:
309
+
returnbuild_response(
310
+
title="MathML recommendation",
311
+
parent=self.data,
312
+
item="mml:math",
313
+
sub_item=None,
314
+
validation_type="exist",
315
+
is_valid=True,
316
+
expected="mml:math or tex-math",
317
+
obtained=_("no codification found"),
318
+
advice=None,
319
+
data=self.data,
320
+
error_level=self.rules["mathml_error_level"],
321
+
advice_text=None,
322
+
advice_params=None,
323
+
)
324
+
325
+
# Only warn if there's tex-math but no mml:math
326
+
ifhas_tex_mathandnothas_mml_math:
327
+
is_valid=False
328
+
expected="mml:math"
329
+
obtained="tex-math"
330
+
331
+
returnbuild_response(
332
+
title="MathML recommendation",
333
+
parent=self.data,
334
+
item="mml:math",
335
+
sub_item=None,
336
+
validation_type="exist",
337
+
is_valid=is_valid,
338
+
expected=expected,
339
+
obtained=obtained,
340
+
advice=_('For accessibility, consider adding <mml:math> in <disp-formula id="{formula_id}">. MathML improves accessibility for screen readers. Consult SPS documentation for more detail.').format(formula_id=item_id),
341
+
data=self.data,
342
+
error_level=self.rules["mathml_error_level"],
343
+
advice_text=_('For accessibility, consider adding <mml:math> in <disp-formula id="{formula_id}">. MathML improves accessibility for screen readers. Consult SPS documentation for more detail.'),
344
+
advice_params={"formula_id": item_id},
345
+
)
346
+
347
+
# Otherwise, it's valid (has mml:math or both)
348
+
returnbuild_response(
349
+
title="MathML recommendation",
350
+
parent=self.data,
351
+
item="mml:math",
352
+
sub_item=None,
353
+
validation_type="exist",
354
+
is_valid=True,
355
+
expected="mml:math",
356
+
obtained="mml:math",
357
+
advice=None,
358
+
data=self.data,
359
+
error_level=self.rules["mathml_error_level"],
360
+
advice_text=None,
361
+
advice_params=None,
362
+
)
363
+
293
364
defvalidate_alternatives(self):
294
365
"""
295
366
Validates the presence of the 'alternatives' attribute in a <disp-formula> element.
Validates and recommends MathML when only TeX math is present for accessibility.
691
+
692
+
Returns:
693
+
dict: A validation result dictionary.
694
+
"""
695
+
has_mml_math=bool(self.data.get("mml_math"))
696
+
has_tex_math=bool(self.data.get("tex_math"))
697
+
item_id=self.data.get("id")
698
+
699
+
# No codification found - return OK response reflecting this condition
700
+
ifnothas_mml_mathandnothas_tex_math:
701
+
returnbuild_response(
702
+
title="MathML recommendation",
703
+
parent=self.data,
704
+
item="mml:math",
705
+
sub_item=None,
706
+
validation_type="exist",
707
+
is_valid=True,
708
+
expected="mml:math or tex-math",
709
+
obtained=_("no codification found"),
710
+
advice=None,
711
+
data=self.data,
712
+
error_level=self.rules["mathml_error_level"],
713
+
advice_text=None,
714
+
advice_params=None,
715
+
)
716
+
717
+
# Only warn if there's tex-math but no mml:math
718
+
ifhas_tex_mathandnothas_mml_math:
719
+
is_valid=False
720
+
expected="mml:math"
721
+
obtained="tex-math"
722
+
723
+
returnbuild_response(
724
+
title="MathML recommendation",
725
+
parent=self.data,
726
+
item="mml:math",
727
+
sub_item=None,
728
+
validation_type="exist",
729
+
is_valid=is_valid,
730
+
expected=expected,
731
+
obtained=obtained,
732
+
advice=_('For accessibility, consider adding <mml:math> in <inline-formula id="{formula_id}">. MathML improves accessibility for screen readers. Consult SPS documentation for more detail.').format(formula_id=item_id),
733
+
data=self.data,
734
+
error_level=self.rules["mathml_error_level"],
735
+
advice_text=_('For accessibility, consider adding <mml:math> in <inline-formula id="{formula_id}">. MathML improves accessibility for screen readers. Consult SPS documentation for more detail.'),
736
+
advice_params={"formula_id": item_id},
737
+
)
738
+
739
+
# Otherwise, it's valid (has mml:math or both)
740
+
returnbuild_response(
741
+
title="MathML recommendation",
742
+
parent=self.data,
743
+
item="mml:math",
744
+
sub_item=None,
745
+
validation_type="exist",
746
+
is_valid=True,
747
+
expected="mml:math",
748
+
obtained="mml:math",
749
+
advice=None,
750
+
data=self.data,
751
+
error_level=self.rules["mathml_error_level"],
752
+
advice_text=None,
753
+
advice_params=None,
754
+
)
755
+
614
756
defvalidate_alternatives(self):
615
757
"""
616
758
Validates the presence of alternatives in a <inline-formula> element.
0 commit comments