Merge pull request #9358 from jonels-msft/menu-headings

Provide more semantic structure for screen-readers
This commit is contained in:
Takeshi KOMIYA 2021-07-07 01:58:18 +09:00 committed by GitHub
commit 7bd4603d85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View File

@ -415,7 +415,7 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator):
# overwritten # overwritten
def visit_title(self, node: Element) -> None: def visit_title(self, node: Element) -> None:
if isinstance(node.parent, addnodes.compact_paragraph) and node.parent.get('toctree'): if isinstance(node.parent, addnodes.compact_paragraph) and node.parent.get('toctree'):
self.body.append(self.starttag(node, 'p', '', CLASS='caption')) self.body.append(self.starttag(node, 'p', '', CLASS='caption', ROLE='heading'))
self.body.append('<span class="caption-text">') self.body.append('<span class="caption-text">')
self.context.append('</span></p>\n') self.context.append('</span></p>\n')
else: else:

View File

@ -366,7 +366,7 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
# overwritten # overwritten
def visit_title(self, node: Element) -> None: def visit_title(self, node: Element) -> None:
if isinstance(node.parent, addnodes.compact_paragraph) and node.parent.get('toctree'): if isinstance(node.parent, addnodes.compact_paragraph) and node.parent.get('toctree'):
self.body.append(self.starttag(node, 'p', '', CLASS='caption')) self.body.append(self.starttag(node, 'p', '', CLASS='caption', ROLE='heading'))
self.body.append('<span class="caption-text">') self.body.append('<span class="caption-text">')
self.context.append('</span></p>\n') self.context.append('</span></p>\n')
else: else:

View File

@ -622,7 +622,7 @@ def test_html_meta(app):
assert expected_expr in result assert expected_expr in result
expected_expr = '<meta content="I18N, SPHINX, MARKUP" name="keywords" />' expected_expr = '<meta content="I18N, SPHINX, MARKUP" name="keywords" />'
assert expected_expr in result assert expected_expr in result
expected_expr = '<p class="caption"><span class="caption-text">HIDDEN TOC</span></p>' expected_expr = '<p class="caption" role="heading"><span class="caption-text">HIDDEN TOC</span></p>'
assert expected_expr in result assert expected_expr in result