Skip to content

Replace <em> with <span> for desc_annotation semantic HTML #13689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Contributors
* Louis Maddox -- better docstrings
* Łukasz Langa -- partial support for autodoc
* Marco Buttu -- doctest extension (pyversion option)
* Mark Ostroth -- semantic HTML contributions
* Martin Hans -- autodoc improvements
* Martin Larralde -- additional napoleon admonitions
* Martin Liška -- option directive and role improvements
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ Bugs fixed
Patch by Jean-François B.
* #13685: gettext: Correctly ignore trailing backslashes.
Patch by Bénédikt Tran.
* #13688: HTML5: Replace ``<em class="property">`` with ``<span class="property">``
for Python attribute type annotations to improve semantic HTML structure.
Patch by Mark O.
Comment on lines +82 to +84
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a suggested link / reference for "semantic HTML structure"?

Suggested change
* #13688: HTML5: Replace ``<em class="property">`` with ``<span class="property">``
for Python attribute type annotations to improve semantic HTML structure.
Patch by Mark O.
* #13688: HTML builder: Replace ``<em class="property">`` with ``<span class="property">``
for Python attribute type annotations to improve semantic HTML structure.
Patch by Mark Ostroth.

Copy link
Author

@q2mark q2mark Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AA-Turner this is the current reference for all HTML elements.

https://html.spec.whatwg.org/multipage/text-level-semantics.html

Or MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements

Turns out we might want to use "var" and "code" but that could break existing themes. For now I am suggesting removing <em> because the intention is not to emphasize text but to denote the purpose of the code.


Testing
-------
4 changes: 2 additions & 2 deletions sphinx/writers/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ def depart_desc_optional(self, node: Element) -> None:
self.param_group_index += 1

def visit_desc_annotation(self, node: Element) -> None:
self.body.append(self.starttag(node, 'em', '', CLASS='property'))
self.body.append(self.starttag(node, 'span', '', CLASS='property'))

def depart_desc_annotation(self, node: Element) -> None:
self.body.append('</em>')
self.body.append('</span>')

##############################################

Expand Down
6 changes: 3 additions & 3 deletions tests/test_domains/test_domain_py_pyobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,17 +925,17 @@ def test_domain_py_type_alias(app):

content = (app.outdir / 'type_alias.html').read_text(encoding='utf8')
assert (
'<em class="property"><span class="k"><span class="pre">type</span></span><span class="w"> </span></em>'
'<span class="property"><span class="k"><span class="pre">type</span></span><span class="w"> </span></span>'
'<span class="sig-prename descclassname"><span class="pre">module_one.</span></span>'
'<span class="sig-name descname"><span class="pre">MyAlias</span></span>'
'<em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span>'
'<span class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span>'
'<span class="w"> </span><span class="pre">list</span>'
'<span class="p"><span class="pre">[</span></span>'
'<span class="pre">int</span><span class="w"> </span>'
'<span class="p"><span class="pre">|</span></span><span class="w"> </span>'
'<a class="reference internal" href="#module_two.SomeClass" title="module_two.SomeClass">'
'<span class="pre">module_two.SomeClass</span></a>'
'<span class="p"><span class="pre">]</span></span></em>'
'<span class="p"><span class="pre">]</span></span></span>'
) in content
assert app.warning.getvalue() == ''

Expand Down
Loading