From 9acde6e29f58df714b5e89868f46f7d694631b25 Mon Sep 17 00:00:00 2001 From: Fernando Raya Date: Mon, 20 May 2024 20:09:50 +0200 Subject: [PATCH] doc: Add copy button to code blocks Add a Sphinx extension to show a copy button in the code blocks. The text copied excludes the number of line and prompt characters in console blocks. --- .../workflows/build-deploy-documentation.yml | 17 ++++++++++------- .github/workflows/build-documentation.yml | 14 +++++++------- documentation/README.rst | 5 +++++ documentation/source/conf.py | 7 +++++++ 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-deploy-documentation.yml b/.github/workflows/build-deploy-documentation.yml index eb60da47a..28ad3c117 100644 --- a/.github/workflows/build-deploy-documentation.yml +++ b/.github/workflows/build-deploy-documentation.yml @@ -25,18 +25,21 @@ jobs: with: submodules: recursive - # - # Build documentation installing first 'furo' theme dependencies - # + - name: Add sphinx dependencies + run: | + echo furo >> documentation/requirements.txt + echo sphinx-copybutton >> documentation/requirements.txt - - uses: ammaraskar/sphinx-action@master + - name: Build documentation + uses: ammaraskar/sphinx-action@master with: - pre-build-command: "echo furo >> documentation/requirements.txt" docs-folder: "documentation" + - name: Bypassing Jekyll on GH pages + run: | + sudo touch documentation/_build/html/.nojekyll + - name: Deploy documents to GH pages uses: JamesIves/github-pages-deploy-action@v4 with: folder: documentation/_build/html - - diff --git a/.github/workflows/build-documentation.yml b/.github/workflows/build-documentation.yml index eee31c61e..8a5af329a 100644 --- a/.github/workflows/build-documentation.yml +++ b/.github/workflows/build-documentation.yml @@ -25,12 +25,12 @@ jobs: with: submodules: recursive - # - # Build documentation installing first 'furo' theme dependencies - # + - name: Add sphinx dependencies + run: | + echo furo >> documentation/requirements.txt + echo sphinx-copybutton >> documentation/requirements.txt - - uses: ammaraskar/sphinx-action@master + - name: Build documentation + uses: ammaraskar/sphinx-action@master with: - pre-build-command: "echo furo >> documentation/requirements.txt" - docs-folder: "documentation" - + docs-folder: "documentation" \ No newline at end of file diff --git a/documentation/README.rst b/documentation/README.rst index 591528463..b305c19ae 100644 --- a/documentation/README.rst +++ b/documentation/README.rst @@ -28,6 +28,11 @@ You may also need ``python-dateutil``. sudo pip3 install python-dateutil +And ``sphinx-copybutton`` to show a copy button in code blocks:: + + sudo pip3 install sphinx-copybutton + + Building ======== diff --git a/documentation/source/conf.py b/documentation/source/conf.py index ff6a3e7da..f72f596ba 100644 --- a/documentation/source/conf.py +++ b/documentation/source/conf.py @@ -23,6 +23,7 @@ 'dylan.domain', 'sphinx.ext.graphviz', 'sphinx.ext.intersphinx', + 'sphinx_copybutton', ] primary_domain = 'dylan' exclude_patterns = [ @@ -51,3 +52,9 @@ html_title = 'Open Dylan' html_static_path = ['_static'] html_favicon = '_static/favicon.ico' + +# -- Options for copybutton ------------------------------------------------- +# https://sphinx-copybutton.readthedocs.io/en/latest/use.html + +# Skip line numbers and prompt characters +copybutton_exclude = '.linenos, .gp'