Skip to content

Commit c79e692

Browse files
authored
Use classifier nodes (#72)
1 parent 4ee6da0 commit c79e692

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ version-file = 'src/scanpydoc/_version.py'
6565
[tool.hatch.envs.docs]
6666
features = ['doc']
6767
[tool.hatch.envs.docs.scripts]
68-
build = 'sphinx-build -M html docs docs/_build/html'
68+
build = 'sphinx-build -M html docs docs/_build'
6969

7070
[[tool.hatch.envs.test.matrix]]
7171
python = ['3.8', '3.9', '3.10', '3.11']

src/scanpydoc/definition_list_typed_field.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,30 @@ def make_refs(role_name, name, node):
4848
def handle_item(
4949
fieldarg: str, content: list[nodes.inline]
5050
) -> nodes.definition_list_item:
51-
head = nodes.inline()
52-
head += make_refs(self.rolename, fieldarg, addnodes.literal_strong)
51+
term = nodes.term()
52+
term += make_refs(self.rolename, fieldarg, addnodes.literal_strong)
53+
5354
field_type = types.pop(fieldarg, None)
5455
if field_type is not None:
55-
head += nodes.Text(" : ")
5656
if len(field_type) == 1 and isinstance(field_type[0], nodes.Text):
5757
(text_node,) = field_type # type: nodes.Text
58-
head += make_refs(
58+
classifier_content = make_refs(
5959
self.typerolename, text_node.astext(), addnodes.literal_emphasis
6060
)
6161
else:
62-
head += field_type
63-
64-
# Contents are wrapped into a span for pydata sphinx theme
65-
head_wrap = nodes.term("", "", head)
66-
body_content = nodes.paragraph("", "", *content)
67-
body = nodes.definition("", body_content)
68-
69-
return nodes.definition_list_item("", head_wrap, body)
62+
classifier_content = field_type
63+
term += [
64+
# https://github.com/sphinx-doc/sphinx/issues/10815
65+
nodes.Text(" "),
66+
# Sphinx tries to fixup classifiers without rawsource,
67+
# but for this expects attributes we don’t have. Thus “×”.
68+
nodes.classifier("×", "", *classifier_content),
69+
]
70+
71+
def_content = nodes.paragraph("", "", *content)
72+
definition = nodes.definition("", def_content)
73+
74+
return nodes.definition_list_item("", term, definition)
7075

7176
field_name = nodes.field_name("", self.label)
7277
assert not self.can_collapse

0 commit comments

Comments
 (0)