Skip to content

Commit 784fa73

Browse files
authored
Style deprecation notices in the API reference (#329)
Preparation for the client-common 0.4.1 update, so deprecation notices already look right by the time it adds them. Two things: a CSS rule that styles the `deprecated` admonition class (gravestone icon, its own colour, otherwise like a warning), and the [griffe-warnings-deprecated](https://mkdocstrings.github.io/griffe-warnings-deprecated/) extension wired into the mkdocstrings handler so symbols decorated with `typing_extensions.deprecated` get an admonition generated for them. The extension's `kind` is set to `deprecated` rather than the default `warning`, so what it emits is markup-identical to a hand-written `Deprecated:` admonition. One rule styles both, which matters because the decorator cannot reach module-level aliases, a single function argument, enum members or whole modules.
2 parents 001e39c + d82a93a commit 784fa73

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎docs/_css/mkdocstrings.css‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,25 @@ a.autorefs-external::after {
4242
a.autorefs-external:hover::after {
4343
background-color: var(--md-accent-fg-color);
4444
}
45+
46+
/* A "Deprecated" admonition, styled like a warning but with its own icon. */
47+
:root {
48+
--md-admonition-icon--deprecated: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M10 2h4c3.31 0 5 2.69 5 6v10.66C16.88 17.63 15.07 17 12 17s-4.88.63-7 1.66V8c0-3.31 1.69-6 5-6M8 8v1.5h8V8zm1 4v1.5h6V12zM3 22v-.69c2.66-1.69 10.23-5.47 18-.06V22z"/></svg>');
49+
}
50+
51+
.md-typeset .admonition.deprecated,
52+
.md-typeset details.deprecated {
53+
border-color: #cc9900;
54+
}
55+
56+
.md-typeset .deprecated > .admonition-title,
57+
.md-typeset .deprecated > summary {
58+
background-color: #cc99001a;
59+
}
60+
61+
.md-typeset .deprecated > .admonition-title::before,
62+
.md-typeset .deprecated > summary::before {
63+
background-color: #cc9900;
64+
-webkit-mask-image: var(--md-admonition-icon--deprecated);
65+
mask-image: var(--md-admonition-icon--deprecated);
66+
}

‎mkdocs.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ plugins:
101101
python:
102102
paths: ["src"]
103103
options:
104+
extensions:
105+
- griffe_warnings_deprecated:
106+
kind: deprecated
107+
title: Deprecated
104108
docstring_section_style: spacy
105109
inherited_members: true
106110
merge_init_into_class: false

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dev-flake8 = [
5555
dev-formatting = ["black == 26.5.1", "isort == 8.0.1"]
5656
dev-mkdocs = [
5757
"black == 26.5.1",
58+
"griffe-warnings-deprecated == 1.1.1",
5859
"Markdown==3.10.3",
5960
"mike == 2.2.0",
6061
"mkdocs-gen-files == 0.6.1",

0 commit comments

Comments
 (0)