From 7f34b8ab53ccf1dfdd525c29dac634ac208ef621 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 13 Aug 2021 18:50:38 +0200 Subject: [PATCH] docs: Add copy buttons to all the codeblocks This uses a bit of javascript to add copy buttons, so you can directly copy all the code in a given block to the clipboard! For codeblocks without prompts, it just copies all the code, for blocks with prompts, it copies all the lines after prompts, under the assumption that that's the code to be executed. It would give you *all* the lines, so the output wouldn't be interleaved like it is in the html, but good enough. The buttons appear on hover, so they aren't usable on phones, but since you won't really have a clipboard on phones and I have no idea how to make them not always in front of the text otherwise: Eh. I'm not in love with the javascript here, but it'll do. --- doc_src/python_docs_theme/layout.html | 54 +++++++++++++++++++ .../python_docs_theme/static/pydoctheme.css | 20 +++++++ 2 files changed, 74 insertions(+) diff --git a/doc_src/python_docs_theme/layout.html b/doc_src/python_docs_theme/layout.html index ec9f29dbb..8cd0b5377 100644 --- a/doc_src/python_docs_theme/layout.html +++ b/doc_src/python_docs_theme/layout.html @@ -58,4 +58,58 @@ {% trans sphinx_version=sphinx_version|e %}Created using Sphinx {{ sphinx_version }}.{% endtrans %} + + {% endblock %} diff --git a/doc_src/python_docs_theme/static/pydoctheme.css b/doc_src/python_docs_theme/static/pydoctheme.css index 036fa9146..c9109ebaf 100644 --- a/doc_src/python_docs_theme/static/pydoctheme.css +++ b/doc_src/python_docs_theme/static/pydoctheme.css @@ -164,6 +164,26 @@ div.body pre { border: 1px solid #ac9; } +div.highlight { + /* For the button to be positionable inside us */ + position: relative; +} + +div.highlight pre { + padding: 10px; +} + +pre button { + position: absolute; + top: 4px; + right: 4px; + opacity: 0; +} + +div.highlight pre:hover > button { + opacity: 1; +} + div.body div.admonition, div.body div.impl-detail { border-radius: 3px; }