Skip to content
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

mkdocs: Fix numbered code annotations #684

Merged
merged 2 commits into from
Sep 20, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
- ".editorconfig"
- ".git*"
- ".git*/**"
- "docs/*.py"
- "docs/**/*.py"
- CODEOWNERS
- MANIFEST.in
- noxfile.py
36 changes: 34 additions & 2 deletions docs/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,44 @@ a.external:hover::after, a.md-nav__link[href^="https:"]:hover::after {
margin-bottom: 1.5rem;
}

/* Code annotations with numbers
* https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#annotations-with-numbers
/* Code annotations with numbers.
*
* Normally annothations are shown with a (+) button that expands the
* annotation. To be able to explain code step by step, it is good to have
* annotations with numbers, to be able to follow the notes in a particular
* order.
*
* To do this, we need some custom CSS rules. Before this customization was
* officially supported and documented, but now they are not officially
* supported anymore, so it could eventually break (it already did once).
*
* If that happens we either need to look into how to fix the CSS ourselves or
* remove the feature. To do the customization, this is what we should be able
* to count on:
*
* "you can be sure that the data-md-annotation-id attribute will always be
* present in the source, which means you can always number them in any way you
* like."
*
* Code annotation are described here:
* https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#code-annotations
*
* Here are the original docs on how to enable numbered annotations:
* https://web.archive.org/web/20230724161216/https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#annotations-with-numbers
*
* This is the PR fixing the numbered annotations when they broke:
* https://github.com/frequenz-floss/frequenz-sdk-python/pull/684
*
* And this is the reported regression when it was decided to drop support for
* numbered annotations officially:
* https://github.com/squidfunk/mkdocs-material/issues/6042
*/
.md-typeset .md-annotation__index > ::before {
content: attr(data-md-annotation-id);
}
.md-typeset :focus-within > .md-annotation__index > ::before {
transform: none;
}
.md-typeset .md-annotation__index {
width: 4ch;
}