Merge pull request #301152 from DanielSidhion/examples-collapsible

nixos-render-docs: make examples collapsible by default
This commit is contained in:
Silvan Mosberger 2024-04-04 16:48:21 +02:00 committed by GitHub
commit 60e005352d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View File

@ -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;

View File

@ -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'<div class="example"><span {id} ></span>'
return f'<div class="example"><span {id} ></span><details>'
def example_close(self, token: Token, tokens: Sequence[Token], i: int) -> str:
return '</div></div><br class="example-break" />'
return '</div></details></div><br class="example-break" />'
def example_title_open(self, token: Token, tokens: Sequence[Token], i: int) -> str:
return '<p class="title"><strong>'
return '<summary><span class="title"><strong>'
def example_title_close(self, token: Token, tokens: Sequence[Token], i: int) -> str:
return '</strong></p><div class="example-contents">'
return '</strong></span></summary><div class="example-contents">'
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 ""