fix no speech when role="math" on a non-math element#17327
Conversation
The fix (which is a bit of a hueristic) is to look inside the `span` (or other element with `role="math"` and see if exactly one of the children is `math`. If so, then we recursively call the code to get the MathML for it. If there isn't exactly one math element, we fall through and raise a LookupError (which is what happened before adding this check).
|
Any suggestions for how to write a unit or system test for this? It seems like I should be able to provide some HTML, call some function, and then make sure the MathML is returned from this call. I looked at the existing tests and nothing struck me as similar, although I could have easily overlooked a similar test. There is If testing this is not currently an option, then this will be ready for review. |
See test results for failed build of commit 9e2ac7ccde |
|
Once you mark it ready, try tagging coderabbitai, and asking for suggested unit test code.
It might give you an idea or two where to go with it.
You can always mark it draft again to investigate the result. I don't think it will respond until after the first review on being marked ready, though I could be wrong.
|
|
@coderabbitai: as per @XLTechie, any suggestions for a test? |
|
Tip For best results, initiate chat on the files or code changes. @NSoiffer: I'd be happy to suggest a unit test for this fix. Since the issue involves elements with import unittest
from some_module import getMathMlFromNode
from some_parser import parseHtmlToNode
class TestMathRoleSpan(unittest.TestCase):
def test_math_role_span_with_single_math_child(self):
# HTML content with role="math" wrapping a <math> element
html_content = '''
<span role="math">
<math>
<msqrt>
<mn>4</mn>
</msqrt>
</math>
</span>
'''
# Parse the HTML content into a node
node = parseHtmlToNode(html_content)
# Call the function that retrieves MathML from the node
mathml = getMathMlFromNode(node)
# Expected MathML output
expected_mathml = '''
<math>
<msqrt>
<mn>4</mn>
</msqrt>
</math>
'''
# Assert that the retrieved MathML matches the expected output
self.assertEqual(mathml.strip(), expected_mathml.strip())
if __name__ == '__main__':
unittest.main()In this test:
If your codebase uses different parsing or testing utilities, you can adjust the above code accordingly. Additionally, if there's an existing test class for MathML processing, you can add this test method to that class. I hope this helps! |
|
For testing, you will probably have to create a chrome test in the system test framework |
|
However since we don't have mathML support bundled in NVDA yet, I don't think this can be tested |
See test results for failed build of commit d298d88a12 |
Link to issue number:
This fixes #15058.
Summary of the issue:
When someone has something like
The math is not spoken (nothing is spoken).
This construct happens in real life math (see #15058 for more details).
Description of user facing changes
Web content such as the above will now be spoken as if the
span(or other elements) are not present. This is what should have always happened.Description of development approach
The fix (which is a bit of a hueristic) is to look inside the
span(or other element withrole="math"and see if exactly one of the children ismath. If so, then we recursively call the code to get the MathML for it.If there isn't exactly one math element, we fall through and raise a LookupError (which is what happened before adding this check).
Testing strategy:
Known issues with pull request:
It only deals with one scenario where
role="math"occurs. If there are multiplemathchildren or if the math is not MathML, nothing is done. Potentially there are better things that might be done (such as speaking the leaf content) rather than being silent.Code Review Checklist:
@coderabbitai summary