Skip to content

Commit b16a136

Browse files
committed
docs: Add copy button to prompt blocks via sphinx-copybutton
Target p:last-child inside prompt admonitions so the button lands inside the div (same positioning context as code blocks). Hidden at rest, visible on hover — identical behavior to code blocks. - copybutton_selector extended with div.admonition.prompt > p:last-child - copybutton_exclude adds .admonition-title - Hover CSS for button visibility inside prompt blocks - Fix hidden title still taking space (display:none suffices) - Remove bottom margin on last paragraph to tighten padding
1 parent 2e03186 commit b16a136

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

docs/_static/css/custom.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,23 @@ div.admonition.prompt > p {
228228
color: var(--color-foreground-primary);
229229
}
230230

231+
div.admonition.prompt > p:last-of-type {
232+
margin-bottom: 0;
233+
}
234+
235+
/* Copy button — inserted afterend of p:last-child, so it
236+
* lands inside the prompt div. position:relative on the
237+
* prompt div provides the positioning context. */
238+
div.admonition.prompt > button.copybtn {
239+
background: transparent !important;
240+
border: none !important;
241+
}
242+
243+
div.admonition.prompt:hover > button.copybtn,
244+
div.admonition.prompt > button.copybtn.success {
245+
opacity: 1;
246+
}
247+
231248
div.admonition.prompt > p:last-child {
232249
margin-bottom: 0;
233250
}

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@
138138
copybutton_prompt_is_regexp = True
139139
copybutton_remove_prompts = True
140140
copybutton_line_continuation_character = "\\"
141+
copybutton_selector = "div.highlight pre, div.admonition.prompt > p:last-child"
142+
copybutton_exclude = ".linenos, .admonition-title"
141143

142144
# sphinxext-rediraffe
143145
rediraffe_redirects = "redirects.txt"

0 commit comments

Comments
 (0)