From 2ce2079e4d82c9456a05b6764a818d6461e3c0af Mon Sep 17 00:00:00 2001 From: DS Date: Tue, 2 Apr 2024 21:28:13 -0700 Subject: [PATCH] nixos-render-docs: make examples collapsible by default --- doc/style.css | 16 ++++++++++++++++ .../src/nixos_render_docs/html.py | 8 ++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/doc/style.css b/doc/style.css index fddf4f4823c7..38984169589f 100644 --- a/doc/style.css +++ b/doc/style.css @@ -347,6 +347,22 @@ div.appendix div.example { margin-top: 1.5em; } +div.book div.example details, +div.appendix div.example details { + padding: 5px; +} + +div.book div.example details[open], +div.appendix div.example details[open] { + border: 1px solid #aaa; + border-radius: 4px; +} + +div.book div.example details>summary, +div.appendix div.example details>summary { + cursor: pointer; +} + div.book br.example-break, div.appendix br.example-break { display: none; diff --git a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/html.py b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/html.py index 2e43a6a2be87..1de511c7ce31 100644 --- a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/html.py +++ b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/html.py @@ -219,13 +219,13 @@ class HTMLRenderer(Renderer): def example_open(self, token: Token, tokens: Sequence[Token], i: int) -> str: if id := cast(str, token.attrs.get('id', '')): id = f'id="{escape(id, True)}"' if id else '' - return f'
' + return f'
' def example_close(self, token: Token, tokens: Sequence[Token], i: int) -> str: - return '

' + return '
' def example_title_open(self, token: Token, tokens: Sequence[Token], i: int) -> str: - return '

' + return '

' def example_title_close(self, token: Token, tokens: Sequence[Token], i: int) -> str: - return '

' + return '
' def image(self, token: Token, tokens: Sequence[Token], i: int) -> str: src = self._pull_image(cast(str, token.attrs['src'])) alt = f'alt="{escape(token.content, True)}"' if token.content else ""