Skip to content

Commit

Permalink
doc: Add copy button to code blocks (#1604)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fraya authored May 21, 2024
2 parents 83db088 + 9acde6e commit 61ce604
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/build-deploy-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


14 changes: 7 additions & 7 deletions .github/workflows/build-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 5 additions & 0 deletions documentation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
========

Expand Down
7 changes: 7 additions & 0 deletions documentation/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'dylan.domain',
'sphinx.ext.graphviz',
'sphinx.ext.intersphinx',
'sphinx_copybutton',
]
primary_domain = 'dylan'
exclude_patterns = [
Expand Down Expand Up @@ -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'

0 comments on commit 61ce604

Please sign in to comment.